Skip to content

Instantly share code, notes, and snippets.

View viebel's full-sized avatar

Yehonathan Sharvit viebel

View GitHub Profile
@viebel
viebel / nvd3_chart.js
Created June 16, 2016 20:01
create a nvd3 chart
data = function() {
var sin = [],
cos = [];
for (var i = 0; i < 100; i++) {
sin.push({
x: i, y: Math.sin(i/10)}
);
cos.push({
x: i, y: .5 * Math.cos(i/10)}
);
def multiplication_table(n)
str = " |" + (" %3d" * n) % [*1..n]
str += "\n"
str += "----+" + "----" * n
str += "\n"
1.upto(n) do |x|
str += "%3d |" % x
1.upto(x-1) {|y| str += " "}
x.upto(n) {|y| str += " %3d" % (x*y)}
str += "\n"
function cartesianProductOf() {
return _.reduce(arguments, function(a, b) {
return _.flatten(_.map(a, function(x) {
return _.map(b, function(y) {
return x.concat([y]);
});
}), true);
}, [ [] ]);
};
function bar(x) {
return x + x;
}
print "Hello from Gist PHP!";
class Voice {
public function loud($text) {
return $text . '!!!!!!';
}
}
$lang = new Voice;
echo $lang->loud("PHP");
@viebel
viebel / defprint.cljs
Created July 14, 2016 07:03
The defprint macro defines a function with a tweak: each time the function is called, it prints the values of its arguments. The tricky part is that it works also with desctructuring.
(ns my.best$macros)
(defmacro defprint1 [func-name args & body]
`(defn ~func-name [& args#]
(print '~func-name "called with: " args#)
(let [~args args#]
~@body)))
(defmacro defprint2
[name args & body]
@viebel
viebel / primes.go
Created July 18, 2016 03:46
A concurrent prime sieve
// A concurrent prime sieve
package main
import "fmt"
// Send the sequence 2, 3, 4, ... to channel 'ch'.
func Generate(ch chan<- int) {
for i := 2; ; i++ {
ch <- i // Send 'i' to channel 'ch'.
@viebel
viebel / number-lambda.cljs
Created July 22, 2016 06:06
Numbers in Lambda Calculus
(defn v [x]
(list 'λ x))
(defn view [n] ((n v) 'x))
(deftype LambdaNum [n]
Object
(toString [this] (str (view this)))
(equiv [this other] (-equiv this other))
@viebel
viebel / lambda_calculus.cljs
Last active July 26, 2016 19:00
Constructing the arithmetic only with functions. This gist is used by articles inside blog.klipse.tech. Be careful not to break the articles.
(defn visual [x]
(list 'f x))
(defn view [f]
((f visual) 'x))
(deftype Lambda [f]
Object
(toString [_] (str (view f)))