Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/python
import sys
sys.setrecursionlimit(10000)
max = 1000
memo = {}
def collatz(x):
global memo
if x in memo: pass
elif x % 2: memo[x] = x * 3 + 1
@bensonk
bensonk / fls
Created March 23, 2010 06:47
Fuzzy file lister written in python.
#!/usr/bin/env python
import sys, os, os.path
def match(query, item):
for c in query:
if c in item: item = item[item.find(c)+1:]
else: return False
return True
def finder(query, items):
return [ item for item in items if match(query, item) ]
import os, sys
class Newquitter(object):
def __call__(s, v):
sys.exit(v)
def __repr__(s):
if os.isatty(sys.stdout.fileno()): sys.exit(0)
else: return "Use exit() or Ctrl-D (i.e. EOF) to exit"
__str__ = __repr__
class Child(Parent):
def __init__(self, x):
# This is crap, Python.
super(Child, self).__init__(x)
import org.someplace.projname.Ingester;
import org.someplace.projname.Processor;
import org.someplace.projname.OutputCleaner;
import org.someplace.projname.Formatter;
public class Test {
public static void main(String[] args){
MifPipeline pipeline = new MifPipeline();
pipeline.addMifModule(Ingester.class.getname(), "stdio://stdin", "vm://one");
pipeline.addMifModule(Processor.class.getname(), "vm://one", "vm://two");
import org.someplace.projname.{Ingester,Processor,OutputCleaner,Formatter};
object MifPipeline extends MifPipelineBuilder {
def main(args: String[]) {
"stdio://in" -> Ingester -> Processor -> OutputCleaner -> Formatter -> "stdio://out"
}
}
#include <iostream>
#include <fstream>
#include <string>
#include <set>
#include <stdlib.h>
using namespace std;
int main(int argc, char** argv) {
if(argc != 2) {
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <set>
#include <stdlib.h>
using namespace std;
int main(int argc, char** argv) {
//submit a new message to the server
function send(msg) {
if (CONFIG.debug === false) {
// XXX should be POST
// XXX should add to messages immediately
jQuery.get("/send", {id: CONFIG.id, text: msg}, function (data) { }, "json");
}
}
class Vector
def normalize
sum_of_squares = to_a.inject(0) { |s, x| s + x*x }
if sum_of_squares == 0
self
else
self * (1 / Math.sqrt(sum_of_squares))
end
end
end