Skip to content

Instantly share code, notes, and snippets.

View spulec's full-sized avatar

Steve Pulec spulec

View GitHub Profile
@spulec
spulec / flask_moto.py
Created March 14, 2015 23:41
flask moto test
from flask import Flask
app = Flask(__name__)
import boto
from moto import mock_s3
@app.route("/")
def hello():
conn = boto.connect_s3('the_key', 'the_secret')
bucket = conn.create_bucket('mybucket')
@spulec
spulec / gist:8285482
Created January 6, 2014 16:36
Auto activate virtualenvs in new terminal windows.
# If we are in a Development folder, we're probably in a virtual env. Try to activate it based on our CWD.
IN=$PWD
if [[ "$IN" == */Development/* ]]
then
arrIN=(${IN//// })
# This assumes Development is the third token and your project directory is the fourth
workon ${arrIN[3]}
fi
@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
@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?
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:6061741
Last active December 20, 2015 03:09
Tester
print "Hello, {{ name }}"
@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: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 / 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 / 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;