Skip to content

Instantly share code, notes, and snippets.

View Veejay's full-sized avatar

Bertrand Chardon Veejay

View GitHub Profile
require 'rubygems'
require 'sinatra'
get '/' do
erb :index
end
get %r{/(services|faq|about).php} do
erb params[:captures].first.to_sym
end
@Veejay
Veejay / gist:1377379
Created November 18, 2011 18:51
Crash Fiber / Ray using Ruby 1.9.2p180
mango:Ray bertrand$ ruby test_fibers.rb
test_fibers.rb:38: [BUG] Bus Error
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin11.2.0]
-- control frame ----------
c:0014 p:---- s:0050 b:0050 l:000049 d:000049 CFUNC :resume
c:0013 p:0079 s:0047 b:0046 l:002078 d:001478 BLOCK test_fibers.rb:38
c:0012 p:---- s:0044 b:0044 l:000043 d:000043 FINISH
c:0011 p:---- s:0042 b:0042 l:000041 d:000041 CFUNC :instance_exec
c:0010 p:0024 s:0039 b:0039 l:000038 d:000038 METHOD /Users/bertrand/.rvm/gems/ruby-1.9.2-p180/gems/ray-0.2.0/lib/ray/scene.rb:114
@Veejay
Veejay / gist:1953285
Created March 1, 2012 21:16
Test for StaffPlansController#show action
require 'spec_helper'
describe StaffplansController do
before(:each) do
@current_user = login_user
@company = Factory(:company)
@current_user.update_attributes(current_company_id: @company.id)
end
describe 'GET#show' do
$ ->
$('div.client_selector select#project_client_id')
.change ->
if $(@).val() == "new"
$(@).closest('div.client_selector').append '<input id="client_name" name="client[name]" size="30" type="text">'
@Veejay
Veejay / gist:2047303
Created March 15, 2012 22:09
Adds an instance method to arrays that returns an array containing all the elements that satisfy a criterion defined by a block. The elements are REMOVED from the original array.
Array.class_eval do
def extract!
if block_given?
[].tap do |rejects|
delete_if do |element|
yield(element) and rejects << element
end
end
else
self
@Veejay
Veejay / json_serializer.rb
Created March 23, 2012 01:17
JSON Serializer built on top of Jbuilder with emphasis on ease of use
module StaffPlan::JsonSerializer
def serialize(*args)
options = args.extract_options!
if args.first.is_a?(Array) or args.first.is_a?(ActiveRecord::Relation)
serialize_collection(args.first, options)
else
serialize_instance(args.first, options)
end
end
@Veejay
Veejay / password_reset_spec.rb
Created March 26, 2012 21:58
Specs for password reset
require 'spec_helper'
describe RegistrationsController do
describe "Forgetful user gets to the user page. He should have a forgot password link" do
it "should display a template containing the string t('sessions.new.forgot_password')" do
end
end
describe "User provides an email address" do
it "should display a page containg an appropriate text field and a submit button" do
int
mbtowc(wchar_t *p, char *s, size_t n)
{
long l;
int c0, c, nc;
Tab *t;
if(s == 0)
return 0;
@Veejay
Veejay / test.js
Created April 11, 2012 15:58
JSON object
{ companies: [
{ name: “company name”
, users: [
{ id: 1
, first_name: “rob”
, last_name: “sterner”
, project_ids: [1,2,3,4]
}
]
, projects: [
respond_to :json
def index
if params[:secret].eql? SOME_API_TOKEN
respond_with Company.all_with_users_and_projects
else
render { head :forbidden } and return
end
end