Skip to content

Instantly share code, notes, and snippets.

View ciniglio's full-sized avatar

Alejandro Ciniglio ciniglio

View GitHub Profile
@ciniglio
ciniglio / challenge.rb
Created May 2, 2012 04:58 — forked from isa/gist:2571012
Convert in less than 30 lines
LIST = [['A','B','C'], ['A','C','E'], ['E','F','D'],['D','A','J'],['E','D','J']]
out = Hash.new(0)
LIST.each do |row|
arr = row.sort + row.sort
3.times { out[[arr.shift,arr.shift].sort] += 1 }
end
for key in out.keys.sort do
puts "#{key.join(", ")}, #{out[key]}"
end
@ciniglio
ciniglio / gist:3913131
Created October 18, 2012 16:43
Scroll half a screen
(global-set-key (kbd "C-c V") (lambda ()
(interactive)
(scroll-up-command (/ (window-total-height) 2))))
@ciniglio
ciniglio / gist:4077081
Created November 15, 2012 06:50
Installing postgres on mac for rails dev

Installation

Install Postgres and have it load on startup

sudo port install postgresql92-server
sudo port load postgresql92-server

Make needed dirs

sudo mkdir -p /opt/local/var/db/postgresql92/defaultdb
@ciniglio
ciniglio / External.go
Created November 29, 2012 16:13
Internal Channels Pattern
func main() {
t := NewThing(0)
var r int
for i := 0; i < 10; i++ {
r = t.inc()
}
}
func main() {
t := NewThing(0)
for i := 0; i < 10; i++ {
inc(t)
}
}
func addOne(i int) {
return i + 1
}
@ciniglio
ciniglio / gist:4218251
Created December 5, 2012 18:35
Added multi-byte support for string#chop
From 2f5fa63bf565c7dcc6f3ff4808eab337f1240dff Mon Sep 17 00:00:00 2001
From: Alejandro Ciniglio <mail@alejandrociniglio.com>
Date: Wed, 5 Dec 2012 12:08:45 -0500
Subject: [PATCH] Added multi-byte support for String#chop
Added support for string19
Added spec to test under 1.9
---
kernel/common/string19.rb | 11 ++++++++++-
spec/ruby/core/string/chop_spec.rb | 5 +++++
@ciniglio
ciniglio / lastindex.rb
Created December 7, 2012 17:00
Recursion
def lastindex(e, a)
return -1 if a.empty?
if a.pop == e
return a.length
end
return lastindex(e, a)
end
@ciniglio
ciniglio / Palindrome.rb
Created December 10, 2012 00:36
Grepline Challenge Pt 1
# Palindrome checker
def palindrome?(s)
a = s.split("")
while a.length > 1 do
return false unless a.pop == a.shift
end
return true
end
@ciniglio
ciniglio / fib.rb
Created December 10, 2012 00:58
Greplin challenge p2
def fib(n)
@a ||= [1,1]
(0..n).each do |i|
@a[i] = @a[i-1] + @a[i-2] unless @a[i]
end
@a[n]
end
def fib_after(n)
@ciniglio
ciniglio / subsets.rb
Created December 10, 2012 01:22
Greplin challenge p3
def subset_sum(a)
ret = []
while a.length > 1 do
n = a.pop
find_sum_from_left(n, a).each do |arr|
ret << (arr + [n])
end
end
return ret
end