Skip to content

Instantly share code, notes, and snippets.

View ashchristopher's full-sized avatar

Ash Christopher ashchristopher

  • Shopify
  • Toronto, Ontario
View GitHub Profile
#!/usr/bin/env python
"""
Use pip to get a list of local packages to check against one or more package
indexes for updated versions.
"""
import pip
import sys, xmlrpclib
from cStringIO import StringIO
from distutils.version import StrictVersion, LooseVersion
@ashchristopher
ashchristopher / CreateFixturesWithRealData
Created January 17, 2011 18:38
Create fixtures using real data.
from django.core import serializers
from yourapp.models import YourModel
data = serializers.serialize("json", YourModel.objects.all(), indent = 4)
f = open('path/to/file', 'w')
f.write(data)
f.close()
@ashchristopher
ashchristopher / background.sh
Created January 17, 2011 01:05 — forked from zaius/background.sh
How to redirect a running process output to a file and log out
ctrl-z
bg
touch /tmp/stdout
touch /tmp/stderr
gdb -p $!
# In GDB
p dup2(open("/tmp/stdout", 1), 1)
p dup2(open("/tmp/stderr", 1), 2)
@ashchristopher
ashchristopher / Generic Foreign Keys WTF?!
Created January 14, 2011 21:15
Generic Foreign Keys WTF?!
In models.py
--------------------
from datetime import datetime
from django.db import models
from django.contrib.sites.models import Site
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
class Cart(models.Model):

Step 1

Get a VPS that offers 2 or more IP addresses.

Step 2

From the WHM cPanel, find the menu item Service Configuration, select Apache Configuration and then click on Reserved IPs Editor.

Step 3

/*
* 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;
$('.required_field').each(function(){
$("label[for='" + $(this).attr("id") + "']").attr('class', 'required');
});
# Hey coops..
#
# Imagine yourself on the other side of the table: two job openings, hundreds of resumes,
# _all of which_ look friggin' identical. Yeah, the HR departments at your MegaCorp XYZ are using
# automated tools to scan for keywords, and the coop department at your school is trying to beat
# you into submission to follow some "predefined template".. But, unless what you're aspiring to
# is to be an automaton at MegaCorp XYZ, relegated to writing test harnesses for code that will
# never see the light of day.. please do yourself a favor, and _be different_! Be bold, dammit.
#
# (Frankly, I'm falling asleep while reading your resumes.. Wake me up! Srsly.)
@ashchristopher
ashchristopher / HTTPS redirects
Created January 29, 2010 21:20
Dealing with Http/Https issues.
# if we are using port 443 and the url doesnt contain onlinebooking or media-server then redirect to http.
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} !(onlinebooking)
RewriteCond %{REQUEST_URI} !(media-server)
RewriteRule ^(.*)$ http://test.gapadventures.com$1 [R=301,L]
# if not using port 443 and url contains onlinebooking, redirect to https
# Redirect to HTTPS server.
@ashchristopher
ashchristopher / cache.delete
Created December 16, 2009 22:50
Overloading the python-memcahce delete() function in a django project since it isn't supported.
Initially wanted to do this:
from django.core.cache.backends.memcached import CacheClass
class DeletableCache(object):
"""
The memcache library doesnt seem to support delete. This is a mixin to fake it.