Skip to content

Instantly share code, notes, and snippets.

View H2CO3's full-sized avatar
🦀

Árpád Goretity  H2CO3

🦀
View GitHub Profile
//
// derive.c
// just because
// (just because I wanted to demonstrate what the Sparkling API is good for)
//
// created by H2CO3 on 31/01/2014
// use for good, not for evil
//
#include <stdio.h>
var six_factorial = function(f, x) {
return f(f, x);
}(function(f, x) {
return x < 2 ? 1 : x * f(f, x - 1);
}, 6);
@H2CO3
H2CO3 / bf.spn
Last active August 29, 2015 13:56
//
// bf.spn
// a Brainfuck parser and interpreter in Sparkling
//
// by Arpad Goretity (H2CO3)
// The "zeroise" optimization is based on the idea of Daniel Silverstone
// run as: spn bf.spn foo.bf
//
global ins_incrmt = 0,
function rrot(a, begin, k) {
var n = k - 1;
var tmp = a[begin + n];
for var i = n; i > 0; i-- {
a[begin + i % k] = a[begin + (i - 1) % k];
}
a[begin] = tmp;
}
function toFact(n, ndigs) {
function curry(fn) {
let curry_argc = argc - 1;
var curry_args = {};
for var i = 0; i < curry_argc; i++ {
curry_args[i] = #i;
}
return function() {
for var i = 0; i < argc; i++ {
//
// WARNING:
// a "Greeter" class is a typical BAD example,
// an anti-pattern. You shouldn't be making this
// a class IRL. I've only come up with this
// example because I've run out of creative sauce.
//
function Greeter(msg) {
var self = {
#!/usr/local/bin/spn
# Playing around with differential geometry is fun!
let derivative = function derivative(fn) {
return function(x0) {
let f = fn;
let dx = 1.0e-5;
let x = x0 + dx;
let y0 = f(x0), y = f(x);
@H2CO3
H2CO3 / cplx_mat.js
Last active August 29, 2015 14:06
Playin' around with complex matrices...
# Computes conjugate transpose of M
let conjTransp = function conjTransp(M) {
return map(range(sizeof M[0]), function(row) {
return map(range(sizeof M), function(col) {
return cplx_conj(M[col][row]);
});
});
};
# Helper for cplxMatMul
@H2CO3
H2CO3 / hash_cfdictionary.c
Last active August 29, 2015 14:07
NSMutableDictionary vs. CFMutableDictionaryRef vs. SpnHashMap – a top-off-my-head benchmark
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#import <CoreFoundation/CoreFoundation.h>
#define KEYSIZE (10 + 1 + 1)
int main()
{
@H2CO3
H2CO3 / fib.c
Last active August 29, 2015 14:09
Argument passing benchmark
#include <stdio.h>
unsigned long fib1(unsigned long n)
{
return n < 2 ? 1 : fib1(n - 1) + fib1(n - 2);
}
unsigned long fib2(unsigned long n, unsigned long m)
{
return n < 2 ? 1 : fib2(n - 1, m) + fib2(n - 2, m);