Skip to content

Instantly share code, notes, and snippets.

View spulec's full-sized avatar

Steve Pulec spulec

View GitHub Profile
@spulec
spulec / pre-commit
Last active January 13, 2023 02:26
Yipit Pre-commit Hook
#!/usr/bin/env python
import os
import re
import subprocess
import sys
modified = re.compile('^[MA]\s+(?P<name>.*)$')
CHECKS = [
@spulec
spulec / robot.js
Created December 1, 2012 02:11 — forked from cezarsa/robot.js
Simple Wall Robot
var Robot = function(robot){
robot.turnLeft(robot.angle % 90);
robot.turnGunRight(90);
robot.clone();
this.direction = 1;
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(1);
if (robot.parentId) {
@spulec
spulec / robot.js
Created December 1, 2012 02:21 — forked from heynemann/robot.js
Back and Forth
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot){
robot.clone();
this.direction = 1;
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
@spulec
spulec / chef_setup.sh
Last active December 11, 2015 03:59
chef machine base setup
if [ ! -f /usr/local/bin/chef-client ]; then
# Become up to date
apt-get update
# Get our basics
apt-get install -y -q ruby1.9.1 ruby1.9.1-dev build-essential wget
fi
gem install ohai --no-rdoc --no-ri
gem install right_aws --no-ri --no-rdoc
gem install chef --no-rdoc --no-ri --version '10.16.4'
@spulec
spulec / gist:4586854
Created January 21, 2013 15:30
Add encoding and __future__ imports to all .py files in a repo.
import subprocess
import shlex
files = subprocess.check_output(shlex.split('git ls-files --full-name')).strip().split('\n')
py_files = [file for file in files if file.endswith(".py")]
len(py_files)
new_header = '# -*- coding: utf-8 -*-\nfrom __future__ import unicode_literals\n'
for the_file in py_files:
read_file = open(the_file, 'r')
lines = list(read_file)
result_lines = []
@spulec
spulec / gist:5131669
Created March 11, 2013 03:19
Read python source file from encoding.
import codecs
import re
opened_file = open(filename, "r")
encoding_line = opened_file.readline()
opened_file.close()
encoding_regex = re.compile('# -\*- coding:(.*) -\*-')
results = re.search(encoding_regex, encoding_line)
if results:
encoding = results.groups()[0]
else:
@spulec
spulec / gist:6061741
Last active December 20, 2015 03:09
Tester
print "Hello, {{ name }}"
import boto
conn = boto.connect_s3()
bucket = conn.get_bucket("{{ bucket }}")
key = bucket.new_key("{{ filename }}")
key.set_contents_from_filename("{{ filename }}")
url = key.generate_url({% if expires %}{{ expires }}{% else %}3600{% endif %})
print url
@spulec
spulec / gist:6241822
Created August 15, 2013 15:34
The values in the test look right in my pdb, but not when the test runs
- Have you accounted for any timing issues? Your pdb is probably running a second or two after the test assertions run.
- Could there be a unicode vs bytestring issues? It's possible that strings you type in your pdb are one thing while strings in your test files are another. This espcially applies if you use unicode_literals, since most pdb-like programs still use bytestrings as input.
- Could it be that in the pdb your code is running a function additional times and that function has side-effects?
@spulec
spulec / gist:6799081
Created October 2, 2013 19:18
HTTPretty runner
Fixtures/Command line runner
It would be awesome if there were a command line runner. For example, imagine I run a django app that relies on a ton of external APIs. It would be great for development if I could run `httpretty manage.py runserver` and all of the calls would be mocked accordingly. `httpretty` would import a file named `.httpretty.py` which would setup all the routing configuration.
Happy to do some work on this if it sounds interesting.
Example `.httpretty.py`
```python