This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Got data from the web service | |
*/ | |
- (void)requestFinished:(ASIHTTPRequest *)request { | |
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; | |
// Use when fetching text data | |
NSString *responseString = [request responseString]; | |
// parse the response | |
SBJsonParser *parser = [SBJsonParser new]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// send an asynch request to http://localhost/some.json (a JSON file) | |
NSURL *url = [NSURL URLWithString:@"http://localhost/some.json"]; | |
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; | |
[request setDelegate:self]; | |
[request startAsynchronous]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Python script to copy a delicious XML file into a mongodb. | |
Essentially saves all attributes from the XML as-is, but I do make the following changes: | |
- Added a "tags" attribute to the saved document that separates the tags into a list | |
- Converted the "time" attribute to a datetime |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# Input: Entire Document | |
# Output: Replace Document | |
java -jar ~/bin/yuicompressor-2.4.2.jar $TM_FILEPATH |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Textmate command for inserting a random string | |
# | |
# Input: none | |
# Output: Insert as text | |
# based on: http://stackoverflow.com/questions/88311/how-best-to-generate-a-random-string-in-ruby | |
o = [('a'..'z'),('A'..'Z')].map{|i| i.to_a}.flatten; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Textmate item to increment all numbers in a selection | |
# | |
# If you have: | |
# | |
# line1 | |
# line1 | |
# line1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datettime | |
import rotatelib | |
import MySQLdb | |
db = MySQLdb.connect('localhost', 'user', 'password', 'my_database') | |
# find any backup tables (tables with a date in the name) that are older than 5 days | |
items = rotatelib.list_backup_tables(db=db, before=datetime.timedelta(5)) | |
for item in items: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// convert the error reporting value to an array of constant values | |
// from: http://php.net/manual/en/function.error-reporting.php | |
$bit = ini_get('error_reporting'); | |
$res = array(); | |
while ($bit > 0) { | |
for($i = 0, $n = 0; $i <= $bit; $i = 1 * pow(2, $n), $n++) { | |
$end = $i; | |
} | |
$res[] = $end; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery plugin | |
// make "blank" options non-selectable | |
(function($){ | |
$(document).ready(function(){ | |
jQuery('select').change(function(){ | |
var select = jQuery(this) | |
var blankValues = ['', '-', '#', ' '] | |
if(jQuery.inArray(select.val(), blankValues) != -1){ | |
jQuery('option:selected', select).attr('selected', '') | |
jQuery('option:first', select).attr('selected', 'selected') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
from django.utils.http import urlquote | |
from django import http | |
class EnforceHostnameMiddleware(object): | |
""" | |
Enforce the hostname per the ENFORCE_HOSTNAME setting in the project's settings | |
The ENFORCE_HOSTNAME can either be a single host or a list of acceptable hosts | |
""" |