Skip to content

Instantly share code, notes, and snippets.

View josevalim's full-sized avatar

José Valim josevalim

View GitHub Profile
<% @widgets.each do |widget| %>
<p><%= widget.name %></p>
<% end %>
@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"},
module UnicornPowers
def fire_super_ray_beam
self.ray_beam_power
end
end
module TomCruise
mixin UnicornPowers
def ray_beam_power
# How to give your devise controllers all the same layout (e.g. "authentication" below)
class ApplicationController < ActionController::Base
layout :setup_layout
protected
def setup_layout
devise_controller? ? "authentication" : "application"
end
end
# note that last item is User class
a = [10, [20, 30, ["helo", "world"]], [1.2, 1.3], {:foo => :bar}, User]
puts a.to_xml
<?xml version="1.0" encoding="UTF-8"?>
<objects type="array">
<object type="integer">10</object>
<object type="array">
<object type="integer">20</object>
Warden::Strategies.add(:openid) do
def valid?
!params["openid_identifier"].blank?
end
def authenticate!
if resp = env[Rack::OpenID::RESPONSE]
RAILS_DEFAULT_LOGGER.info "Attempting OpenID auth: #{env["rack.openid.response"].inspect}"
case resp.status
when :success
# 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
[ 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)
actionpack/lib/action_view/template/handlers.rb:13
activerecord/lib/active_record/railtie.rb:74 (was activerecord/lib/active_record/rails.rb)
activesupport/lib/active_support/testing/performance.rb:321
@josevalim
josevalim / quiz.rb
Created May 15, 2009 18:28 — forked from ryanb/quiz.rb
# COMMUNITY CHALLENGE
#
# 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.
#
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