This file contains 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
# 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' |
This file contains 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
/** | |
* 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) { |
This file contains 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 | |
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 |
This file contains 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
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 = []; |
This file contains 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
function buildQueryString(parameterMap) { | |
var params = []; | |
for (name in parameterMap) { | |
if (parameterMap.hasOwnProperty(name)) { | |
params.push(encodeURIComponent(name) + '=' + encodeURIComponent(parameterMap[name])); | |
} | |
} | |
return params.join('&'); |
This file contains 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
# 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' |
This file contains 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
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 ... | |
}); |
This file contains 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
// 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 |
This file contains 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
# Pretty git-aware shell prompt. | |
case $TERM in | |
xterm*) | |
TITLEBAR='\[\033]0;\u@\h:\w\007\]' | |
;; | |
*) | |
TITLEBAR="" | |
;; | |
esac |
This file contains 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
YUI.use('base-base', function (Y) { | |
function A() {} | |
Y.extend(A, Y.Base, {}, { | |
ATTRS: { | |
foo: {value: 'foo'} | |
} | |
}); |