Skip to content

Instantly share code, notes, and snippets.

View arya's full-sized avatar

Arya Asemanfar arya

  • San Francisco, California
View GitHub Profile
# original
def randomized
order = self.dup
result = []
result << order.choice! until order.blank?
result
end
# new
def randomized(n = nil)
/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)"
<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>
# 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|
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}
<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;
#fails
class AnonymousFunction
def initialize(&func)
self.class.send(:define_method, :call, &func)
end
end
blah = 1
s = AnonymousFunction.new do |blah|
puts blah
# 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
# 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)
#
# bash completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# 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