Skip to content

Instantly share code, notes, and snippets.

View bartek's full-sized avatar
🐗

Bartek Ciszkowski bartek

🐗
View GitHub Profile
@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 / 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 / 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
# 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 / international_calling_codes.json
Created March 24, 2011 16:24
List of countries by ISO name and their calling codes. No one should have to go through the torture of finding these, so hopefully someone finds this useful.
{"Canada": "+1", "East Timor": "+670", "Réunion": "+262", "Montenegro": "+382", "Mali": "+223", "Cambodia": "+855", "Switzerland": "+41", "Ethiopia": "+251", "Saudi Arabia": "+966", "Aruba": "+297", "Swaziland": "+268", "Argentina": "+54", "Cameroon": "+237", "Wallis and Futuna Islands": "+681", "Bahrain": "+973", "Korea, Democratic People's Republic of": "+850", "Mayotte": "+262", "Haiti ": "+509", "Bosnia and Herzegovina": "+387", "Micronesia, Federated States of": "+691", "Jordan": "+962", "United States": "+1", "United States Minor Outlying Islands": "+1", "Trinidad and Tobago": "+1-868", "Greece": "+30", "Burkina Faso": "+226", "Senegal ": "+221", "Cuba (Guantanamo Bay)": "+5399", "Guantanamo Bay": "+5399", "Togo": "+228", "Spain": "+34", "Liberia": "+231", "French Antilles": "+596", "Nepal": "+977", "Tanzania, United Republic of": "+255", "Martinique": "+596", "Hungary": "+36", "Christmas Island": "+61-8", "French Guiana": "+594", "Niue": "+683", "Monaco": "+377", "Chatham Island (New Zealand)": "+64",
@bartek
bartek / node.js-snowleopard-build
Created March 15, 2011 01:54
Building node.js on Snow Leopard sometimes sucks!
"""
If you're having trouble building node.js on OSX (Snow Leopard seems to be problematic here) with an error like this:
""""
$ brew install node
==> Downloading http://nodejs.org/dist/node-v0.4.2.tar.gz
File already downloaded and cached to /Users/bartekc/Library/Caches/Homebrew
==> ./configure --prefix=/usr/local/Cellar/node/0.4.2
==> make install
........
@bartek
bartek / googlemap_location.js
Created December 13, 2010 14:48
A simple Google Map Widget with a lat/lng marker. JS file included and required.
/*
* A simple Google maps Javascript widget which will display a map and
* a marker with the ability to move the marker, then setting the
* lat/lng of the marker into the specified (or default) fields.
*/
var google_map_location = new function() {
var jQuery;
var init_options;
var geocoder;
@bartek
bartek / readability.py
Created December 1, 2010 02:58
Pasting to bookmark. Original from: http://nirmalpatel.com/fcgi/hn.py
"""
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
def get_primes(n):
numbers = set(range(n, 1, -1))
primes = []
while numbers:
p = numbers.pop()
primes.append(p)
numbers.difference_update(set(range(p*2, n+1, p)))
return primes
#!/usr/bin/env python
"""
PDF To Image Converter Class.
The base of this script was derived from the pdfpeek package by David Brenneman:
http://pypi.python.org/pypi/collective.pdfpeek
Simply wanted something in a single file. Could use a bit of adjustments in
how files are saved, but this was mostly playing around to see how previewing PDF files works.