Skip to content

Instantly share code, notes, and snippets.

View rgrove's full-sized avatar
🥧

Ryan Grove rgrove

🥧
View GitHub Profile
@rgrove
rgrove / gist:282168
Created January 20, 2010 19:49 — forked from ahx/gist:281893
# remove content of script tags using Sanitize
require 'sanitize'
html = '<p>Do not<script>fail();</script> kill the <a href="/cats/42">cat</a>.</p>'
Sanitize.clean(html, Sanitize::Config::BASIC.merge(
:transformers => lambda { |env|
node = env[:node]
if node.name.downcase == 'script'
@rgrove
rgrove / storage-lite.js
Created February 19, 2010 18:00
A persistent local key/value data store for YUI3 similar to HTML5's localStorage. Works in IE5+, Firefox 2+, Safari 3.1+, Chrome 4+, and Opera 10.5+.
/**
* Implements a persistent local key/value data store similar to HTML5's
* localStorage. Should work in IE5+, Firefox 2+, Safari 3.1+, Chrome 4+, and
* Opera 10.5+.
*
* @module storage-lite
*/
YUI.add('storage-lite', function (Y) {
@rgrove
rgrove / capmon.rb
Created February 26, 2010 00:47
Ruby script to retrieve and display Comcast data usage. See http://wonko.com/post/ruby-script-to-display-comcast-data-usage
#!/usr/bin/env ruby
require 'rubygems'
require 'mechanize'
URL_LOGIN = 'https://login.comcast.net/login?continue=https://login.comcast.net/account'
URL_USERS = 'https://customer.comcast.com/Secure/Users.aspx'
abort "Usage: #{$0} <username> <password>" unless ARGV.length == 2
var count = 10,
http = require("http"),
sys = require("sys"),
twitter = http.createClient(80, "search.twitter.com"),
i, request;
for (i = 1; i <= count; i++) {
request = twitter.request("GET", "/search.json?q=crockfordfact+OR+crockfordfacts&rpp=100&page=" + i, {"host": "search.twitter.com"});
request.addListener('response', function (response) {
var responseData = [];
function buildQueryString(parameterMap) {
var params = [];
for (name in parameterMap) {
if (parameterMap.hasOwnProperty(name)) {
params.push(encodeURIComponent(name) + '=' + encodeURIComponent(parameterMap[name]));
}
}
return params.join('&');
@rgrove
rgrove / serve.ru
Created April 20, 2010 20:56
Simple "right here, right now" web server for testing static content
# Install dependencies:
#
# gem install thin
#
# Run this to serve the current directory at http://localhost:3000/:
#
# thin -R /path/to/serve.ru start
#
require 'rubygems'
@rgrove
rgrove / gist:383871
Created April 29, 2010 16:50
Lazy loading with Y.use()
YUI().use('foo', function (Y) {
// ... do stuff with foo ...
// When you need to load "bar", call Y.use() and use it inside the
// callback. The difference between YUI().use() and Y.use() is that
// the first creates a new YUI instance, whereas the second adds
// "bar" to the existing instance.
Y.use('bar', function () {
// ... do stuff with bar ...
});
@rgrove
rgrove / gist:392619
Created May 6, 2010 19:50
Using custom hash values with YUI 3.2.0 (dev) History
// Using custom hash values with YUI History. Requires the current dev version
// of History from YUI 3.2.0 in git:
// http://github.com/yui/yui3/blob/master/build/history/history.js
YUI().use('history', function (Y) {
// Listen for hash changes.
Y.on('hashchange', function (e) {
// The event facade (e) contains the following interesting properties:
// e.oldHash, e.oldUrl, e.newHash, e.newUrl
@rgrove
rgrove / gist:400636
Created May 13, 2010 23:44
My custom git-aware shell prompt
# Pretty git-aware shell prompt.
case $TERM in
xterm*)
TITLEBAR='\[\033]0;\u@\h:\w\007\]'
;;
*)
TITLEBAR=""
;;
esac
@rgrove
rgrove / gist:441343
Created June 16, 2010 22:10
A (possibly terrible) way to aggregate all ATTR definitions in a Y.Base hierarchy from the class level, pre-instantiation
YUI.use('base-base', function (Y) {
function A() {}
Y.extend(A, Y.Base, {}, {
ATTRS: {
foo: {value: 'foo'}
}
});