Skip to content

Instantly share code, notes, and snippets.

View dexterous's full-sized avatar

Saager Mhatre dexterous

View GitHub Profile
@dexterous
dexterous / emails.sed
Created March 8, 2011 09:40
devcamp.in utils
#!/usr/gnu/bin/sed -rf
s_\|\s*(\[\S+\s*)?([^\|]+)\]?\s*\|\|([^\|]+)\|\|.*_"\2" <\3>, _
s_ "_"_g
s_]"_"_
s_< _<_
s_ >_>_
s_\s*\(at\)\s*_@_g
s_\s*\(dot\)\s*_._g
s_\s*\[dot\]\s*_._g
# http://github.com/c42/goldberg/raw/master/Gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.5'
gem 'sqlite3', '~> 1.3.3', :platforms => :ruby
gem 'haml', '~> 3.0.25'
platform :jruby do
@dexterous
dexterous / OS.groovy
Created June 21, 2011 09:31
a not so quick script hacked together to scrape the product info from lenovo's product listing page
enum OS {
DOS('PC DOS 2000 License'), WIN('Genuine Windows 7 Professional 32');
private final String text
private OS(text) { this.text = text }
public static parseText(text) { OS.values().find { it.text == text } }
}
@dexterous
dexterous / terrain.py
Created June 22, 2011 10:51 — forked from groner/terrain.py
Hooks for lettuce to run a test pylons app
'''Hooks for lettuce to run a test pylons app'''
from lettuce import *
from paste.fixture import TestApp
import pylons.test
from paste.deploy.loadwsgi import loadapp
from paste.script.appinstall import SetupCommand
@dexterous
dexterous / prime_generator.py
Created July 5, 2011 09:32
prime number generator in python
def prime_generator():
potential = 2
primes = []
while True:
while any(potential % x == 0 for x in primes):
potential += 1
yield potential
primes.append(potential)
@dexterous
dexterous / shit_error.js
Created July 29, 2011 11:16
The (ho|e)rror!
// if you're going to send back...
{
'status' : 'Failure',
'message' : 'Resource creation failed',
'errors' : ['Problems creating resource in the system']
}
// ... you might as well just save everyone the trouble and send back...
{ 'shit happened': true }
@dexterous
dexterous / method_missing.py
Created August 1, 2011 07:59
python's equivalent of method_missing
#!/usr/bin/env python
class Foo(object):
def explicit_method(self):
return 'called explicit method'
def __getattr__(self, name):
def method_missing(*args, **kwargs):
return 'called %s with %d arguments %s & %d keywords %s' % (name, len(args), args, len(kwargs), kwargs)
return method_missing
@dexterous
dexterous / fac.groovy
Created August 2, 2011 15:20
Groovy factorials!
facTramp = { n, r = 1 -> if (n < 3) { r * n } else { facTramp.trampoline(n - 1, r * n) } }.trampoline()
facIter = { n -> (2g..n).inject(1){ a, e -> a * e } }
assert facTramp(100g) == facIter(100g)
@dexterous
dexterous / literally_dereferenced.py
Created August 4, 2011 12:35
head.bang_on(wall.of(brick.type(material='concrete', colour='lightGray')))
#!/usr/bin/env python
# dear pythonista,
# if...
__builtins__.open == 'foo'
# ... is allowed yet results in...
print __builtins__.open #=> <built-in function open>
@dexterous
dexterous / change_the_world.py
Created August 4, 2011 13:11
python.connect(body_part='palm', to='face')
#!/usr/bin/env python
True, False = False, True
if False:
print 'what the!?!?!?'