Skip to content

Instantly share code, notes, and snippets.

@ianoxley
ianoxley / dateutils.js
Created March 7, 2012 13:41
JavaScript function to parse an ASP.NET JSON-serialised DateTime and extract the UNIX timestamp
/**
* Returns the UNIX timestamp from the ASP.NET JSON-serialised DateTime
*
* @param d - a string in the format /Date(1331127585489)/
* @return UNIX timestamp extracted from d, or zero
* @see http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx
* for possible changes to the way DateTime objects are serialised to JSON
*
* Example usage:
* var jsonDateTime = '/Date(1331127585489)/';
@ianoxley
ianoxley / install_pathogen.sh
Created December 19, 2011 10:35
Install pathogen.vim on Windows
# From https://github.com/tpope/vim-pathogen with .vim replaced with vimfiles
mkdir -p ~/vimfiles/autoload ~/vimfiles/bundle; \
curl -so ~/vimfiles/autoload/pathogen.vim \
https://raw.github.com/tpope/vim-pathogen/HEAD/autoload/pathogen.vim
# Install some plugins
cd ~/vimfiles/bundle
git clone git://github.com/scrooloose/nerdtree.git
git clone git://github.com/msanders/snipmate.vim.git
@ianoxley
ianoxley / proxy.py
Created December 7, 2011 16:24
Access URL's from behind a proxy in Python
""" proxy.py
Wires up a proxy server so you can access URL's via Python.
Based on this answer from Stack Overflow: http://stackoverflow.com/a/35443
TODO:
1. use proper command line args via optparse / OptionParser
"""
import urllib2
@ianoxley
ianoxley / example.html.haml
Created August 15, 2011 20:06
Example code for my Introduction to Haml article on RubySource.com
!!! 5
%html
%head
%title Example HAML
/[if IE]
%link{ :rel => "stylesheet", :href => "/css/ie.css" }
%body
#container
%header
%h1 Our Awesome HTML5 Template
@ianoxley
ianoxley / multiemail.js
Created August 1, 2011 14:35
jQuery Validation Plugin: Multiple Email Address Validation
// Edited / adapted from http://forum.jquery.com/topic/jquery-validate-comma-seperated-multiple-emails-validation#14737000002179275
jQuery.validator.addMethod("multiemail", function (value, element) {
if (this.optional(element)) {
return true;
}
var emails = value.split(','),
valid = true;
for (var i = 0, limit = emails.length; i < limit; i++) {
@ianoxley
ianoxley / base58.py
Created March 11, 2011 14:00
base58 encoding in Python
""" base58 encoding / decoding functions """
import unittest
alphabet = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'
base_count = len(alphabet)
def encode(num):
""" Returns num in a base58-encoded string """
encode = ''
@ianoxley
ianoxley / varchar2nvarchar.sql
Created February 7, 2011 16:48
Changes all varchar columns to nvarchar in SQL Server
SELECT 'ALTER TABLE [' + TABLE_SCHEMA + '].[' + TABLE_NAME + '] ALTER COLUMN [' + COLUMN_NAME + '] nvarchar(' + CAST(CHARACTER_MAXIMUM_LENGTH As NVARCHAR) + ');'
FROM INFORMATION_SCHEMA.COLUMNS
WHERE DATA_TYPE = 'VARCHAR';
@ianoxley
ianoxley / formutils.module
Created December 6, 2010 13:59
Removing the * to denote required fields and marking all optional fields as "optional" in Drupal
function formutils_form_alter(&$form, &$form_state, $form_id) {
if (is_array($form['submitted'])) {
foreach ($form['submitted'] as $field) {
if (!$field['#required']) {
$currentTitle = $field['#title'];
$field['#title'] = $currentTitle . ' (optional)';
}
}
}
}
# Copy a file's contents to the clipboard
cat filename | xclip -sel clip
# Generate a random password
date | md5sum
@ianoxley
ianoxley / framebust.js
Created July 28, 2010 11:30
A JavaScript snippet for framebusting
if (self != top) {
document.documentElement.style.visibility = 'hidden';
top.location = self.location;
}