Skip to content

Instantly share code, notes, and snippets.

View hellerve's full-sized avatar

Veit Heller hellerve

View GitHub Profile
@hellerve
hellerve / guess_the_number.bingo
Created January 8, 2015 12:26
An example bingo program
secret_number gets between: 1 10
3 times
write: Choose a number from 1 to 10.
my_number gets ask: >
if my_number is @secret_number
write: You win! The number was @secret_number.
quit
else
@hellerve
hellerve / gist:dd77db4bccfed583f102
Created February 5, 2015 14:40
Obscure C++ syntax
#include <stdio.h>
int main() <%
int x <:3] = {1, 2, 3%>;
printf("%d, %d, %d\n", x[0:>, x<:1], x<:2:>);
return 0;
}
@hellerve
hellerve / gist:59a7d3c4d1a7054ab7fb
Created July 16, 2015 16:29
Private methods in JS
var myObj = (function() {
function myObj(something) {
this.something = something;
}
function privateMethod() {
console.log("private method called");
}
myObj.prototype.publicMethod = function() {
@hellerve
hellerve / templating.js
Last active January 5, 2016 03:58
The Poor Man's Templating Engine In JS
function templating(template, values) {
for(var k in values) {
template = template.replace('{{' + k.toString() + '}}', values[k].toString());
}
return template;
}
@hellerve
hellerve / templating.zp
Last active October 20, 2015 16:16
The poor man's templating engine in zepto
(define (templating template values)
(hash:keys-reduce (lambda (template k) (string:substitute template (++ "{{" k "}}") (values k))) template values))
@hellerve
hellerve / knapsack-combinatorics.zp
Last active November 23, 2015 11:31
This is a zepto solution to a problem described in SICP 1.2.2
;; Solution to:
;; How many different ways can we make change of $ 1.00, given half-dollars, quarters, dimes, nickels, and pennies?
;; More generally, can we write a procedure to compute the number of ways to change any given amount of money?
;;
;; Example usage for $1.00: (count-change 100) => 292
;; This computation takes around 0.6 secs on my machine in zepto.
(define (count-change amount)
(cc amount 5))
@hellerve
hellerve / Array.prototype.next.js
Created January 5, 2016 11:27
A next() and previous() method for arrays with builtin wraparound
Array.prototype.next = function(i) {
return this[++i % this.length];
}
Array.prototype.previous = function(i) {
return i === 0 ? this[this.length - 1] : this[--i % this.length];
}
@hellerve
hellerve / fu.clj
Created January 15, 2016 19:03
How to fuck up a clojure devs day
; Sneak this in somewhere
(defmacro = [& args] (apply (rand-nth [identical? not=]) args))
@hellerve
hellerve / bench.carp
Created October 24, 2017 16:32
Simple benchmarking in carp
(system-include "../bench.h")
(register get-time-elapsed (Fn [] Double))
(defn min [a]
(let [m (Double.copy (Array.nth a 0))]
(do
(for [i 1 (Array.count a)]
(let [el (Double.copy (Array.nth a i))]
(if (Double.< el m)
@hellerve
hellerve / b64.h
Created April 3, 2018 14:59
A Carp CLI for commandlinefu.com
#include <string.h>
#include <stdlib.h>
#include <core.h>
static const char base64_table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
String b64(String* osrc) {
String src = *osrc;
int len = strlen(src);
char *pos;