Skip to content

Instantly share code, notes, and snippets.

View git2samus's full-sized avatar

Michael Cetrulo git2samus

View GitHub Profile
// ==UserScript==
// @name mangareader
// @namespace git2samus
// @include http://www.mangareader.net/*
// @match http://www.mangareader.net/*
// ==/UserScript==
if (document.getElementById('imgholder'))
window.location.hash = '#imgholder';
// ==UserScript==
// @name reddit comment animation
// @namespace git2samus
// @include http://www.reddit.com/*
// @match http://www.reddit.com/*
// ==/UserScript==
/* Frame class:
* represents a single frame in the animation
*/
function range() {
switch (arguments.length) {
case 1:
var start=0, stop=arguments[0], step=1;
break;
case 2:
var start=arguments[0], stop=arguments[1], step=1;
break;
case 3:
var start=arguments[0], stop=arguments[1], step=arguments[2];
function squareGuessFactory(x) {
var guess=1;
return function() {
guess -= (guess*guess-x) / (2*guess);
return guess;
};
};
function newton_square_root(x, e) {
function newton_square_root(x, e) {
var guess = 1;
while (Math.abs(x - guess*guess) > e)
guess -= (guess*guess-x) / (2*guess);
return guess;
}
> function fibonacciFactory() {
var a=0, b=1;
return function() {
var next=a+b;
a=b, b=next;
return a;
};
};
undefined
> next_fibonacci = fibonacciFactory();
> function integerFactory() {
var n=0;
return function() {
return n++;
};
};
undefined
> next_integer = integerFactory();
function () { return n++; }
> next_integer();
@git2samus
git2samus / gist:2341447
Created April 9, 2012 04:34
lazy merge-sort
(defn lazy-sort
([input-seq]
(lazy-sort (merge-step [(first input-seq)] [(second input-seq)]) (drop 2 input-seq)))
([partial-result input-seq]
(let [result-length (count partial-result)]
(if (seq input-seq)
(recur (merge-step partial-result (divide-step (take result-length input-seq))) (drop result-length input-seq))
partial-result))))
@git2samus
git2samus / gist:2341265
Created April 9, 2012 03:52
merge-sort as a recursive function
(defn merge-step
([seq1 seq2]
(merge-step [] seq1 seq2))
([result seq1 seq2]
(let [head1 (first seq1)
head2 (first seq2)]
(cond
(nil? head1) (concat result seq2)
(nil? head2) (concat result seq1)
:else (if (< head1 head2)
@git2samus
git2samus / gist:2339850
Created April 8, 2012 21:08
merge-sort as a list generator
(defn merge-step [seq1 seq2]
(let [head1 (first seq1)
head2 (first seq2)]
(cond
(nil? head1) seq2
(nil? head2) seq1
:else (if (< head1 head2)
(cons head1 (merge-step (rest seq1) seq2))
(cons head2 (merge-step seq1 (rest seq2)))))))