This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip3 freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U |