Skip to content

Instantly share code, notes, and snippets.

View josevalim's full-sized avatar

José Valim josevalim

View GitHub Profile
module Introspection
% This method is generated automatically by
% Elixir and is exhibited here as an example.
% def __module_name__
% 'Introspection
% end
def original_inspect
inspect
end
module UnicornPowers
def fire_super_ray_beam
self.ray_beam_power
end
end
module TomCruise
mixin UnicornPowers
def ray_beam_power
@josevalim
josevalim / plain_text_controller.txt
Created July 30, 2011 18:26
Plain text controller. Exercise to the reader: which advantages of cucumber are actually carried over to such examples?
Given the posts controller
it requires authentication before each action except index and show
Given the action index
it retrieves all posts
and responds to formats:
* html
* xml
Given the action show
@josevalim
josevalim / rbx_partial_application.diff
Created September 17, 2011 20:59
Partial application on rubinius. Apply the diff to rubinius project and run `rake build`. Idea by @josevalim, code by @wycats.
diff --git a/lib/compiler/ast/transforms.rb b/lib/compiler/ast/transforms.rb
index 19e1cfb..4e52ec2 100644
--- a/lib/compiler/ast/transforms.rb
+++ b/lib/compiler/ast/transforms.rb
@@ -59,6 +59,71 @@ module Rubinius
end
end
+ # Provide an underscore node that allows partial application in Ruby.
+ # Instead of doing a method call, we are going to generate a lambda
@josevalim
josevalim / omniauth_controller.rb
Created October 8, 2011 10:58
Dynamic omniauth
class OmniauthController < ApplicationController
def start
request_phase(:facebook, client_id, client_secret)
end
def callback
callback_phase(:facebook, client_id, client_secret) do
render :text => "Done!"
end
end
@josevalim
josevalim / Gemfile
Created November 14, 2011 10:04
Ruby-Prof
source :rubygems
gem "ruby-prof"
@josevalim
josevalim / application.rb
Created December 6, 2011 11:54
Potentially faster boot
# THANKS EVERYONE FOR YOUR BELOVED BENCHMARKS.
# THIS PATCH IS NOW IN RAILS:
#
# https://github.com/rails/rails/commit/885a599303585b796da7a0a1c3ccd0bc5c642134
# Please add the following lines after Bundler.require
# and before "class Application < Rails::Application"
# in your config/application.rb
#
# Notice this is just an experiment, don't leave those
@josevalim
josevalim / 1_README.md
Created December 13, 2011 09:30
FSSM based FileWatcher for Rails

Rails 3.2 ships with a simple FileWatcher that only reloads your app if any of the files changed.

Besides, it also provides a mechanism to hook up your own file watcher mechanism, so we can use tools like FSSM that hooks into Mac OS X fsevents. This is an example on how to hook your own mechanism (you need Rails master, soon to be Rails 3.2):

  1. Copy the 2_file_watcher.rb file below to lib/file_watcher.rb

  2. Add the following inside your Application in config/application.rb

if Rails.env.development?

@josevalim
josevalim / index.erb
Created December 13, 2011 22:54 — forked from rafacv/index.erb
Code to get a hanging POST request on Windows using WEBRICK.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(function () {
$("#myb").click(function () {
$.ajax({
url: "/showme",
type: "POST",
data: {nome: "Jose", sobrenome: "Valim"},
<% @widgets.each do |widget| %>
<p><%= widget.name %></p>
<% end %>