Skip to content

Instantly share code, notes, and snippets.

/*
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];
// 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];
@robballou
robballou / import_to_mongo.py
Created December 16, 2010 21:31
Import delicious bookmark XML to mongodb
#!/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
#!/usr/bin/env sh
# Input: Entire Document
# Output: Replace Document
java -jar ~/bin/yuicompressor-2.4.2.jar $TM_FILEPATH
#!/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;
#!/usr/bin/env ruby
#
# Textmate item to increment all numbers in a selection
#
# If you have:
#
# line1
# line1
# line1
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:
<?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;
// 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')
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
"""