Skip to content

Instantly share code, notes, and snippets.

@jpetazzo
jpetazzo / README.md
Created November 15, 2012 20:52
Wrap your WSGI app with Guppy

Edit your wsgi.py file to wrap your application object as shown in the attached example.

Then go to /__guppy__ to see memory usage profiling.

This is very basic and probably needs to be refined.

@jpetazzo
jpetazzo / dotcloud.yml
Created December 3, 2012 20:48
Bitlbee on dotCloud
bitlbee:
type: python-worker
systempackages:
- bitlbee
processes:
bitlbee: bitlbee -n
--- a/fs/namespace.c.orig 2012-09-27 18:46:48.198667043 +0000
+++ b/fs/namespace.c 2012-09-27 18:47:13.214668751 +0000
@@ -2797,7 +2797,8 @@
struct mnt_namespace *mnt_ns = ns;
struct path root;
- if (fs->users != 1)
+ int fs_users = atomic_read(&(fs->users));
+ if (fs_users != 1)
return -EINVAL;
@jpetazzo
jpetazzo / dotcloud.yml
Created February 5, 2013 18:11
Unicorn on dotCloud
www:
# We use ruby-worker because we don't want all the scaffolding that comes with ruby (passenger etc.)
type: ruby-worker
# ... But we still want a www port to get HTTP traffic!
ports:
www: http
processes:
# OK, let's face it, I don't have the exact syntax of unicorn on the top of my head,
# so this is blatantly fake:
unicorn: unicorn --port $PORT_WWW --workers 10 --run-in-foreground
@jpetazzo
jpetazzo / README.md
Last active October 12, 2023 09:09
Manual custom geocoding using OSM database

Someone asked how to get the latlong from a specific road near a town on OpenStreetMap.

If you need to do it only once (e.g., you're about to go on a trip, and your GPS cannot find your destination city, but allows you to enter GPS coordinates), you can use Nominatim, OpenStreetMap's geocoding interface.

If you need to do it multiple times, in a programmatic manner, there are at least two ways to do that.

Note: I worked with OSM data a couple of years ago, but I don't have an OSM database on my local laptop right now, so some instructions will be a bit fuzzy. I do apologize in advance.

PostGIS queries on a local OSM DB

#!/bin/sh
[ -f ~/.ssh/id_rsa ] || ssh-keygen -q -f .ssh/id_rsa -N ''
docker run -a -i -t base sh -c "apt-get install -qq openssh-server ; mkdir -p /root/.ssh ; echo $(cat ~/.ssh/id_rsa.pub) > /root/.ssh/authorized_keys ; mkdir -p /var/run/sshd ; /usr/sbin/sshd -D"
@jpetazzo
jpetazzo / gist:5400376
Created April 16, 2013 22:56
Find out kworker-related issues
echo workqueue:workqueue_queue_work > /sys/kernel/debug/tracing/set_event
cat /sys/kernel/debug/tracing/trace_pipe > out.txt
(Leave it running a couple of seconds, then Ctrl+C; this is just to flush the buffer)
cat /sys/kernel/debug/tracing/trace_pipe > out.txt
(Leave it running a couple of seconds, then Ctrl+C; this is to recover the data)
cut -d- -f2 out.txt | awk '{print $1}' | sort | uniq -c | sort -n
@jpetazzo
jpetazzo / README.md
Last active August 21, 2019 17:55
Give network superpowers to docker

Unionize: network superpowers for your docker containers

Unionize lets you connect together docker containers in arbitrarily complex scenarios.

Note: I recommend to use https://github.com/jpetazzo/pipework instead.

  • pipework is a better name than unionize
  • it's hosted on a "real" github repo instead of a small gist :-)

Now if you want Unionize, it's still here. Just check those examples.

@jpetazzo
jpetazzo / postgresql.changefile
Last active December 16, 2015 20:39
PostgreSQL for dotcloud-builder
from ubuntu:precise
run LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -y -q postgresql-9.1 postgresql-contrib-9.1
copy postgresql.run /init
@jpetazzo
jpetazzo / gist:5616238
Last active December 17, 2015 13:19
Count how many FD are used by each process (to find FD leaks)
for PID in /proc/[1-9]* ; do echo $(ls $PID/fd | wc -l) $PID $(cat $PID/cmdline) ; done | sort -n