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
1.9.3-p545 :001 > (1..2) | |
=> 1..2 | |
1.9.3-p545 :002 > (1..2).class | |
=> Range | |
1.9.3-p545 :003 > (1..2).include?(1) | |
=> true | |
1.9.3-p545 :004 > (1..2).include?(3) | |
=> false | |
1.9.3-p545 :005 > 1..2.include?(3) | |
NoMethodError: undefined method `include?' for 2:Fixnum |
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
<?xml version="1.0"?> | |
<settings> | |
<console change_refresh="10" refresh="100" rows="40" columns="120" buffer_rows="999" buffer_columns="120" shell="" init_dir="c:\applications" save_size="0"> | |
<colors> | |
<color id="0" r="0" g="0" b="0"/> | |
<color id="1" r="0" g="0" b="128"/> | |
<color id="2" r="0" g="150" b="0"/> | |
<color id="3" r="0" g="150" b="150"/> | |
<color id="4" r="170" g="25" b="25"/> | |
<color id="5" r="128" g="0" b="128"/> |
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 Array | |
# wrap elements in blueprintcss-oriented div tags | |
# ex. results.to_blueprint_html('span', 2, 10, 4, 8) | |
def to_blueprint_html(css_class, *args) | |
raise ArgumentError, "args count doesn't match number of elements" if args.size != self.size | |
output = [] | |
each_with_index do |item, index| | |
output << "<div class='#{css_class}-#{args[index]}'>#{item}</div>" | |
end | |
output.last.gsub!(/'>/, " last'>") # last element should have 'last' class assigned |
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 with: | |
# bash < <(curl -L https://raw.github.com/gist/1621689) | |
# | |
# Reference: http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug | |
# | |
# > bundle -v | |
# > Bundler version 1.0.21 | |
echo "Installing ruby-debug with ruby-1.9.3-p0 and Bundler ..." |
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
def ApplicationController | |
# perhaps in a mixin | |
def permanent_redirect_to(options) | |
url = case options | |
when String | |
options | |
else | |
url_for(options) | |
end | |
head :moved_permanently, :location => url |
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
def combine_anagrams(words) | |
h = {} | |
words.map do |word| | |
sort_key = word.each_char.sort.join | |
h[sort_key] ||= [] | |
h[sort_key] << word | |
end | |
h.values | |
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
### | |
# Rails Controller to manage an NFL team's fans | |
# from a email signup form | |
### | |
class FansController < ActionController::Base | |
def create | |
@fan = Fan.new(fan_params) | |
respond_to do |format| |
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
# Demonstrates a basic module mixin and a slightly advanced meta technique: | |
# the use_socket (line 13) wrapper method connects to a server and issues | |
# various SocketIO commands. I use instance_eval (line 16) with a recipient | |
# SocketIO object, not an instance of the caller (NodeMessenger). | |
# instance_eval runs the passed block with receiver of self, which is a | |
# SocketIO object. | |
# The general purpose of this code is to talk to a Socket.io server | |
require 'SocketIO' | |
module NodeSocket |
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 makeFun() { | |
var f = []; | |
// closure to freeze vars in async loop | |
var sum = function (n, m) { | |
return function () { | |
console.log("sum=" + (n + m)); | |
} | |
}; |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
OlderNewer