Skip to content

Instantly share code, notes, and snippets.

@jpetazzo
jpetazzo / spotify.sh
Created August 19, 2011 06:53
If Spotify crashes right after start, try this.
#!/bin/sh
# Hopefully fixes the infamous "Spotify crashes immediately on startup" bug.
# In fact, it does not crash immediately; it seems to be crashing while
# looking for local files. The first time you start Spotify after the boot
# of your machine, you will have maybe 10 seconds before it crashes. Then,
# after each start, it will crash almost instantly (less than one second on
# my box).
#
# The following workaround replaces one of Spotify's configuration files
# with a FIFO, effectively preventing reading from the file. Then, it writes
@jpetazzo
jpetazzo / README
Created December 7, 2011 10:13
Get an "admin" port suitable for long-running HTTP connections (for e.g. big imports that take more than 1 minute)
Edit your dotcloud.yml file to add the "ports" section as shown in the sample dotcloud.yml.
Add a supervisord.conf to start the socat program.
Push your code. Use "dotcloud info" to retrieve the host+port to be used for your admin connection (it's conveniently named "admin" since it's what we requested in dotcloud.yml). Enjoy!
Note: this won't work with the custom service, but can be easily adapted if needed.
# Find all minutes during which there was at least one "502" status code:
grep ' 502 ' http.log | awk '{print $4}' | cut -d: -f1-3 | uniq
# Find all minutes during which there were valid requests (excluding 502 and 400 status codes):
grep -v ' 502 ' http.log | grep -v ' 400 ' | awk '{print $4}' | cut -d: -f1-3 | uniq
# If you want hours instead of minutes, replace f1-3 by f1-2.
@jpetazzo
jpetazzo / builder.sh
Created January 5, 2012 09:10
dotCloud builder for Cromlech
#!/bin/bash
[ -d ~/bin ] || virtualenv ~
. ~/bin/activate
cp -a . ~
cd
python bootstrap.py
sed -i 's/port = 8080/port = 42800/g' base.cfg # ugly hack
buildout
@jpetazzo
jpetazzo / pulseaudio-volume-control.py
Created January 7, 2012 22:24
Little script that I use to change the Pulseaudio volume with my keyboard bindings
#!/usr/bin/env python
import commands, sys, os
padump = commands.getoutput('pacmd dump').split('\n')
if sys.argv[1]=='toggle':
for muteline in padump:
if 'set-sink-mute' in muteline:
cmd, src, val = muteline.split()
val = {'yes':'no', 'no':'yes'}[val]
os.system('pacmd {cmd} {src} {val} >/dev/null'.format(**locals()))
else:
@jpetazzo
jpetazzo / rrdgauge.sh
Created February 4, 2012 06:43
Example of rrdtool GAUGE to store a value between 0 and 100
#!/bin/sh
rrdtool create foo.rrd --start -2h --step 900 DS:foo:GAUGE:3600:0:100 RRA:AVERAGE:0.5:1:1000
for N in $(seq 20 -1 1)
do
rrdtool update foo.rrd -- -$(($N*600)):$N$N
rrdtool lastupdate foo.rrd
done
rrdtool graph --start -1h foo.png DEF:foo=foo.rrd:foo:AVERAGE LINE:foo#000000:thefoo
rrdtool fetch foo.rrd AVERAGE | tail
@jpetazzo
jpetazzo / README
Created February 10, 2012 11:00
all-in-one ruby + memcached + jetty
Use this like the "ruby" service: it will install dependencies from Gemfile, and look for a Rails/Rack environment to serve it with passenger.
However, it will also run:
- a local memcached, on port 11211
- a local jetty configured to deploy WAR files, with servlets & JSP support, on port 8080
Place WAR files in the webapps directory as in this example.
If you need to add worker processes, add them to dotcloud.yml, in the processes section.
#!/usr/bin/env python
A = [1, 8, -3, 0, 1, 3, -2, 4, 5]
def complementary_pairs(K, A):
buckets = {}
for x in A:
if x not in buckets:
buckets[x] = 0
buckets[x] += 1
@jpetazzo
jpetazzo / README.md
Created April 4, 2012 16:20
Repair a Riak bitcask-based cluster when the ring has gone out of control

So I heard you hosed your Riak cluster

I don't know what you did (I don't know what I did when this happened to me), but you ended up with a completely borked Riak cluster. Possible causes and symptoms include:

  • riak-admin transfers shows different things depending on the node you run it on
  • you tried to leave/join nodes to fix things, but it made them only worse
  • you ran mixed versions in parallel, instead of doing a clean rolling upgrade
  • some data seems to be missing, and when you list the keys in a bucket, clearly there is not the amount you were expecting
  • YOU'RE AFRAID YOU MIGHT HAVE LOST DATA
@jpetazzo
jpetazzo / delete-a-riak-bucket.py
Created April 4, 2012 23:25
Quick and dirty script to wipe out the content of a single Riak bucket
#!/usr/bin/env python
# delete a given riak bucket
import sys
import requests
import json
from pprint import pprint
if len(sys.argv) < 3: