Skip to content

Instantly share code, notes, and snippets.

View drguildo's full-sized avatar

Simon Morgan drguildo

View GitHub Profile
@drguildo
drguildo / gist:147121
Last active August 30, 2015 13:54
A bookmarklet that prompts the user for a search pattern and lists all links on the current page that match it.
// javascript:(function(){var x,nD,z,i;x=prompt("Pattern:", "");if(x!=null){nD=window.open().document;nD.writeln('<pre>');z=document.links;for(i=0;i<z.length;++i){if(z[i].href.indexOf(x)!=-1){nD.writeln(z[i].href);}}nD.writeln('</pre>');nD.close();}})();
javascript:(
function(){
var x,nD,z,i;
x=prompt("Pattern:", "");
if(x!=null) {
nD = window.open().document;
nD.writeln('<pre>');
z = document.links;
def read_input():
import sys
data = []
n = int(input())
for i in range(n):
data.append(input())
return data
@drguildo
drguildo / gist:1267961
Created October 6, 2011 17:02
Clojure tail call optimisation
(def rat
(fn x [a]
'(a)
(if (< a 10000)
(x (+ a 4)))))
(def mouse
(fn [a]
'(a)
(if (< a 10000)
@drguildo
drguildo / gist:1340990
Created November 5, 2011 02:10
4clojure problem #26
#((fn fib [n xs]
(if (not (zero? n))
(fib
(dec n)
(conj xs (+ (first (reverse xs)) (fnext (reverse xs)))))
xs)) (- % 2) [1 1])
[joe@numbercruncher ~]$ python
>>> 0.1 * 0.1
0.010000000000000002
>>> ^D
[joe@numbercruncher ~]$ sudo pacman -Rns python
(defn flatn [xs]
(if (not (empty? xs))
(if (seq? (first xs))
(concat (flatn (first xs)) (flatn (rest xs)))
(conj (flatn (rest xs)) (first xs)))))
(defn flatn [xs]
(if (not (empty? xs))
(if (seq? (first xs))
(concat (flatn (first xs)) (flatn (rest xs)))
(conj (flatn (rest xs)) (first xs)))))
@drguildo
drguildo / CompilationEngine.scala
Created April 19, 2012 19:54
IDEA Gist integration test.
if (isNextToken((".", SYMBOL))) {
tokenizer.nextToken()
output.append("<symbol> . </symbol>")
compileIdentifier()
}
@drguildo
drguildo / gist:2658997
Created May 11, 2012 11:04
Calling invokeLater in Scala
SwingUtilities.invokeLater(new Runnable {
def run() {
guiStuff()
}
})
@drguildo
drguildo / gist:3019542
Created June 29, 2012 17:41
Ubiquity Black Box Testing Problem Set
# CORRECT SPECIFICATION:
#
# the Queue class provides a fixed-size FIFO queue of integers
#
# the constructor takes a single parameter: an integer > 0 that
# is the maximum number of elements the queue can hold.
#
# empty() returns True if and only if the queue currently
# holds no elements, and False otherwise.
#