Skip to content

Instantly share code, notes, and snippets.

@rob-b
rob-b / dotfiles.yml
Created October 23, 2013 20:21
Ansible playbooks for building silver searcher and the latest versions of vim + tmux from source and for installing my dotfiles
---
- hosts: webservers
connection: ssh
user: $user
sudo: yes
tasks:
- name: Install dotfile essentials
apt: pkg=$item state=latest install_recommends=no update_cache=yes cache_valid_time=3600
with_items:
- cmake
@rob-b
rob-b / gist:6914238
Created October 10, 2013 07:07
pyramid_jinja2 doesn't easily work with appengine; here's the changes needed
commit ae9c6a6dc96897d6d82db20bfca68df813f5dabb
Author: Rob Berry
Date: Thu Oct 10 08:00:02 2013 +0100
Add pyramid_jinja2
diff --git a/buildout.cfg b/buildout.cfg
index 2510ba1..367938f 100644
--- a/buildout.cfg
+++ b/buildout.cfg
@rob-b
rob-b / .env
Created October 9, 2013 09:41
Autoenv .env file for buildout projects
echo Prepending $(dirname $0)/bin to PATH
new=$(dirname $0)/bin
typeset -U path
path=($new "$path[@]")
export PATH
@rob-b
rob-b / ec2.yml
Created September 17, 2013 12:10
- name: ec2 instance
hosts: localhost
connection: local
# user: root
gather_facts: false
vars:
keypair: lostproperty
instance_type: m1.small
security_group: default
from functools import update_wrapper
def cached_property(f, name=None):
if not name:
name = f.__name__
prop = '_%s' % name
def _get_property(self):
#!/usr/bin/env python
# coding: utf-8
def easy_input(question, answer=None, default=None):
"""Ask a question, return an answer.
<question> is a string that is presented to the user.
<answer> is a list of strings presented as a choice. User may type only first letters
<default> is the presumed answer if the user just hits <Enter>.
@rob-b
rob-b / gist:5501046
Created May 2, 2013 08:59
Very basic ansible config
---
- hosts: webservers
user: root
tasks:
- name: create admin group
action: group name=ubuntu gid=1000 system=no
- name: create user
action: user name=ubuntu group=ubuntu shell=/bin/zsh uid=1000
!/bin/bash
#
# This git update hook will refuse unnecessary merge commits caused by pulling
# from being pushed to a shared repository. These commits make following the
# history of a project difficult and are always avoidable with rebasing.
#
# by Scott Kyle (appden)
# modified by Olivier Refalo (orefalo)
refname="$1"
def daterange(date, to=None):
condition = lambda x: (x <= to) if to else lambda x: True
step = datetime.timedelta(days=1)
while condition(date):
yield date
date += step
def inclusive_daterange(date, to=None):
if to:

Pytest's session fixture scope is really handy, but there are some things which need to execute only once per actual test session. For example, one of my session fixtures sets up DB tables at the start of the test session and tears them down at the end. (I use PostgreSQL's nested transactions to keep from having to drop and recreate tables between each individual test.)

@pytest.fixture(scope='session')
def dbtables(request, sqlengine):
    Base.metadata.create_all(sqlengine)

    def teardown():
        Base.metadata.drop_all(sqlengine)