Skip to content

Instantly share code, notes, and snippets.

View ishikawa's full-sized avatar
🏠
Working from home

Takanori Ishikawa ishikawa

🏠
Working from home
View GitHub Profile
@ishikawa
ishikawa / gist:2580
Created July 26, 2008 02:49
domready.js
/**
* domready.js
*
* Cross browser mozilla's 'onDOMContentLoaded' implementation.
* Executes a function when the dom tree is loaded without waiting for images.
*
* Based on +Element.Events.domready+ from Mootools open source project,
* this tiny javascript library adds the emulated 'DOMContentLoaded' functionality.
*
* Features:
@ishikawa
ishikawa / gist:2582
Created July 26, 2008 02:53
Random ASCII Characters
require 'enumerator'
def random_string(length=10, s="")
length.enum_for(:times).inject(s) do |result, index|
s << rand(93) + 33
end
end
@ishikawa
ishikawa / gist:2584
Created July 26, 2008 02:55
Parse Query String From Script Element's Src Attribute
/**
* Helper object to parse the query string variables from
* <script> element's src attribute.
*
* For example, in test.html:
*
* <script src="test.js?name=value"></script>
*
* and in test.js, you can get query as name/value pairs:
*
#!/usr/bin/ruby
require 'webrick'
include WEBrick
def start_webrick(config = {})
config.update(:Port => 5001)
server = HTTPServer.new(config)
yield server if block_given?
@ishikawa
ishikawa / gist:2586
Created July 26, 2008 03:03
Subversion quickstart
creating the Subversion repository
% svnadmin create --fs-type fsfs path-to-svn-repos
% mkdir tmp
% cd tmp
% mkdir webframework
% cd webframework
% mkdir trunk branches tags
% cd ..
% svn import . file:///path-to-svn-repos --message 'Initial repository layout'
@ishikawa
ishikawa / array_product.rb
Created July 26, 2008 03:04
Array#Product For Ruby 1.8
class Array
# Array#product
# -------------
# Returns the cartesian product of the receiver and the arrays given as arguments.
#
# Usage:
# [1, 2, 3].product([4, 5]) # => [[1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5]]
# [1, 2].product([1, 2]) # => [[1, 1], [1, 2], [2, 1], [2, 2]]
# [1, 2].product([3, 4],[5, 6]) # => [[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6],
@ishikawa
ishikawa / gist:2588
Created July 26, 2008 03:06
Apple's Modifications To Python 2.5.1 (Locale.Py, ...)
diff -ur ./Python-2.5.1.orig/Lib/locale.py ./Python-2.5.1/Lib/locale.py
--- ./Python-2.5.1.orig/Lib/locale.py 2006-05-18 11:06:40.000000000 +0900
+++ ./Python-2.5.1/Lib/locale.py 2007-09-09 12:50:14.000000000 +0900
@@ -485,7 +485,7 @@
"""
_setlocale(category, _build_localename(getdefaultlocale()))
-if sys.platform in ('win32', 'darwin', 'mac'):
+if sys.platform in ('win32', 'mac'):
# On Win32, this will return the ANSI code page
@ishikawa
ishikawa / sha1.js
Created July 26, 2008 03:07
JavaScript Implementation Of The SHA-1
/*
* The JavaScript implementation of the Secure Hash Algorithm 1
*
* Copyright (c) 2008 Takanori Ishikawa <takanori.ishikawa@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
/*
* A Simple BDD (Behaviour Driven Development) library for JavaScript.
*
* Copyright (c) 2008 Takanori Ishikawa <takanori.ishikawa@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
@ishikawa
ishikawa / gist:2591
Created July 26, 2008 03:10
Iterates Over The Bytes Of String
import array
for byte in array.array('B', "ABCDEFG"):
print byte # prints 65, 66, 67, 68, ... and so on.