Skip to content

Instantly share code, notes, and snippets.

View lukewendling's full-sized avatar

Luke Wendling lukewendling

View GitHub Profile
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
<?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"/>
@lukewendling
lukewendling / gist:92548
Created April 9, 2009 16:05
add a blueprintcss-based 'to_html' method to Ruby's Array
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
@lukewendling
lukewendling / gist:1621689
Created January 16, 2012 16:37 — forked from dx7/gist:1333785
Installing ruby-debug with ruby-1.9.3-p0 and Bundler
# 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 ..."
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
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
@lukewendling
lukewendling / gist:7027680
Last active December 25, 2015 19:29
Basic structure of a Rails API with Backbone frontend
###
# 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|
@lukewendling
lukewendling / gist:7030008
Last active December 25, 2015 19:48
Ruby meta - instance_eval inside a block
# 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
@lukewendling
lukewendling / makeFun.js
Last active December 27, 2015 12:19
let's assume the original f object was supposed to be an array
function makeFun() {
var f = [];
// closure to freeze vars in async loop
var sum = function (n, m) {
return function () {
console.log("sum=" + (n + m));
}
};
@lukewendling
lukewendling / sample.geo.json
Created February 1, 2016 22:14
Embed Map - sample geo json
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.