Skip to content

Instantly share code, notes, and snippets.

View ciniglio's full-sized avatar

Alejandro Ciniglio ciniglio

View GitHub Profile
@ciniglio
ciniglio / gist:4757315
Last active December 12, 2015 10:09
Installing Mongodb with macports

Use macports to install mongodb

sudo port install mongodb

Chown db dirs to _mongo user

sudo chown -R _mongo:_mongo /opt/local/var/db/mongodb/ sudo chown -R _mongo:_mongo /opt/local/var/log/mongodb/

Copy launchagent and load it

sudo cp /opt/local/etc/LaunchDaemons/org.macports.mongodb/org.macports.mongodb.plist /Library/LaunchAgents/ sudo launchctl load -w /Library/LaunchAgents/org.macports.mongodb.plist

@ciniglio
ciniglio / each does add new scope.rb
Created December 12, 2012 16:06
Closures in loops
a = (0..100).to_a
f = []
#for i in a
a.each do |i|
f << -> {
puts i }
end
f.each do |i|
i.call
@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
@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 / 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 / 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 / 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 +++++
func main() {
t := NewThing(0)
for i := 0; i < 10; i++ {
inc(t)
}
}
func addOne(i int) {
return i + 1
}
@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()
}
}
@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