Skip to content

Instantly share code, notes, and snippets.

View hnsl's full-sized avatar
🤠

Hannes Landeholm hnsl

🤠
View GitHub Profile
-1.585 *
(
if (((1.262 * a + 1.262 * b) + -0.000) > 0)
then ((1.262 * a + 1.262 * b) + -0.000)
else 0
)
+
1.303 *
@hnsl
hnsl / marten.cpp
Last active November 21, 2015 18:36
marten
#include <iostream>
#include <vector>
#include <algorithm>
class Vertex {
public:
// Vertex id in vertexes.
int id;
// Index of vertex begin edge (first).
int idx;
@hnsl
hnsl / gist:17c5bfbf3d55d08a1883
Last active November 20, 2015 00:12
bandwidth 2
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <iostream>
class Computer;
class Link {
public:
@hnsl
hnsl / gist:4030290c6b22c1723bc6
Created September 18, 2015 21:36
test close
ch := make(chan interface{})
msg := "foo"
go func() {
x := <- ch
if _, ok := x.(string); ok {
jlib.JPrint("%s", x.(string))
}
close(ch)
}()
@hnsl
hnsl / gist:2ec70a739cadb2af9583
Created August 9, 2015 21:11
hello world with proofs
module Main
total
minusS : (n : Nat) -> (m : Nat) -> LTE m n -> Nat
minusS n m x = n - m
total
decNat : Nat -> Nat
decNat k with (isLTE 1 k)
decNat k | (Yes prf) = minusS k 1 prf
@hnsl
hnsl / gist:c20d73d581d578da1a05
Created August 6, 2015 02:59
Haskell reverse polish notation
consumeRPN [] st = last st
consumeRPN (x:xs) st
| x == "+" = consumeRPN xs (ll ++ [l1 + l2])
| x == "-" = consumeRPN xs (ll ++ [l1 - l2])
| x == "*" = consumeRPN xs (ll ++ [l1 * l2])
| x == "/" = consumeRPN xs (ll ++ [l1 / l2])
| otherwise = consumeRPN xs (st ++ [read x])
where
l2 = last st
l1 = last $ init st
@hnsl
hnsl / gist:03e5953ec151558583cc
Created August 4, 2015 03:05
golang interface experiments
type count int32
type incrementable interface {
Inc()
}
type countable interface {
incrementable
Dec()
cmake -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo -DLLVM_ENABLE_ASSERTIONS:BOOL=ON -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/python2 -DCMAKE_INSTALL_PREFIX:PATH=/usr ../llvm
@hnsl
hnsl / gist:b078f0b7e4d99872ec90
Created April 8, 2015 15:34
librcd normal distribution
static double gaussian_noise(double mu, double sigma) {
double u1;
do {
u1 = ((double) lwt_rdrand64()) * (1.0 / (double) UINT64_MAX);
} while (u1 <= (DBL_EPSILON));
double u2 = ((double) lwt_rdrand64()) * (1.0 / (double) UINT64_MAX);
double z0 = sqrt(-2.0 * log(u1)) * cos((2.0 * M_PI) * u2);
return z0 * sigma + mu;
}
CREATE OR REPLACE FUNCTION public.json_append(data json, insert_data json)
RETURNS json
IMMUTABLE
LANGUAGE sql
AS $$
SELECT ('{'||string_agg(to_json(key)||':'||value, ',')||'}')::json
FROM (
SELECT * FROM json_each(data)
UNION ALL
SELECT * FROM json_each(insert_data)