Skip to content

Instantly share code, notes, and snippets.

@Idorobots
Idorobots / gist:3894107
Created October 15, 2012 18:15
ASM DFD generator
(DFD (Database "Dane_Klientów")
(I/O "Klient")
(Process "Weryfikacja_Zamówienia")
(Flow "Zamówienie" "Klient" "Weryfikacja_Zamówienia")
(Flow "Odmowa" "Weryfikacja_Zamówienia" "Klient")
(Process "Weryfikacja_Danych_Kredytowych")
(Flow "Zweryfikowane_zamówienie" "Weryfikacja_Zamówienia" "Weryfikacja_Danych_Kredytowych")
(Flow "Informacja_o_błędnych_danych" "Weryfikacja_Danych_Kredytowych" "Klient")
(Flow "Gotowe_zamówienie" "Weryfikacja_Danych_Kredytowych" "Wykonanie_Zamówienia")
(Process "Wykonanie_Zamówienia")
@Idorobots
Idorobots / gist:3955696
Created October 25, 2012 21:57
The parallel HerpDerp VM.
uint[] code = [0,
DERP,
RECEIVE,
CMP, 1,
JUMPL, 1,
MOVEA, 1,
ADDMEM, 0,
CMP, 1,
MOVEAD,
MOVEA, 0,
@Idorobots
Idorobots / gist:4228302
Created December 6, 2012 20:59
Gamify config
(require 'gamify)
(gamify-start)
@Idorobots
Idorobots / gist:4228636
Created December 6, 2012 21:27
Org-Capture targets
(setq org-capture-templates
(list* `("1" "New easy quest." entry (file "")
,(concat "* TODO %?\nSCHEDULED: %t\n"
":PROPERTIES:\n"
":gamify_exp: %(gamify-assign-some-exp 5 2)\n"
":END:\n"
"%U\n%a\n %i\n"))
`("2" "New medium quest." entry (file "")
,(concat "* TODO %?\nSCHEDULED: %t\n"
":PROPERTIES:\n"
@Idorobots
Idorobots / gist:4560378
Last active December 11, 2015 06:38
ASM MOP example featuring inheritance and multimethod dispatch.
(defclass Point (Object)
'x 'y)
#; A constructor
(defmethod initialize ((p Point) initargs)
(call-next-method)
(initialize-slots p initargs))
#; Point3D inherits the ctor
(defclass Point3D (Point)
@Idorobots
Idorobots / gist:4968517
Created February 16, 2013 20:11
Function roots
(define (bisection f a b tol)
(let ((c (* (+ a b) 0.5)))
(cond ((<= (abs (f c)) tol) c)
((> (* (f a) (f c)) 0) (bisection f c b tol))
(else (bisection f a c tol)))))
(define (newton f fp fb a b tol)
(let loop ((c (if (> (* (f a) (fb a)) 0) a b)))
(if (<= (abs (f c)) tol)
c
@Idorobots
Idorobots / gist:4968636
Created February 16, 2013 20:37
Splines in Scheme-like
(define (splines-1 x X Y)
(foldl (lambda (((X0 . Y0) . (X1 . Y1)) result)
(if (<= X0 x X1)
(+ Y0 (* (/ (- Y1 Y0)
(- X1 X0))
(- x X0))
result)))
(let ((zipped (zip X Y)))
(zip zipped (cdr zipped)))))
@Idorobots
Idorobots / gist:5016087
Last active December 14, 2015 02:49
Code that writes code that writes code that defines a virtual machine emulator.
(defmacro defvm (regs @tuple body)
(append `(do (defmacro defop (name @tuple body)
(append (tuple 'defun name '$regs
(append (tuple 'dump (stringof name)) '$regs))
body))
(defmacro go (name)
(cons name '$regs)))
(map (lambda (op)
(append `(defop $(car op))
@Idorobots
Idorobots / gist:5021523
Last active December 14, 2015 03:29
Simple Hillis-Steele inclusive scan algorithm implementation.
V hillis_steele(alias op, V)(V array) {
for(size_t i = 1; i < array.length; i *= 2) {
for(size_t j = array.length; j > 0; --j) {
if(j > i) {
array[j-1] = op(array[j-1-i], array[j-1]);
}
}
}
return array;
}
@Idorobots
Idorobots / gist:5147755
Created March 12, 2013 22:40
Matlab fminunc example.
function zad5()
foo = @(x1, x2) 100*(x2 - x1^2)^2 + (sqrt(2) - x1)^2;
bar = @(x) foo(x(1), x(2));
X0 = [0; 0];
Ymin = fminunc(bar, X0);
Ymin