Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

=begin
## Description
A tool for Octopress to generate IDs in header tags and index list aside. It helps you easily build a tutorial page with many chapters.
## Features
* Support all languages.
## Syntax
@robertjwhitney
robertjwhitney / uri.js
Created May 7, 2012 16:41 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@robertjwhitney
robertjwhitney / chat.rb
Created April 1, 2012 17:29 — forked from rkh/chat.rb
Simple Chat Application using the Sinatra Streaming API
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
@robertjwhitney
robertjwhitney / heroku_deploy.rake
Created December 13, 2011 15:44 — forked from michaeldwan/heroku_deploy.rake
Simple Rake task for customizing deployment to Heroku
# rake deploy:production master
# List of environments and their heroku git remotes
ENVIRONMENTS = {
:staging => 'myapp-staging',
:production => 'myapp-production'
}
namespace :deploy do
ENVIRONMENTS.keys.each do |env|
@robertjwhitney
robertjwhitney / gist:1207453
Created September 9, 2011 22:03 — forked from ekampf/gist:847741
A ruby snippet to sanitize Html (and specifically Microsoft Word's messy HTML) (based on https://gist.github.com/139987)
# This function cleans up messy HTML that was pasted by a user to a WYSIWYG editor.
# Specifically it also handles messy Word\Outlook generated HTML while keeping its original formattings.
require 'rubygems'
require 'sanitize'
def clean_up_document(html)
elements = %w[p b h1 h2 h3 h4 h5 h6 strong li ul ol i br div pre p]
attributes = {
'a' => ['href', 'title'],
@robertjwhitney
robertjwhitney / yui_compressor.rb
Created April 28, 2011 14:46 — forked from seth/yui_compressor.rb
A Nanoc filter for minifying CSS and Javascript using the YUI Compressor
YUI_JAR = File.dirname(__FILE__) + "/../tools/yuicompressor-2.4.2.jar"
class YuiCompressor < Nanoc3::Filter
identifier :yui_compress
type :text => :binary
def run(content, params={})
type = type_from_extension
cmd = "java -jar #{YUI_JAR} --type #{type} -o #{output_filename}"
IO.popen(cmd, 'w') { |f| f.write(content) }
raise "yuicompressor exited with #{$?} for '#{cmd}'" unless $? == 0
alias fuckit="git add . && git commit -m 'Throwaway commit' && git reset --hard HEAD^"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- saved from url=(0068)http://24ways.org/examples/compose-to-a-vertical-rhythm/example.html -->
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>Compose a Vertical Rhythm example</TITLE>
<LINK rel="alternate stylesheet" type="text/css" href="vertical_rhythm.css" title="sass">
<LINK rel="alternate stylesheet" type="text/css" href="original.css" title="original">
</HEAD><BODY>
<H1>Aboard Minerva off the Coast of New England</H1>
SunSpider Results
Safari (Version 4.0.4 (6531.21.10)):
http://www2.webkit.org/perf/sunspider-0.9/sunspider-results.html?%7B%223d-cube%22:%5B15,16,15,16,15%5D,%223d-morph%22:%5B21,20,21,21,20%5D,%223d-raytrace%22:%5B18,18,17,17,18%5D,%22access-binary-trees%22:%5B10,8,9,8,8%5D,%22access-fannkuch%22:%5B16,17,18,16,16%5D,%22access-nbody%22:%5B11,11,11,11,11%5D,%22access-nsieve%22:%5B10,9,9,9,9%5D,%22bitops-3bit-bits-in-byte%22:%5B3,3,3,3,3%5D,%22bitops-bits-in-byte%22:%5B7,8,7,8,7%5D,%22bitops-bitwise-and%22:%5B4,5,5,5,4%5D,%22bitops-nsieve-bits%22:%5B7,7,8,8,7%5D,%22controlflow-recursive%22:%5B4,4,4,3,4%5D,%22crypto-aes%22:%5B14,13,13,12,13%5D,%22crypto-md5%22:%5B7,8,7,8,7%5D,%22crypto-sha1%22:%5B6,6,5,6,4%5D,%22date-format-tofte%22:%5B34,34,36,35,35%5D,%22date-format-xparb%22:%5B41,39,39,39,40%5D,%22math-cordic%22:%5B10,10,11,11,11%5D,%22math-partial-sums%22:%5B18,18,18,18,18%5D,%22math-spectral-norm%22:%5B8,8,8,8,7%5D,%22regexp-dna%22:%5B29,28,28,28,28%5D,%22string-base64%22:%5B25,29,26,29,26%5D,%22string-fas
system "gem sources -a http://gems.github.com"
required_gems = %w{ pauldix-feedzirra prawn }
required_gems.each { |required_gem| system "sudo gem install #{required_gem} --no-ri --no-rdoc" }
require 'rubygems'
require 'feedzirra'
require 'prawn'
require 'net/ftp'
ftp_address = 'snuggietonight.com'