Skip to content

Instantly share code, notes, and snippets.

@kennethreitz
kennethreitz / .aliases
Created April 25, 2010 20:38
My environment configuration
alias ports='sudo lsof -iTCP -sTCP:LISTEN -P'
alias dnsflush='dscacheutil -flushcache'
alias git-add='git add -A'
alias dmesg="sudo dmesg"
alias l='ls -lrtha'
alias dir='ls -lh'
alias svnscrub='find . -name .svn -exec rm -rf {} \;'
alias vpnfix='sudo route -nv add -net 10 -interface utun0 && sudo route change default 10.0.1.1'
alias gitx='/Applications/GitX.app/Contents/MacOS/GitX &'
@kkaefer
kkaefer / gist:646017
Created October 25, 2010 23:33
node.js proxy to enforce HTTPS and remove cookies
var http = require('http');
var secure = new RegExp('(' + [
'facebook.com',
'twitter.com',
'google.com'
].join('|').replace('.', '\\.') + ')$');
var noSecure = new RegExp('^(' + [
'http://(www\.)?google\.com/(image|imghp)',
@wimleers
wimleers / dps-cdn-rsync.sh
Created October 31, 2010 23:58
Script that syncs a directory recursively to a Push CDN using rsync.
#!/bin/sh
LOGFILE=/data/logs/dps-cdn-rsync/$(date "+%Y-%m").log
# Append a header first, so we know when this script was run.
date "+%n%n=====%nSyncing DriverPacks to CDN at %Y-%m-%d %H:%M:%S" >> $LOGFILE
# Now perform the actual syncing, still appending to the logfile.
rsync -avv --progress --delete --exclude lost+found --exclude .ssh --exclude .bash_history /data/www/downloadsorigin.driverpacks.net/ dpsdl.drupalcdn@storage01.netdna.com:/home/dpsdl.drupalcdn/public_html/ >> $LOGFILE
@wimleers
wimleers / crontab
Created November 1, 2010 00:00
DriverPacks.net server crontab file
#
# Normal cronjobs.
# m h dom mon dow command
#
# Regenerate torrents.tar.gz every hour.
*/60 * * * * tar -cvzf /data/www/svn_driverpacks.net/files/torrents.tar.gz /data/www/svn_driverpacks.net/files/torrents/*.torrent
# Run DriverPacks CDN and seedbox rsync scripts (for downloads)
*/20 * * * * /home/wim/cronscripts/dps-cdn-rsync.sh
@wimleers
wimleers / gist:702387
Created November 16, 2010 19:55
How to convert from a custom date format into a UTC string using Qt.
QDateTime timeConvertor;
QString customDateString = "14-Nov-2010 05:27:03 +0100";
QString dateTime = customDateString.left(20);
int timezoneOffset = customDateString.right(5).left(3).toInt();
timeConvertor = QDateTime::fromString(dateTime, "dd-MMM-yyyy HH:mm:ss");
// Mark this QDateTime as one with a certain offset from UTC, and set that
// offset.
timeConvertor.setTimeSpec(Qt::OffsetFromUTC);
@wimleers
wimleers / dps-seedbox1-rsync.sh
Created November 29, 2010 12:01
Script that syncs a directory tree recursively to another server, to a single target ("flat") directory, using rsync.
#!/bin/sh
LOGFILE=/data/logs/dps-seedbox1-rsync/$(date "+%Y-%m").log
EXCLUDES_COMMON="--exclude lost+found --exclude .ssh --exclude .bash_history"
EXCLUDES_MORE="--exclude other --exclude BASE --exclude applications"
# Append a header first, so we know when this script was run.
date "+%n%n=====%nSyncing DriverPacks to seedbox1 at %Y-%m-%d %H:%M:%S" > $LOGFILE
# Sync the DriverPacks themselves to the seedbox' 'data' folder. However, we
@wimleers
wimleers / dps-s3-rsync.sh
Created January 20, 2011 10:49
Script that syncs a directory recursively to Amazon S3 using s3sync.
#!/bin/bash
export AWS_ACCESS_KEY_ID=yourID
export AWS_SECRET_ACCESS_KEY=yourSecret
export AWS_TARGET_BUCKET=DriverPacks_back-up
export AWS_TARGET_DIR=/
export SOURCE_DIR=/data/www/downlodsorigin.driverpacks.net/
export S3SYNC_DIR=/home/wim/scripts/s3sync
export SSL_CERT_DIR=/etc/ssl/certs
<?php
$host="https://bodega.fogbugz.com/api.asp";
$user="rick@madefresh.ca";
$password = "********";
$query = 'project:"Bodega Application" milestone:"1.4.0" status:"Active"';
$cols = "ixBug";
$tokenCommand = "curl \"$host?cmd=logon&email=$user&password=$password\" | perl -ne 'print if s/.*\\[CDATA\[(.*)\\]\\].*/\\1/'";
@wimleers
wimleers / mysql-slow-log-analytics.sh
Created April 26, 2011 22:28
Script to automatically analyze slow queries of last hour and last 24 hours, using mk-query-digest.
#!/bin/sh
INPUT=/var/log/mysql/mysql-slow.log
OUTPUT_1H=/data/www/wimleers.com/status/mysql-slow-1h.txt
OUTPUT_24H=/data/www/wimleers.com/status/mysql-slow-24h.txt
# Perform the analytics, overwriting the previous results.
../scripts/mk-query-digest --since 1h $INPUT > $OUTPUT_1H
../scripts/mk-query-digest --since 24h $INPUT > $OUTPUT_24H
@wimleers
wimleers / weird.cpp
Created May 23, 2011 18:29
Note that the array index that is used goes beyond the array's capacity. And thus it modifies the next variable in memory…
#include <stdio.h>
#define uint unsigned int
#define TTW_NUM_GRANULARITIES 5
class Weird {
public:
Weird() {
this->lastUpdate = 0;
for (int g = 0; g < TTW_NUM_GRANULARITIES; g++)