Skip to content

Instantly share code, notes, and snippets.

View beaumartinez's full-sized avatar
😂
I don't use GitHub

Beau beaumartinez

😂
I don't use GitHub
View GitHub Profile
@beaumartinez
beaumartinez / gaecache.py
Created August 9, 2011 21:15
Use GAE's Memcache to cache functions
import google.appengine.api.memcache
DEFAULT_CACHE_TTL = 60 * 60 * 24
def cache(function, ttl=DEFAULT_CACHE_TTL):
'''Cache `function` and its arguments for `ttl` seconds in GAE's
Memcache.
Usable as a decorator.
'''
@beaumartinez
beaumartinez / markdown.rb
Created September 8, 2011 19:53
Render the passed file with GitHub's Markdown renderer
require 'rubygems'
require 'redcarpet'
path = ARGV[0]
file = File.open(path, 'r')
contents = file.read
markdown_renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
html = markdown_renderer.render(contents)
@beaumartinez
beaumartinez / emoticons
Last active September 27, 2015 06:39
Emoticons and shit
░░░░░░░▄▄▄█████▄▄▄░░░░░░░
░░░░░██░░░░░░░░░░░██░░░░░
░░░██░░░░░░░░░░░░░░░██░░░
░░█░░░░░░░░░░░░░░░░░░░█░░
░█░▄▀▀▀▄░░░░░░▄▀▀▀▄░░░░█░
░█▐░░▄██▌░░░░▐░░▄██▌░░░░█
█░▐▄▄███▌░░░░▐▄▄███▌░░░░█
█░░░░░░░░░░░░░░░░░░░░░░░█
█░░▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄░░░░█
█░░░█▒▒▒▒▒▒▒▒▒▒▒▒▒▒█░░░░█
@beaumartinez
beaumartinez / gist:1241940
Created September 26, 2011 09:37
Useful Unicode codepoints
U+0A3: £ (POUND SIGN)
U+2013: – (EN DASH)
U+2014: — (EM DASH)
U+2015: ― (HORIZONTAL BAR)
U+2122: ™ (TRADE MARK SIGN)
@beaumartinez
beaumartinez / concatting-strings.py
Created March 22, 2012 20:48
Concatting strings
# The "idiomaitc" way to concat strings in Python is
characters = ('a', 'b', 'c')
string = ''.join(characters)
# What's nice is that we can store all the strings in a list
characters = list()
for codepoint in range(ord('a'), ord('z') + 1):
@beaumartinez
beaumartinez / requests_oauth.py
Created June 1, 2012 09:48
requests-oauth demo
import requests
from oauth_hook import OAuthHook
def oauth_session(consumer_key, consumer_secret):
hook = OAuthHook(consumer_key=consumer_key, consumer_secret=consumer_secret)
session = requests.session(hooks={'pre_request': hook})
return session
@beaumartinez
beaumartinez / pandas_issue.py
Created August 8, 2012 11:54
Pandas data issues
from itertools import imap, izip
import datetime
import pandas
data = (
{u'_id': u'770000000006',
u'value': {u'timestamps': [datetime.datetime(2012, 5, 11, 15, 19, 49, 695000),
datetime.datetime(2012, 5, 11, 15, 25, 51, 586000),
datetime.datetime(2012, 5, 11, 15, 40, 11, 206000),
def split_at_predicate(predicate, sequence):
split_sequence = list()
for item in sequence:
if predicate(item):
yield split_sequence
split_sequence = list()
split_sequence.append(item)
from lxml.html import fromstring
from requests import get
def get_soups():
'''Get today's soups at Pret.
Return a list in the format:
['Sausage Hot Pot', 'Lentil & Coconut Curry', 'Cream of Mushroom']
#! /usr/bin/env casperjs
var casper = require('casper').create({
logLevel: 'debug',
verbose: true,
viewportSize: {
width: 1280,
height: 800,
},
pageSettings: {