This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Authlogic | |
module Session | |
# Lets you log in using a HTTP token, using the single_access_token. | |
# Behaves similarly to Params, but with HTTP, so it's nice for APIs. | |
module HttpToken | |
def self.included(klass) | |
klass.class_eval do | |
extend Config | |
include InstanceMethods | |
persist :persist_by_http_token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class DummyController < ApplicationController | |
def index | |
render :nothing => true | |
end | |
end | |
MyApp::Application.routes.disable_clear_and_finalize = true | |
MyApp::Application.routes.clear! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding : utf-8 -*- | |
class UserSession | |
include ActiveModel::Conversion | |
include ActiveModel::Validations | |
extend ActiveModel::Naming | |
validates_presence_of :email | |
validates_presence_of :password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support/core_ext/hash/conversions' | |
require 'rake/clean' | |
require 'json' | |
require 'yaml' | |
require 'maruku' | |
require 'mustache' | |
require 'ostruct' | |
require 'haml' | |
CLEAN.include(%w|*.html *.xml *.json *.txt|) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AnagramCounter | |
def count_anagrams | |
Hash[group_by { |x| x.split('').sort.join }.map { |x, y| [x, y.length] }] | |
end | |
end | |
Array.send(:include, AnagramCounter) | |
puts ["abb", "bba", "aba", "bba", "abb", "aab", "abc"].count_anagrams.inspect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_record' | |
# A sample application, consisting of products, users, comments, categories, and whatnot. | |
module SampleApp | |
class Product < ActiveRecord::Base | |
belongs_to :user | |
has_many :comments, :as => :commentable | |
has_many :transactions | |
has_and_belongs_to_many :categories |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Includes a file from a gem. Useful for reusing test helper files from the gems | |
# you're writing functionality for. | |
def gem_file(gem, file, *gem_requirements) | |
File.join(Gem::Dependency.new(gem, *gem_requirements).to_spec.gem_dir, file) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
$username = "08312345676" # Replace with your phone number | |
$password = "000000" # Replace with your webtext PIN | |
require 'mechanize' | |
# A simple three.ie webtext CLI. | |
# Requires Ruby 1.9 and Mechanize (gem install mechanize) | |
# Logs in, fills in the webtext form, submits it, and prints out the result. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'linode' | |
require 'open-uri' | |
$api_key = "MY LINODE API KEY" | |
$subdomain = "my.subdomain.example.com" | |
# Updates a Linode DNS record. Can be used to create a dynamic DNS within a | |
# domain of your own. Just set the subdomain to whatever. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
# | |
# A silly script to demonstrate the Monty Hall Problem. | |
# http://en.wikipedia.org/wiki/Monty_Hall_problem | |
# | |
# Usage | |
# ruby [-v] monty.rb <n> | |
# where n is the number of times each of the 3 players plays the game. | |
# |
OlderNewer