Skip to content

Instantly share code, notes, and snippets.

Avatar
🎱
¯\_(ツ)_/¯

Sander van de Graaf svdgraaf

🎱
¯\_(ツ)_/¯
View GitHub Profile
@svdgraaf
svdgraaf / Ponies.py
Created Sep 24, 2010
Embedding V8 in Python is awesome
View Ponies.py
# import PyV8, duh!
import PyV8
# define a class which methods should be available in Javascript
class epicClass(PyV8.JSClass):
def ponies(self):
return "Ponies!"
def doubletime(self, what, amount):
for i in range(0, amount):
@svdgraaf
svdgraaf / gist:1218812
Created Sep 15, 2011
Running Django on Heroku
View gist:1218812
# create a dir
mkdir foobar
cd foobar
# instantiate a virtual environment
virtualenv --no-site-packages .
# start your virtualenv
source bin/activate
View gist:1985675
{
"environments": [],
"name": "focus",
"repository": {
"location": "git@github.com:hub-nl/nl.focusmedia.git",
"name": "foo",
"variant": "git"
},
"variant": "python"
}
View python-transitions-graph.py
import pygraphviz as pgv
class MachineGraph(object):
def get_graph(self, title=None):
"""Generate a DOT graph with pygraphviz."""
state_attrs = {
'shape': 'circle',
'height': '1.2',
}
@svdgraaf
svdgraaf / gist:6078982
Last active Dec 20, 2015
CENTOS 6 with Varnish 3.03 and VMOD support (geoip example)
View gist:6078982
# varnish
sudo yum remove varnish*
sudo rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el6/noarch/varnish-release-3.0-1.el6.noarch.rpm
sudo yum install varnish-3.0.3
sudo yum install pcre-devel libedit libedit-devel
# varnish source
wget http://repo.varnish-cache.org/source/varnish-3.0.3.tar.gz
tar -zxvf varnish-3.0.3.tar.gz
./configure
@svdgraaf
svdgraaf / abtest.vcl
Last active Dec 26, 2015
AB testing with Varnish (and Django)
View abtest.vcl
# import the abtesting vmod
import abtest;
sub vcl_deliver {
# only continue, if the config file with all the rules can be loaded
if (abtest.load_config("/etc/varnish/abtest-rules.cfg") == 0) {
# if there isn't a named cookie 'ab' in the request, we can add one
if (req.http.Cookie !~ "ab=") {
@svdgraaf
svdgraaf / bottombar.sh
Created Nov 17, 2013
Simple ImageMagick Copyright and timestamp bar to any image
View bottombar.sh
convert [inputfilename.jpg] -gravity north -background black -extent [width]x[height] +repage -box black -fill white -pointsize 12 -gravity southwest -annotate +3+3 '(c)Unicorns and magic sparkledust inc.' -gravity southeast -annotate +3+3 "`date +%H:%I`" -quality 99% output.png
View keybase.md

Keybase proof

I hereby claim:

  • I am svdgraaf on github.
  • I am svdgraaf (https://keybase.io/svdgraaf) on keybase.
  • I have a public key ASCNRi7ZhWzZoXGXEv3E6dxE6R62g1x_e5w_22l1u0ZrJgo

To claim this, I am signing this object:

@svdgraaf
svdgraaf / update_hosts_file.py
Last active Mar 22, 2017
Update AWS instance hosts file with all internal dns names for VPC members. Useful when dns discovery is not useable/available.
View update_hosts_file.py
#!/usr/bin/env python
import boto3
import requests
ec2 = boto3.resource('ec2')
# fetch the instance id
response = requests.get('http://169.254.169.254/latest/meta-data/instance-id')
instance_id = response.text
@svdgraaf
svdgraaf / buildspec.yaml
Created Jan 6, 2017
AWS CodePipeline CloudFormation template length workaround
View buildspec.yaml
version: 0.1
phases:
pre_build:
commands:
- pip install awscli
build:
commands:
post_build:
commands: