Skip to content

Instantly share code, notes, and snippets.

José Valim josevalim

Block or report user

Report or block josevalim

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View fib_with_agents.exs
defmodule FibAgent do
def start_link do
cache = Enum.into([{0, 0}, {1, 1}],
Agent.start_link(fn -> cache end)
def fib(pid, n) when n >= 0 do
Agent.get_and_update(pid, &do_fib(&1, n))
View exq_web_router.ex
defmodule Exq.RouterPlug do
import Plug.Conn
use Plug.Router
plug :match
plug :dispatch
get "/queues" do
IO.puts "YOLO"
conn |> halt()
View example.ex
defmodule SomeModule do
def start(host, options) do
# We are assuming SomeSup has been already started somewhere
# (ideally in a supervision tree).
{:ok, child_pid} = SomeSup.attach_to(SomeSup, host, options)
defmodule SomeSup do
use Supervisor
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master*]$ # dirty working directory
function parse_git_deleted {
[[ $(git status 2> /dev/null | grep deleted:) != "" ]] && echo "-"
function parse_git_added {
[[ $(git status 2> /dev/null | grep "Untracked files:") != "" ]] && echo '+'
mkdir -p /usr/local/src && cd /usr/local/src
tar -xjvf ruby-1.9.1-p0.tar.bz2
cd ruby-1.9.1-p0
./configure --prefix=/usr --program-suffix=19 --enable-shared
make && make install
View templater_dsl.rb
module ActiveRecord
module Generators
class ModelGenerator < Base
# Line below is optional. If the generator name would be :model, the name
# below could be guessed.
# Generators are also public by default. If they are private it can be
# invoked only by other generators.
name :activerecord, :private => false
View quiz.rb
# How would you test this Quiz#problem method? Only two rules:
# 1. You must test the order the gets/puts happen. The tests should not
# still pass if "gets" happens before "puts", etc.
# 2. No changing the Quiz class implementation/structure. But you can
# use whatever framework you want for the tests.
View gist:283011
[ Carlhuda ]
actionmailer/lib/action_mailer/railtie.rb:17 (was actionmailer/lib/action_mailer/rails.rb)
actionmailer/lib/action_mailer/railtie.rb:23 (was actionmailer/lib/action_mailer/rails.rb)
actionpack/lib/action_controller/railtie.rb:17 (was actionpack/lib/action_controller/rails.rb)
actionpack/lib/action_controller/railtie.rb:37 (was actionpack/lib/action_controller/rails.rb)
activerecord/lib/active_record/railtie.rb:74 (was activerecord/lib/active_record/rails.rb)
View snippet.rb
# require "rack/openid"
require 'devise/strategies/base'
require 'uri'
module Devise
module Strategies
# Default strategy for signing in a user, based on openid
# Redirects to sign_in page if it's not authenticated
class OpenId < Warden::Strategies::Base
include Devise::Strategies::Base
View gist:356909
Warden::Strategies.add(:openid) do
def valid?
def authenticate!
if resp = env[Rack::OpenID::RESPONSE] "Attempting OpenID auth: #{env["rack.openid.response"].inspect}"
case resp.status
when :success
You can’t perform that action at this time.