Skip to content

Instantly share code, notes, and snippets.

View cyril's full-sized avatar
🌶️
I like spicy pad thai

Cyril Kato cyril

🌶️
I like spicy pad thai
View GitHub Profile
@tenderlove
tenderlove / person_test.rb
Created February 10, 2011 23:10
Use minitest/spec with Rails 3
require 'test_helper'
require 'minitest/autorun'
class MiniTest::Spec
include ActiveSupport::Testing::SetupAndTeardown
include ActiveRecord::TestFixtures
alias :method_name :__name__ if defined? :__name__
self.fixture_path = File.join(Rails.root, 'test', 'fixtures')
end
require "twitter"
require "sunlight"
data_pos = DATA.pos
last_id = DATA.read.to_s[/\d+/]
last_id = last_id.to_i if last_id
DATA.reopen(__FILE__, "a+")
Twitter.configure do |config|
@gabrielstuff
gabrielstuff / reset_db_password.sh
Created November 19, 2011 11:36
This little snippet helps to reset mysql root password
$ ps -ax
$ #Kill all the related mysql process and direct run the next lines#
$ sudo /usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
#direct log after execute bellow command#
$ mysql -u root
mysql > database mysql;
@ahawkins
ahawkins / web_object.rb
Created May 11, 2012 14:04
My take on ActiveResource using OpenStruct delegating to a HTTP class.
module RadiumIo
class WebObject < OpenStruct
def initialize(attrs = {}, &block)
super
yield self if block_given?
end
def self.create(attributes = {}, &block)
account = new attributes, &block
account.save
@solnic
solnic / fun.rb
Last active December 26, 2015 23:29
Ruby object that has "functions" rather than methods
class Function
attr_reader :name, :fn
class Composed
attr_reader :left, :right
def initialize(left, right)
@left = left
@right = right
end
@netzpirat
netzpirat / 0_README.md
Created November 12, 2010 10:42
Continuous CoffeeScript testing with Guard and Jasmine

Continuous CoffeeScript testing with Guard and Jasmine

This Gist shows how to set up a Rails project to practice BDD with CoffeeScript, Guard and Jasmine. You can see this setup in action on Vimeo

  • Install Gems with Bundler with bundle install
  • Define your guards with mate Guardfile
  • Initialize Jasmine with bundle exec jasmine init
  • Configure Jasmine with mate spec/support/yasmine.ym
  • Start Guard with bundle exec guard
@robcthegeek
robcthegeek / user.rb
Created November 9, 2011 21:32
"Standard" User Model Using Mongoid/BCrypt
require 'bcrypt'
class User
include Mongoid::Document
include Mongoid::Timestamps
include BCrypt
attr_accessor :password, :password_confirmation
attr_protected :password_hash
@drnic
drnic / Guardfile
Created April 5, 2012 06:45
An example Guardfile with the works for a Rails app
guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
@dhh
dhh / gist:981520
Created May 19, 2011 19:27
bulk api
# Bulk API design
#
# resources :posts
class PostsController < ActiveController::Base
# GET /posts/1,4,50,90
# post_url([ @post, @post ])
def show_many
@posts = Post.find(params[:ids])
end
@josevalim
josevalim / 0_README.md
Created September 13, 2012 21:52
Sinatra like routes in Rails controllers

Sinatra like routes in Rails controllers

A proof of concept of having Sinatra like routes inside your controllers.

How to use

Since the router is gone, feel free to remove config/routes.rb. Then add the file below to lib/action_controller/inline_routes.rb inside your app.