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
require 'rubygems' | |
require 'rack' | |
class Object | |
def webapp | |
class << self | |
define_method :call do |env| | |
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?) | |
[200, {}, send(func, *attrs)] | |
end |
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
module TryItOut | |
class << self | |
def ancestors(o) | |
a = [] | |
a << ((o.class == Class) ? o : o.class) | |
loop { | |
break if a[-1].nil? | |
a << a[-1].superclass | |
} | |
a |
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
# Output | |
# p1_a.call(1) => proc1 - a - 1 | |
# p1_b.call(2) => proc1 - b - 2 | |
# p2_o.call(3) => proc2 - o - 3 | |
# p2_p.call(4) => proc2 - p - 4 | |
# TestClass.m_block(&p1_a) => method TestClass.m_block yield(100) => proc1 - a - 100 | |
# TestClass.m_block(&p1_b) => method TestClass.m_block yield(101) => proc1 - b - 101 | |
# TestClass.m_block(&p2_o) => method TestClass.m_block yield(102) => proc2 - o - 102 | |
# TestClass.m_block(&p2_p) => method TestClass.m_block yield(103) => proc2 - p - 103 |
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
class ApplicationController < ActionController::Base | |
... | |
before_filter :page_params, :only => :index | |
def page_key | |
(self.class.to_s + "_page").to_sym | |
end | |
# Use a before_filter on index action to remember the current page |
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
= select_tag('tweet_source', options_for_select([['',0],['My Tweets',1],['Retweets',2],['Favorites',3],['Mentions',4]],2), {}) | |
<select name="tweet_source" id="tweet_source"><option value="0"></option> | |
<option value="1">My Tweets</option> | |
<option selected="selected" value="2">Retweets</option> | |
<option value="3">Favorites</option> | |
<option value="4">Mentions</option></select> | |
Want the onchange event to GET on tweets controller index action with tweet_source in params. |
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
➜ crockford_js_the_good_parts git:(master) ✗ wget -d http://www.conwaylife.com/pattern.asp?p=bargespaceship_106.lif | |
wget -d http://www.conwaylife.com/pattern.asp\?p\=bargespaceship_106.lif | |
DEBUG output created by Wget 1.12 on linux-gnu. | |
--2011-02-12 12:49:20-- http://www.conwaylife.com/pattern.asp?p=bargespaceship_106.lif | |
Resolving www.conwaylife.com... 65.182.101.250 | |
Caching www.conwaylife.com => 65.182.101.250 | |
Connecting to www.conwaylife.com|65.182.101.250|:80... connected. | |
Created socket 3. | |
Releasing 0x08aba240 (new refcount 1). |
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
// Working on my JS idioms | |
// fragment, not tried yet. | |
neighborhood = new function() { | |
// prototype object saved in closure | |
var proto = { | |
add_cell: function(location) { | |
var key = location.key(); | |
if (this.cells_and_neighbors.hasOwnProperty(key)) { | |
this.cells_and_neighbors[key].revive(); | |
} else { |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title class="page_title">Page Title Here</title> | |
<link rel="stylesheet" type="text/css" href="base.css" /> | |
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> | |
</head> | |
<body> | |
<h1 class = "page_title">Page Title Here</h1> | |
<h3>Morph an objects behavior by switching function definitions.</h3> |
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
// Place your application-specific JavaScript functions and classes here | |
// This file is automatically included by javascript_include_tag :defaults | |
// | |
if(!window.jq && window.jQuery){ | |
var jq = jQuery; | |
}; | |
if(!window.App){ | |
window.App = {}; |
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
require 'prawn' | |
Prawn::Document.generate "my.pdf" do | |
font_size 40 | |
font "Times-Roman" |
OlderNewer