Skip to content

Instantly share code, notes, and snippets.

[1] pry(main)> class Foo
[1] pry(main)* def hello
[1] pry(main)* "Hello from Foo"
[1] pry(main)* end
[1] pry(main)* end
=> nil
[2] pry(main)> module Mod
[2] pry(main)* def hello
[2] pry(main)* "Hello from Mod"
[2] pry(main)* end
In [5]: [ (n, 0.5 ** n) for n in range(1, 15) ]
Out[5]:
[(1, 0.5),
(2, 0.25),
(3, 0.125),
(4, 0.0625),
(5, 0.03125),
(6, 0.015625),
(7, 0.0078125),
(8, 0.00390625),
@bensonk
bensonk / DigiRGB.py
Created February 26, 2013 08:13
Cleaned up version of DigiRGB script
#!/usr/bin/env python
#
# Written for PyUSB 1.0 (w/libusb 1.0.3)
#
# Original Author: follower@rancidbacon.com
# Heavily edited by bensonk42 -at- gmail
#
# Version: 2013-02-26
#
@bensonk
bensonk / mutableflask.py
Created November 28, 2012 21:07
An experiment with mutable global state in flask
from flask import Flask, abort, redirect, url_for
app = Flask(__name__)
class Datastore(object):
def __init__(self, **kwargs):
for k,v in kwargs.items():
self.__setattr__(k, v)
ds = Datastore(who='World')
@app.route('/')
#!/usr/bin/python -u
from os import system
from sys import stdin
while True:
line = stdin.readline()
if '200 OK' in line:
system("notify-send -t 3000 -a Notifier '{}'".format(line))
require 'sinatra'
get "/" do
mpc_output = IO.popen("mpc").readlines.join("<br/>")
"<html><body>" +
" <h3>#{mpc_output}</h3>" +
' <p><a href="prev">prev</a> <a href="/toggle">play/pause</a> <a href="/next">next</a></p>' +
"</body></html>"
end
@bensonk
bensonk / get_hashtags.py
Created July 21, 2012 05:21
A python function to find hashtags in a given tweet
def get_hashtags(tweet):
words = tweet.split()
[ x if x.startswith('#') ]
#!/usr/bin/env python
import re
parser = re.compile(r'(.*?);(.*?);(.{3});(.*?);(.*?);')
def parse_line(l):
res = parser.match(l)
if res:
values = res.groups()
credential = {}
credential['username'] = values[0]
credential['hash'] = values[1]
@bensonk
bensonk / gist:2408123
Created April 17, 2012 18:42
Reddit's headers are funny
[work] bensonk@thay ~ $ nc www.reddit.com 80
GET / HTTP/1.1
Host: www.reddit.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19
Accept: text/html
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: djdt=hide; sessionid=5b192a9ec238e8a4a16e87729b84fc52; __utma=1.800606738.1333945678.1334169935.1334174604.12; __utmz=1.1333945678.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
if (Meteor.is_client) {
var people = new Meteor.Collection("people");
people.insert({name: "Benson"});
Template.people.names = function() {
return people.find();
};
}
if (Meteor.is_server) {