Skip to content

Instantly share code, notes, and snippets.

View aguilarsoto's full-sized avatar

Marco V. Aguilar Soto aguilarsoto

  • San Jose, Costa Rica
View GitHub Profile
@aguilarsoto
aguilarsoto / gist:2432748
Created April 21, 2012 00:02
pascal triangle out to out.txt and length received by console
def pascal(n)
file = File.open("out.txt", "w")
p=[1]
while(p.length<n)
file.write(p.join(" ")+"\n")
p=Array.new(p.length+1) do |i|
a=i<p.length ? p[i] : 0
b=i>0 ? p[i-1] : 0
a+b
end
@aguilarsoto
aguilarsoto / gist:2432701
Created April 20, 2012 23:45
pull from twitter parse and return array
require 'rubygems'
require 'json'
require 'open-uri'
timeline = 'https://api.twitter.com/1/statuses/public_timeline.json'
data = open(timeline)
foo = Array.new
result = JSON.parse(data.read)
result.each do |r|
if r['usernames'] || r['text'].match('ruby'))
@aguilarsoto
aguilarsoto / magic
Created November 9, 2011 15:39
nov puzzle geek dad
%http://www.wired.com/geekdad/2011/11/geekdad-puzzle-of-the-weekwizards-and-mages-and-shamans-oh-my/
solucion(Sol):- Sol=[[gabdalf,_,falton,_],[_,_,_,mage],[_,_,_,necromancer],_,_],
member([R1,human,dragonstorm,_],Sol),
member([rokar,_,_,ilusionist],Sol),
is_set([R1,rokar]),
member([_,wood_elf,smeedly,_], Sol),
member([malfor,HE,_,wizard],Sol),
member([_,highelf,_,_],Sol),
is_set([HE,highelf]),
member([_,halforc,V,MA],Sol),
lala = {}
img = Magick::Image::read('joker.bmp').first
img.each_pixel do |bar, c, r|
lala[bar]= 0 unless lala[bar]
lala[bar] = lala[bar]+1
end
lala
{
*
-
user: {
o avatar_url: http://s3.amazonaws.com/socialbooks-development/user/default
o created_at: "2011-01-13T20:27:42Z"
o location: null
o following_count: 0
o updated_at: "2011-01-13T20:27:42Z"
maguilar@naru:~/tmp/getsocialbooks.com/config$ heroku rake db:populate --app social-books-dev
(in /home/app/57f59070-ca2b-482a-a1f1-d3217190f3dd)
Creating default users...
Done.
Creating default users...
Done.
Downloading dummy books...
Creating books. This will take awhile...
Creating book: machiavelli-prince.epub
Creating book: wilde-picture-of-dorian-gray.epub
$ rake db:populate --trace
(in /home/maguilar/getsocialbooks.com)
** Invoke db:populate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:populate
Removing all old content...
Creating users...
Creating followings...
rake aborted!
irb(main):021:0> ash = Book.serializable_hash_options
=> {:include=>{:authorships=>{:only=>["id", "author_id", "book_id", "created_at", "updated_at"]}}, :only=>[:id, :title, :created_at, :updated_at, :epub_checksum]}
irb(main):022:0> ash2
=> {:include=>{:spine_items=>{:only=>["id", "author_id", "book_id", "created_at", "updated_at"]}}}
irb(main):023:0> ash.reverse_merge(ash2)
=> {:include=>{:authorships=>{:only=>["id", "author_id", "book_id", "created_at", "updated_at"]}}, :only=>[:id, :title, :created_at, :updated_at, :epub_checksum]}
irb(main):024:0> ash.merge(ash2)
maguilar@naru:~/getsocialbooks.com$ rake jobs:work --trace
(in /home/maguilar/getsocialbooks.com)
** Invoke jobs:work (first_time)
** Invoke merb_env (first_time)
** Execute merb_env
** Invoke environment (first_time)
** Execute environment
** Execute jobs:work
*** Starting job worker host:naru pid:25747
rake aborted!
user_controller.rb
def show
respond_to do |format|
format.json { render :json => @user.to_json(:method => [:avatar_url])}
end
end