Skip to content

Instantly share code, notes, and snippets.

@djo
djo / gist:1256688
Created October 1, 2011 21:42
Pseudorandom number generator stub
words = ['qwerty', 'abcdef', 'xyzzyx']
SecureRandom.stub(:base64) { words.shift }
SecureRandom.base64.should eq('qwerty')
SecureRandom.base64.should eq('abcdef')
SecureRandom.base64.should eq('xyzzyx')
@djo
djo / Gemfile
Created November 15, 2011 10:18
Sinatra, Bundler, RSpec2 Example
# ./Gemfile
source "http://rubygems.org"
gem "sinatra", "~> 1.3.1"
group :test do
gem "rspec", "~> 2.7.0"
gem "rack-test", "~> 0.6.1"
gem "fuubar", "~> 0.0.6"
@djo
djo / js.html.haml
Created December 13, 2011 10:07
Speed up your Capybara JS specs you can turn off jquery animation. In this case all animations will immediately set elements to their final state when called, rather than displaying an effect.
- if Rails.env.test?
:javascript
$.fx.off = true;
@djo
djo / autoheight.js
Created December 13, 2011 10:25
Autoheight iframe
// iframe auto-height
(function ($) {
$.fn.autoheight = function () {
return this.each(function () {
var iframe = $(this);
var height = iframe.contents().find('body').height() + 20;
iframe.height(height);
});
@djo
djo / application.rb
Created December 20, 2011 09:26
Enforce that all models define their accessible attributes
# Enforce that all models define their accessible attributes
config.active_record.whitelist_attributes = true
@djo
djo / delayed_job_config.rb
Created December 20, 2011 09:58
Change mass-assignment protection strategy to black-list to allow updates of virtual attributes
# Change mass-assignment protection strategy to black-list to allow updates of virtual attributes
Delayed::Job.attr_protected nil
@djo
djo / problem1.rb
Last active September 30, 2015 19:58
The Embedly Challenge, http://apply.embed.ly
# Problem 1 of 3: Math
# ====================
#
# n! means n * (n - 1) * ... * 3 * 2 * 1
# For example, 10! = 10 * 9 * ... * 3 * 2 * 1 = 3628800
# Let R(n) equal the sum of the digits in the number n!
# For example, R(10) is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
# Find the lowest value for n where R(n) is 8001.
#
# Result: 787.
@djo
djo / watch.sh
Created April 4, 2012 14:19
watch command
# Monitor some background process on execution
watch -n 1 "ps aux | grep php"
@djo
djo / say_hello.rb
Created April 6, 2012 13:51
Example for rungist.com
# Example for http://rungist.com/
about = ".xobdnas ybur eht ni tsig s'buhtig a nur ot uoy swolla tI .ybuR yrT rehtonA teY eht si sihT"
"Hi, #{about.reverse}"
@djo
djo / upgrade_notes.md
Created December 4, 2012 10:54
Upgrade to 1.9 notes

Upgrade "the second project" to ruby 1.9 notes

Gems

Keep in mind that not all gems (versions) support a needed ruby version.

  • Remove 1.8 gems: rcov, ruby-debug
  • Add 1.9 gems: debugger

Try 'bundle install'.