Skip to content

Instantly share code, notes, and snippets.

View justinko's full-sized avatar

Justin Ko justinko

View GitHub Profile
# In request/integration/acceptance specs, the more examples you have, the slower the spec.
# This obviously applies to any other kind of spec, but the performance trade off
# is not worth it for high level tests - it can potentially cost you seconds.
# Hard to read/process but fast
describe 'viewing a user profile' do
before { login }
it 'displays the name, birthdate, active, address, phone number, last login'
end
ruby-1.9.3-preview1 :070 > a = [Array, String, Class.new(String)]
=> [Array, String, #<Class:0x007fcab38332b0>]
ruby-1.9.3-preview1 :071 > a.shuffle
=> [#<Class:0x007fcab38332b0>, String, Array]
ruby-1.9.3-preview1 :072 > a.shuffle(random: Random.new(1))
=> [Array, #<Class:0x007fcab38332b0>, String]
ruby-1.9.3-preview1 :073 > a.shuffle(random: Random.new(1))
=> [Array, #<Class:0x007fcab38332b0>, String]
ruby-1.9.3-preview1 :074 > a.shuffle(random: Random.new(2))
=> [#<Class:0x007fcab38332b0>, Array, String]
Search
User enters a non-searchable value
Search for "***" on the search page
"Seriously?" is shown in the message section
No search log is created
Search service is down # This can function as a step too, if one is found.
"Search unavailable, go away" is show in the message section
➜ Downloads gcc -pthread threading1.c
threading1.c:14: error: conflicting types for ‘wait’
/usr/include/sys/wait.h:255: error: previous declaration of ‘wait’ was here
threading1.c: In function ‘threadFunction’:
threading1.c:91: warning: format ‘%i’ expects type ‘int’, but argument 2 has type ‘pthread_t’
threading1.c:91: warning: format ‘%i’ expects type ‘int’, but argument 2 has type ‘pthread_t’
threading1.c:98: warning: format ‘%i’ expects type ‘int’, but argument 2 has type ‘pthread_t’
threading1.c:98: warning: format ‘%i’ expects type ‘int’, but argument 2 has type ‘pthread_t’
threading1.c: At top level:
threading1.c:107: error: conflicting types for ‘wait’
class MyClass
def self.all_methods
all_singleton_methods + all_instance_methods
end
def self.all_singleton_methods
singleton_methods
end
def self.all_instance_methods
@justinko
justinko / gist:1509034
Created December 22, 2011 05:22
Avdi Grimm's creation, pulled from Objects on Rails
def stub_module(full_name)
full_name.to_s.split(/::/).inject(Object) do |context, name|
begin
context.const_get(name)
rescue NameError
context.const_set(name, Module.new)
end
end
end
@justinko
justinko / module_stubbing.rb
Created December 22, 2011 19:52 — forked from myronmarston/module_stubbing.rb
Avdi Grimm's creation, pulled from Objects on Rails
module ModuleStubbing
def stubbed_modules
@stubbed_modules ||= []
end
def stub_module(full_name)
most_shallow_stubbed_module = nil
full_name.to_s.split(/::/).inject(Object) do |context, name|
begin
class PostsController < ApplicationController
before_filter :post, only: :create # this feels like it's "posting", not setting a post
helper_method :post
def create
post.save
end
def post
@post ||= Post.new(params.fetch(:post) {{}})
@justinko
justinko / post_creation_context.rb
Created January 9, 2012 22:38
The value of contexts in DCI
class PostCreationContext
def initialize(post)
@post = post
@post.extend PostNotifier
@post.extend PostIndexer
@post.extend PostCacher
end
def execute
@post.save
@justinko
justinko / gist:1592044
Created January 11, 2012 00:01
rbx error
This change:
https://github.com/rubinius/rubinius/commit/15f8bdf440236481c5fcb953234b1e173edf9e2e
Breaks this code:
https://gist.github.com/1065789
Backtrace:
Kernel(NilClass)#each (method_missing) at kernel/delta/kernel.rb:81
Rubinius::AST::Container(Rubinius::AST::Script)#container_bytecode at \
/Users/justinko/.rvm/rubies/rbx-head/runtime/18/compiler/ast/definitions.rbc:944