Skip to content

Instantly share code, notes, and snippets.

View judy2k's full-sized avatar

Mark Smith judy2k

View GitHub Profile
@judy2k
judy2k / preloadImage.js
Last active August 29, 2015 13:58
Preload an image before calling a callback function
var preloadImage = function(url, callback) {
var loaded = false,
loadHandler = function() {
if (!loaded) {
callback(url);
}
loaded = true;
},
img = $('<img>')
.one('load', loadHandler)
@judy2k
judy2k / gitignore
Last active February 1, 2022 11:14
A script to manage a .gitignore file
#!/bin/bash
# To add two items to the current .gitignore file:
# gitignore '*.swp' bin
#
# To sort and de-dupe the current .gitignore file:
# gitignore
# Append each argument to its own line:
for item in "$@"; do
echo "$item" >> .gitignore;
@judy2k
judy2k / unicode.md
Last active December 31, 2015 02:09
These are some notes for a potential short talk on Python & Unicode.

Python & Unicode

text = open('a_unicode_file.txt', 'r').read()
print text
print 'type:', type(text)       # str is a container for binary data
print 'bytes:', len(text)       # The number of bytes, not characters!
print ' '.join(repr(b) for b in text)
print 'first byte:', text[:1] # Prints an invalid character!
@judy2k
judy2k / double.py
Created March 26, 2013 15:55
The hackiest script in the world - anything that looks like an int in the input, replace with double its value and output to stdout. Use as follows (on OSX): 1. Copy the json data you want to double from your IDE 2. pbcopy | ./double.py | pbpaste 3. Paste the new json with all the numbers doubled back into your IDE
#!/usr/bin/env python
import re
import sys
def rep(sval):
return str(int(sval.group()) * 2)
if __name__ == '__main__':

Python Developer

Twig World is looking to recruit a highly skilled and motivated Python developer to build and maintain our portfolio of award-winning educational online products.

The successful candidate will be joining a small, collaborative team in our Glasgow office which is responsible for the end-to-end development of Twig’s online platform. You will be expected not only to write code, but also to provide ideas and expertise to shape new and existing products.

About the Team

The Tech Team is a tight-knit, cross discipline team of people who are passionate about building great online products. Everyone gets involved in steering what we do, providing ideas for future development and opinions on which technologies we use. The ideal candidate will bring energy, expertise, creativity and innovation to the team, as well as a real pride in their work. A good sense of humour is essential.

Python Developer

Twig World is looking to recruit a highly skilled and motivated Python developer to build and maintain our portfolio of award-winning educational online products.

The successful candidate will be joining a small, collaborative team in our Glasgow office which is responsible for the end-to-end development of Twig’s online platform. You will be expected not only to write code, but also to provide ideas and expertise to shape new and existing products.

About the Team

The Tech Team is a tight-knit, cross discipline team of people who are passionate about building great online products. Everyone gets involved in steering what we do, providing ideas for future development and opinions on which technologies we use. The ideal candidate will bring energy, expertise, creativity and innovation to the team, as well as a real pride in their work. A good sense of humour is essential.

@judy2k
judy2k / coldesc.sql
Created September 18, 2012 15:39
Column Description
DROP FUNCTION IF EXISTS coldesc();
CREATE FUNCTION coldesc() RETURNS TABLE(COL text,VAL text) AS $$
DECLARE
COL text;
Q text;
BEGIN
Q := 'SELECT ''boundary'' as COL, boundary AS VAL FROM planet_osm_line GROUP BY boundary';
FOREACH COL IN ARRAY ARRAY['barrier', 'bicycle', 'bridge', 'boundary', 'building', 'construction']
LOOP
RAISE NOTICE '%', Q;
@judy2k
judy2k / 01_before.py
Created July 7, 2012 13:05
modeltest refactoring
class ModelTest(TestCase):
def test_lookup(self):
# No articles are in the system yet.
self.assertQuerysetEqual(Article.objects.all(), [])
# Create an Article.
a = Article(
id=None,
headline='Area man programs in Python',
# Theirs:
print map(lambda x: x * 2, range(1,11))
# Mine:
print [x*2 for x in range(1,11)]
@judy2k
judy2k / bookingdate.py
Created May 9, 2012 10:07
Using BookingDate
bdate = BookingDate(
booking_name=request.user,
date_available=datetime.datetime.now())
bdate.save()