Skip to content

Instantly share code, notes, and snippets.

View ikr's full-sized avatar

Ivan Krechetov ikr

View GitHub Profile
@ikr
ikr / gist:728304
Created December 4, 2010 16:34
Factorial in JS without loops or direct recursion
var ikr = {
partFactorial: function (self) {
return (function (n) {
return (
(0 === n)? 1 : (n * (self(self))(n - 1))
);
});
},
factorial: function (n) {
@ikr
ikr / gist:737318
Created December 11, 2010 11:12
Factorial function defined for n ∈ [0, 6]
var identity = function (x) {
return x;
};
var almost_factorial = function (f) {
return function (n) {
return (
(0 === n)?
1 :
(n * f(n - 1)));
@ikr
ikr / Y.js
Created February 18, 2011 07:48
function (f) {
return function (self) {
return function (x) {
return f(self(self))(x);
};
}(
function (self) {
return function (x) {
return f(self(self))(x);
};
@ikr
ikr / fref.js
Created February 18, 2011 11:39
var factorial = function (n) {
return (n? n * factorial(n - 1) : 1);
};
var originalFactorial = factorial;
factorial = function() { return 0; };
print(originalFactorial(5)); // 0
var factorial = function f(n) {
return (n? n * f(n - 1) : 1);
};
var originalFactorial = factorial;
factorial = function() { return 0; };
print(originalFactorial(5)); // 120
@ikr
ikr / gist:848920
Created March 1, 2011 09:58
null all files
#!/bin/sh
for f in $(find -type f .)
do
echo "" > $f
done
@ikr
ikr / undefined.js
Created March 8, 2011 06:56
Protection against someone defining the "undefined"
var undefined = 1;
(function (undefined) {
print(undefined); // really undefined, not 1
}());
@ikr
ikr / gist:866870
Created March 12, 2011 00:42
git branch in command prompt
export PS1="\[\033[38m\]\u@\h\[\033[01;34m\] \W \[\033[31m\]\`ruby -e \"print (%x{git branch 2> /dev/null}.grep(/^\*/).first || '').gsub(/^\* (.+)$/, '(\1) ')\"\`\[\033[00m\]$\[\033[00m\] "
@ikr
ikr / gist:875875
Created March 18, 2011 10:35
Adding myself to Apache's user group (_www) on Mac OS X
sudo dseditgroup -o edit -a ikr -t user _www
typedef struct {
item_type q[PQ_SIZE+1]; /* body of queue */
int n; /* number of queue elements */
} priority_queue;
pq_parent(int n) {
if (n == 1) return(-1);
else return((int) n/2);
}