Skip to content

Instantly share code, notes, and snippets.

View bartek's full-sized avatar
🐗

Bartek Ciszkowski bartek

🐗
View GitHub Profile
# Pre-commit hook passing files through jslint
#
# This ensures that all js, html and json files are valid and conform
# to expectations.
ROOT_DIR=$(git rev-parse --show-toplevel)
JSLINT="${ROOT_DIR}/node_modules/.bin/jslint --indent 4 --white true"
for file in $(git diff-index --name-only --diff-filter=ACM --cached HEAD -- | grep -P '\.((js)|(html)|(json))$'); do
if node $JSLINT $file 2>&1 | grep 'No errors found' ; then
@bartek
bartek / bulk_delete.py
Created December 30, 2011 17:53
efficient bulk_delete for Django
"""
This is a quick hack that adds a bulk_delete function, which given a queryset will run the Django
implemented DeleteQuery. The purpose of this is when you have thousands (or in my case, millions)
of records to delete, I did not want to get the pk_list of every record and store that into memory,
like Django does naturally, and instead just execute a single query with its WHERE clauses.
There are probably some issues with this, in regards to ForeignKeys and cascading. More info can
be found in this ticket, which looks to implement a bulk_delete functionality into the core:
https://code.djangoproject.com/ticket/9519
@bartek
bartek / gist:2425130
Created April 20, 2012 01:08
Cloudmade SDK setup with Xcode 4.x

CloudMade SDK Setup with Xcode 4.x

This is actually a lot simpler in Xcode 4, but you just need to know where to get around.

First, get the CloudMade libraries as per the original instructions and check them out into your project folder.

svn co http://developers.cloudmade.com/svn/iphone-api/iphone-api/trunk/inc
svn co http://developers.cloudmade.com/svn/iphone-api/iphone-api/trunk/libs
@bartek
bartek / statsd.py
Created September 17, 2012 19:49
statsd client
import sys
import random
import logging
from socket import socket, AF_INET, SOCK_DGRAM
from django.conf import settings
logger = logging.getLogger(__name__)
class Statsd(object):
@bartek
bartek / postgres_replication_status.py
Created November 26, 2012 20:18
postgres replication status
# I hate urllib and subprocess, so use tools by Kenneth Reitz.
import envoy
import requests
from socket import socket, AF_INET, SOCK_DGRAM
# Simple script to check the delay in replication between master and slave(s).
# The server runnin this will need to be allowed access via pg_hba to all the
# hosts it connects to.
hosts = (
@bartek
bartek / change_db_ownership.sh
Created December 20, 2012 15:32
Script by Alex Soto.
#!/bin/bash
usage()
{
cat << EOF
usage: $0 options
This script set ownership for all table, sequence and views for a given database
Credit: Based on http://stackoverflow.com/a/2686185/305019 by Alex Soto
command! Marked silent !open -a "Marked.app" "%:p"
@bartek
bartek / gist:4439084
Created January 2, 2013 22:56
open currently opened file in vim with Marked.app
command! Marked silent !open -a "Marked.app" "%:p"
@bartek
bartek / postgres_slave_promote.md
Created January 10, 2013 14:29
What to do when promoting a postgresql slave to master

This example is based on having a cascading setup, where you have a single master, a single "primary" slave, and cascading slaves which are being replicated from the primary slave. For an example of this setup, check out http://bartek.im/blog/2012/12/04/postgresql-92-streaming-primer.html

On the existing master, if accessible, stop postgres.

$ sudo service postgresql stop

And better to be safe than sorry. We can't have two masters running. (I only use this in an automated script. If you're doing this manually, you'd know if it was shutoff)

$ kill -9 `sudo cat /var/lib/postgresql/9.2/main/postmaster.pid | head -n 1` &> /dev/null
@bartek
bartek / emoticons.json
Created January 17, 2013 03:32
collection of emoticons so far primarily collected from reddit.
{
"misc": [
"(✿つ⌒∇⌒)つ~♡"
],
"reddit": [
"⊙▃⊙",
"๏̯͡๏﴿",
"ಠ~ಠ",
"ಠoಠ",
"ರ_ರ",