Skip to content

Instantly share code, notes, and snippets.

View eyeseast's full-sized avatar

Chris Amico eyeseast

View GitHub Profile
@schwanksta
schwanksta / apdate_to_datetime.py
Created May 5, 2010 00:10
Converts an AP Style date string to a Python datetime object.
def apdate_to_datetime(date):
"""
Takes an AP-formatted date string and returns a Python datetime
object. This will also work on any date formatted as either
'%b. %d, %Y' or '%B %d, %Y'
Examples:
>>> apdate_to_datetime("Sept. 4, 1986")
datetime.datetime(1986, 9, 4, 0, 0)
>>> apdate_to_datetime("Sep. 4, 1986")
@banterability
banterability / intcomma.js
Created August 31, 2010 21:07
Add commas to integers (2000000 -> 2,000,000) in javascript
var intcomma = function(value) {
// inspired by django.contrib.humanize.intcomma
var origValue = String(value);
var newValue = origValue.replace(/^(-?\d+)(\d{3})/, '$1,$2');
if (origValue == newValue){
return newValue;
} else {
return intcomma(newValue);
}
};
@jacobian
jacobian / virtualenv-example.rb
Created October 5, 2010 21:36
My first Chef definition: create a virtualenv. Be nice.
# An example of the below
virtualenv "/home/dvcsmirrors/hg" do
owner "root"
group "dvcsmirrors"
mode 0775
packages "Mercurial" => "1.6.3",
"hgsubversion" => "1.1.2"
end
"""
jQuery templates use constructs like:
{{if condition}} print something{{/if}}
This, of course, completely screws up Django templates,
because Django thinks {{ and }} mean something.
Wrap {% verbatim %} and {% endverbatim %} around those
blocks of jQuery templates and this will try its best
@enaeseth
enaeseth / yaml_ordered_dict.py
Created February 25, 2011 19:54
Load YAML mappings as ordered dictionaries
import yaml
import yaml.constructor
try:
# included in standard lib from Python 2.7
from collections import OrderedDict
except ImportError:
# try importing the backported drop-in replacement
# it's available on PyPI
from ordereddict import OrderedDict
(function() {
var Geocoder = function(address, cb) {
this.address = address;
this.geocoder = new google.maps.Geocoder();
this.geocode(cb);
};
Geocoder.prototype = {
geocode : function(cb) {
if (this.address === "") return false;
@jkeefe
jkeefe / dc.html
Created May 10, 2011 03:15
Customized DocumentCloud Viewer
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title id="maintitle">Document Viewer</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link href="css/document-cloud.css" media="all" rel="stylesheet" type="text/css">
<!--
Customized document viewer for use with DocumentCloud, at http://documentcloud.org.
@jeffkistler
jeffkistler / geojson.py
Created May 11, 2011 20:30
GeoJSON Django GeoQuerySet Serializer
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
import datetime
import decimal
from django.core.serializers.python import Serializer as PythonSerializer
from django.core.serializers.json import DjangoJSONEncoder
from django.utils.encoding import is_protected_type, smart_unicode
@fcingolani
fcingolani / wp-cron.sh
Created June 14, 2011 19:02
Bash Script to execute wp-cron.php on a Multisite Wordpress.
#!/bin/sh
db_host="host";
db_user="user";
db_pass="password";
db_name="database";
domains=`mysql --silent --skip-column-names --host $db_host --user $db_user -p$db_pass $db_name --execute "SELECT domain FROM wp_blogs WHERE archived = '0' AND spam = '0' AND deleted = '0';"`;
for domain in $domains; do
the_date=`date`;
@onyxfish
onyxfish / fabfile.py
Created August 12, 2011 19:09
Fabric configuration for advanced mapping w/ TileMill and invar
import os
import re
from fabric.api import *
import yaml
"""
Base configuration
"""
# Ubuntu