Skip to content

Instantly share code, notes, and snippets.

View bartek's full-sized avatar
🐗

Bartek Ciszkowski bartek

🐗
View GitHub Profile
# section1.1.7 from SICP written in python .. was just making sure I understood how it all worked.
def square(x):
return x * x
def sqrt_iter(guess, x):
if good_enough(guess, x):
return guess
else:
return sqrt_iter(improve(guess, x), x)
server {
2 listen 98.129.237.54:80;
3 server_name www.mysite.com;
4 rewrite ^/(.*) http://mysite.com/$1 permanent;
5 }
6
7 server {
8 listen 98.129.237.54:80;
9 server_name mysite.com;
10
# Place this in its own file and add it to your `AUTHENTICATION_BACKENDS` setting in settings.py
from django.conf import settings
from django.contrib.auth.models import User
class EmailModelBackend(object):
def authenticate(self, username=None, password=None):
kwargs = {'email': username}
try:
# This configuration assumes you are running some kind of PHP FastCGI daemon to send for processing.
# I've commented parts of the file for clarity if someone does not understand what's going on.
# Here we simply rewrite the `www` out of the domain name because it's useless in most cases.
# Totally optional.
server {
listen 80;
server_name www.example.com;
rewrite ^/(.*) http://example.com/$1 permanent;
}
#!/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.
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
@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.
@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 / 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 / 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",