Skip to content

Instantly share code, notes, and snippets.

View mrsimo's full-sized avatar
💃
./do run hello

Albert Llop mrsimo

💃
./do run hello
View GitHub Profile
# gem install json --version=1.4.6
Successfully installed json_pure-1.4.2
1 gem installed
$ geoffrey install adium
>> Adium is a free instant messaging application for Mac OS X that can connect to AIM, MSN, Jabber, Yahoo, and more.
>> Downloading http://adiumx.cachefly.net/Adium_1.3.10.dmg
: 100% |oooooooooooooooooooooooo| 21.3MB 451.6KB/s ETA: 00:00:00
>> Moving file to /Applications
>> Install successful
(rdb:1) cookies
{:intranet_id=>"4", :intranet_hash=>"$2a$10$byweo.aZfMGUpCjgoXjLD.exllI.K8PJ8LZZVnOuC6ve1TzT9Mg5y"}
(rdb:1) cookies[:intranet_id]
nil
(rdb:1) cookies.class
ActionDispatch::Cookies::CookieJar
# With a typical synchronous API
Api::User.exists?('mrsimo') # => true / false
# With an async API
exists = Api::User.exists?('mrsimo')
API.run_queue
exists.result # => true / false
# In ActiveRecord I'd usually do when I want to find the organization but only if the user belongs to it:
current_user.organizations.find(params[:id])
# With a has_and_belongs_to_many relationship with Mongoid, I have to do this:
Organization.where(:_id => params[:id], :user_ids => current_user.id).first
# => #<Organization _id: 4ea3302c2907207f5100000f ...
# Because:
current_user.organizations
# => [#<Organization _id: 4ea3302c2907207f5100000f ...>]
@mrsimo
mrsimo / receta.md
Created November 13, 2011 21:55
Receta de pajaricas (palomitas dulces

Pajaricas

Las pajaricas son palomitas dulces, esta es la receta de mi abuela (de Teruel).

Poner en una olla una medida de maíz, una de azúcar, media de agua y media de aceite de oliva. Con una tacita de café pequeña sale cantidad para una persona, más o menos.

Remover un poquito para que quede uniforme (sino se deshace demasiado azúcar), y poner el fuego a tope. Cuando empiezan a explotar, mover la olla entera circularmente sin alejar del fuego, y no parar hasta que dejen de explotar.

Recomendaciones

branches = `git branch`.chomp.split("\n")
branches.map!(&:strip)
branches.each do |branch|
puts "================================"
puts "Considering: #{branch}"
puts
system "git log --color --stat -n 1 #{branch}"
@mrsimo
mrsimo / hack.sh
Created April 4, 2012 08:34 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2299719/hack.sh | sh
#
@mrsimo
mrsimo / request.rb
Created July 4, 2012 07:46
HTTPS request with Net::HTTP and basic http auth
site = URI("https://some.domain.net/path?event_id=#{event.id}")
http = Net::HTTP.new(site.host, site.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if Rails.env.development?
http.open_timeout = 1
http.read_timeout = 1
req = Net::HTTP::Get.new("#{site.path}?#{site.query}")
req.basic_auth 'user', 'pass'
@mrsimo
mrsimo / helper.rb
Created July 16, 2012 15:05
This SCREAMS to be moved to a model -_-
def participation_options(invitation)
options = []
options << :yes if invitation.can_change_to_yes? || invitation.can_buy_tickets? || invitation.participation == :yes
options << :maybe if invitation.can_change_to_maybe? || invitation.participation == :maybe
options << :no if invitation.can_change_to_no? || invitation.participation == :no
options
end