Skip to content

Instantly share code, notes, and snippets.

@asottile
asottile / check_upgradeable.py
Created June 16, 2016 16:11
Check whether a yelp-cheetah template is trivially upgradable to 0.17.0
import argparse
import ast
import io
from Cheetah.compile import compile_source
from Cheetah.Template import Template
template_self_vars = {var for var in dir(Template) if not var.startswith('_')}
@asottile
asottile / SassMeister-input.scss
Created January 30, 2016 07:25
Generated by SassMeister.com.
// ----
// Sass (v3.4.20)
// Compass (v1.0.3)
// ----
a, b {
&:not(c) {
d: e;
}
}
import random
import re
simple_word_regex = re.compile('^[a-z]+$')
word_list = []
with open('/usr/share/dict/american-english', 'r') as words_file:
for word_line in words_file:
word = word_line.strip()
@asottile
asottile / gist:6265617
Last active December 21, 2015 06:39
Patching out modules in Python
import contextlib
import collections
import mock
import sys
def fake_module(**args):
return (collections.namedtuple('module', args.keys())(**args))
def get_patch_dict(dotted_module_path, module):
patch_dict = {}
@asottile
asottile / Range.cpp
Created April 2, 2013 17:02
Python like xrange in c++ with range fors!
#include <iostream>
using std::cout;
using std::endl;
class Range {
public:
explicit Range(int endValue) : start(0), endValue(endValue) { }
Range(int start, int endValue) : start(start), endValue(endValue) { }
@asottile
asottile / GhettoRetry.hpp
Created March 20, 2013 15:47
Ghetto Retry for c++
#ifndef GHETTO_RETRY_H
#define GHETTO_RETRY_H
template<typename TEx, TCall>
void ghettoRetry(TCall call, int count = 1) {
// Retry count number of times
// Note the last one will throw on failure
for (int i = 0; i < count - 1; i += 1) {
try {
call();