Skip to content

Instantly share code, notes, and snippets.

@tobami
tobami / chef-roles-to-json-task.rb
Created February 21, 2011 08:11 — forked from timdiggins/chef-roles-to-json-task.rb
Chef ruby roles to json
# ADD this to Rakefile and run it by issuing rake roles.to_json
ROLE_DIR = File.expand_path(File.join(TOPDIR, "roles"))
namespace :roles do
desc "Convert ruby roles from ruby to json, creating/overwriting json files."
task :to_json do
Dir.glob(File.join(ROLE_DIR, '*.rb')) do |rb_file|
role = Chef::Role.new
role.from_file(rb_file)
json_file = rb_file.sub(/\.rb$/,'.json')
@tobami
tobami / flask_async.py
Created April 15, 2013 14:19
Demonstration of the ability to switchable flask server, from the blocking dev server to the async gevent server. Instructions to test in the comment below
#!/usr/bin/env python
import time
import argparse
import gevent
import gevent.monkey
from gevent.pywsgi import WSGIServer
gevent.monkey.patch_all()
from flask import Flask, request, Response, render_template
@tobami
tobami / upgrade-packages.sh
Created December 2, 2015 09:40
Upgrade all packages in a virtualenv
pip3 freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U
@tobami
tobami / detect-large-objects.sh
Created October 21, 2015 09:26
Displays the largest objects in a git repo
#!/bin/bash
#set -x
# Shows you the largest objects in your repo's pack file.
# Written for osx.
#
# @see http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/
# @author Antony Stubbs
# set the internal field spereator to line break, so that we can iterate easily over the verify-pack output
@tobami
tobami / pypy_branches_migration_script.py
Created April 24, 2011 14:47
Migrate PyPy's Codespeed data to branches
pypy = Project.objects.get(name="pypy")
pypy_trunk = Branch.objects.create(name="trunk", project=pypy)
for rev in Revision.objects.filter(project=pypy):
rev.branch = pypy_trunk
@tobami
tobami / catching urlopen exceptions
Created March 15, 2011 19:10
codespeed/tools/save_single_result.py with exception catching
try:
f = urllib2.urlopen(SPEEDURL + 'result/add/', params)
response = f.read()
f.close()
except urllib2.URLError, e:
if hasattr(e, 'reason'):
response = '\n We failed to reach a server\n'
response += ' Reason: ' + str(e.reason)
elif hasattr(e, 'code'):
response = '\n The server couldn\'t fulfill the request\n'
@tobami
tobami / pymongo_update.py
Created February 18, 2011 08:08
Pure pymongo data saving for cross-benchmarking
def save_data(self, rows):
# Mark all as 'old'
self.db.offers.update(
{'productlist': self.productlist.name},
{'$set': {'old': True}}, multi=True, safe=True)
# Upsert
for row in rows:
# Add productlist key and mark as 'not old'
row['productlist'] = self.productlist.name
@tobami
tobami / mongoengine_models.py
Created February 17, 2011 14:06
MongoEngine models for cross-benchmarks
from mongoengine import *
class ProductList(Document):
name = StringField(required=True, unique=True)
def import_offers(self, offers):
for o in Offer.objects.filter(productlist=self.name):
o.old=True
o.save()
@tobami
tobami / Docker
Last active August 29, 2015 14:04
Boot2docker
Install: http://boot2docker.io/
export DOCKER_HOST=tcp://:2375
# Make a volume container (only need to do this once)
$ docker run -v /data --name my-data busybox true
# Share it using Samba (Windows file sharing)
$ docker run --rm -v /usr/local/bin/docker:/docker -v /var/run/docker.sock:/docker.sock svendowideit/samba my-data
# then find out the IP address of your Boot2Docker host
$ boot2docker ip
192.168.59.103
@tobami
tobami / docker.txt
Created July 23, 2014 15:27
Docker experiments
docker pull debian(:wheezy)
docker run -i -t debian:wheezy /bin/bash
--
install
--
docker commit <container_id> <some_name>
--
docker run -i -t -p 127.0.0.1:3306:3306 -d wheezy-mysql:butler2 "/usr/bin/mysqld_safe"