This file contains hidden or 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
# Rake tasks for building a jekyll blog and deploying to S3. | |
# | |
# These tasks aren't intended to replace the `jekyll` executable, | |
# but provide convenient Rake-isms to generate the destination dir | |
# when necessary. | |
# | |
# To write to s3, it assumes there is a bucket field in the | |
# jekyll config: | |
# aws: | |
# bucket: 'my-s3-bucket' |
This file contains hidden or 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
/** | |
* | |
* HTMLElement.replicate() | |
* | |
* Here's an extension to the DOM's [HTMLElement interface][1] that completely | |
* replicates an element. Unlike `Node.cloneNode`, this method also copies over | |
* relevant styles. This allows you to clone nodes completely detached from the | |
* source document, but with enough information to render their independent | |
* representation. | |
* |
This file contains hidden or 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
fibRecurse := method(n, | |
if(n == 0, 0, | |
if(n == 1, 1, | |
fibRecurse(n-1) + fibRecurse(n - 2) | |
) | |
) | |
) | |
fibLoop := method(n, | |
i := 0 ; a := 0 ; b := 1 |
This file contains hidden or 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
require 'sinatra' | |
get '/' do | |
erb :index | |
end | |
get '/events' do | |
f = File.new("pipe") | |
content_type 'text/event-stream' |
This file contains hidden or 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
def fibonacci(n) | |
Enumerator.new do |yielder| | |
i = j = 1 | |
loop do | |
yielder << i | |
i, j = j, i+j | |
end | |
end.take(n) | |
end |
This file contains hidden or 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
def sieve(n) | |
integers = 2..n | |
not_primes = (2..Math.sqrt(n).ceil).reduce([]) do |marked, p| | |
(p**2).step(n, p) {|j| marked << j } | |
marked | |
end | |
integers.to_a - not_primes | |
end |
This file contains hidden or 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
t timeline -l | ruby -e 'puts $stdin.readlines.shuffle.pop' | awk '{ print $1}' | xargs -J % t reply % 'NOW you'"'"'re talking my language! (cf. https://twitter.com/markwunsch/status/382969649509707776)' |
This file contains hidden or 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
curl -s 'http://realbusinessmen.tumblr.com/api/read?type=photo&num=50' | ruby -r'rexml/document' -e 'puts REXML::Document.new(STDIN).elements["tumblr/posts"].to_a.shuffle.pop.map(&:text)' |
This file contains hidden or 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
/** | |
* | |
* Here's a thing that will look through all the text nodes of a document, and | |
* upon encountering an emoji codepoint, will replace it with an image. | |
* For now, those images are pulled from GitHub, which isn't very nice, so I | |
* need to find a more suitable host. | |
* | |
* Much of this code was gleaned from staring at the minified GitHub JS. | |
* | |
* Copyright (c) 2013 Mark Wunsch. Licensed under the MIT License. |
This file contains hidden or 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 getLegitTextNodes() { | |
if (!document.createTreeWalker) return []; | |
var blacklist = ['SCRIPT', 'OPTION', 'TEXTAREA'], | |
textNodes = [], | |
walker = document.createTreeWalker( | |
document.body, | |
NodeFilter.SHOW_TEXT, | |
function excludeBlacklistedNodes(node) { | |
if (blacklist.indexOf(node.parentElement.nodeName.toUpperCase()) >= 0) return NodeFilter.FILTER_REJECT; |