Skip to content

Instantly share code, notes, and snippets.

View cipharius's full-sized avatar

Valts Liepiņš cipharius

View GitHub Profile
proc planeFit(cluster: Tensor[float], threshold = 10e-2): Option[Plane] =
## Fit points to a 3D plane
# At least 3 points are required to fit a plane
if cluster.shape[0] < 3: return
let points = cluster[_, 0..2]
let mean = points.mean(axis=0)
let delta = points .- mean
let covarMatrix = delta.covariance
@cipharius
cipharius / sort-selections.kak
Last active April 18, 2024 14:39
Sort kakoune selections using GNU sort utility
define-command sort-selections -params 0.. -override -docstring '
sort-selections: Sort current selections using GNU sort utility
All parameters will be passed to the GNU sort utility
' %{
# Copy current selections to a temporary sort buffer
execute-keys %{"sy}
edit -scratch *sort-selections*
execute-keys %{"s<a-p>}
# Seperate selections with null characters
@cipharius
cipharius / random-camera-sway.lua
Last active February 9, 2020 06:46
Roblox random camera sway
local camera = workspace.CurrentCamera
local fixedCFrame = CFrame.new(0, 100, 0) -- CFrame of default looking direction/position
local rate = 1/5 -- Speed at which the camera will sway
local xSwayAngle = math.pi/9 -- X angle change interval
local ySwayAngle = math.pi/9 -- Y angle change interval
local rollAngle = math.pi/18 -- Roll angle change interval
function update(t)
local phi = math.pi/2 + math.noise(t*rate, 0) * xSwayAngle
local theta = math.pi/2 + math.noise(t*rate, 10) * ySwayAngle
@cipharius
cipharius / RPN-calculator.hs
Created September 10, 2020 08:36
Simple revers polish notation parser and calculator in Haskell
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Text as T
import Data.Attoparsec.Text
data Op
= Add Op Op
| Sub Op Op
| Mul Op Op
| Div Op Op
| Const Double
@cipharius
cipharius / Arcan.nix
Last active May 1, 2021 11:43 — forked from egasimus/Arcan.nix
Building Arcan on NixOS, 2021 version
({ lib, newScope, stdenv, pkgs }: let
# nicer aliases
derive = stdenv.mkDerivation;
concat = builtins.concatStringsSep " ";
# vendored libuvc: don't build, just make sources available
libuvc-src = derive {
name = "libuvc-src";
# using fetchgit instead fetchFromGitHub because
@cipharius
cipharius / mergeInPlace.zig
Last active May 16, 2023 14:55
Merges two sorted slices of one contiguous memory
const std = @import("std");
fn mergeInPlace(comptime T: type, s: []T, midpoint: usize) void {
std.debug.assert(midpoint <= s.len);
if (midpoint == 0 or midpoint == s.len) return;
var a: usize = 0;
var b: usize = midpoint;
var c: usize = midpoint;