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
# original | |
def randomized | |
order = self.dup | |
result = [] | |
result << order.choice! until order.blank? | |
result | |
end | |
# new | |
def randomized(n = nil) |
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
/sbin/ifconfig | grep -Eo "10\.20\.[0-9]{1,3}\.[0-9]{1,3}" | grep -vE "^(255|127)" | sort | uniq | xargs -I{} resolveip {} | awk '{print $6}' | grep -vE "(localhost)" |
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
<fb:user-agent includes="ie 6,ie 7"> | |
<script type="text/javascript"> | |
console.log = function(msg) { | |
var el = document.createElement('div'); | |
$(el).text(msg); | |
$('#debug_console').append(el); | |
}; | |
</script> | |
<style> |
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
# http://www.facebook.com/jobs_puzzles/index.php?puzzle_id=8 | |
require 'set' | |
class Node | |
@@nodes = Hash.new {|h, k| h[k] = Node.new(k)} | |
class << self | |
def find_clusters | |
Node.solidify! | |
clusters = [] | |
nodes.values.each do |n| |
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 multi_choose(choices, size, index = 0, hax = Hash.new) | |
return [] if index == choices.size | |
hax[[size, index]] ||= begin | |
base = [choices[index]] * size | |
s = base | |
multisets = [base] | |
0.upto(size - 1) do |i| | |
s = s.dup | |
s.pop | |
multi_choose(choices, i + 1, index + 1, hax).each {|s2| multisets << s + s2} |
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
<div id="body"> | |
<div id="link_test"> | |
<a href="#should_not_show_up" id="the_link">Click Me</a> | |
</div> | |
<script type="text/javascript"> | |
function TestCase() { | |
document.getElementById('link_test').addEventListener('click', function(){ | |
console.log('clicked from container'); | |
return false; |
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
#fails | |
class AnonymousFunction | |
def initialize(&func) | |
self.class.send(:define_method, :call, &func) | |
end | |
end | |
blah = 1 | |
s = AnonymousFunction.new do |blah| | |
puts blah |
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
# a maybe valid use-case of flip flops | |
begin | |
puts "hi" | |
raise Exception | |
rescue Exception => e | |
retry if ((i ||= 1) == 1)..((i += 1) >= 2) | |
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
# inject but doesn't need you to return the memo, uses the same object. Doesn't work with immutable (i.e. summing) | |
module Enumerable | |
def inject_into(obj) | |
each {|e| yield(obj, e)} | |
obj | |
end | |
end | |
a = [1,2,3].inject_into([]) do |m, e| | |
m << (e + 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
# | |
# bash completion support for core Git. | |
# | |
# Copyright (C) 2006,2007 Shawn O. Pearce <[email protected]> | |
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/). | |
# Distributed under the GNU General Public License, version 2.0. | |
# | |
# The contained completion routines provide support for completing: | |
# | |
# *) local and remote branch names |
OlderNewer