Skip to content

Instantly share code, notes, and snippets.

@dnagir
dnagir / eample.rb
Last active August 29, 2015 14:02
nil, nil, nil
# In the context of Rails app (mailers)
# Somewhere in email helper
def from_address_by(person_name)
return nil unless person_name
address = Mail::Address.new AppConfig.email.from # ex: "john@example.com"
address.display_name = person_name # ex: "John Doe"
address.format # returns "John Doe <john@example.com>"
end
@dnagir
dnagir / output.sh
Last active August 29, 2015 14:02
Chronic time_class (how come it doesn't break in Rubinius?)
> rvm use ruby-2.1.1
Using /Users/dnagir/.rvm/gems/ruby-2.1.1
> ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]
> ruby test.rb
Run options: --seed 49028
# Running:
@dnagir
dnagir / output.sh
Created June 25, 2014 04:57
Unsafe Ruby vars
> ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]
> ruby test.rb
Run options: --seed 22679
# Running:
F.
Finished in 2.320485s, 0.8619 runs/s, 172.3778 assertions/s.
# spec/support/shared_subject.rb
module RSpecSharedSubjectMacros
# Usage:
# 1. Replace 'subject' with 'shared_subject' to share the first result acroos the whole context
# 2. (optional) replace 'before(:each)' blocks with 'shared_setup'
# 3. Done. The subject will be shared within one, single context (nested will be re-setup again)
#
# DANGER NOTE: Make sure you accept the disadvantages of this, such as:
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
class GameOfLife
attr_accessor :state, :height, :width, :rules
def initialize options={}
self.rules = options[:rules] || [ [0,0,0,1,0,0,0,0,0], [0,0,1,1,0,0,0,0,0] ]
self.height = options[:size] || options[:height] || 10
self.width = options[:size] || options[:width] || 10
self.state = options[:seed] || grid { rand(2) }
@dnagir
dnagir / ScottishRubyConf2010-notes.txt
Created May 18, 2011 13:49
The things I learned from Scottish RubyConf 2010
Harmony for browser testing
Capybara.driver = :rack_test # uses Harmony and can run JS
Good talk about Arel: 1LT_04-mp4_500mbs.mp4
Rack GeoIP.
Rack GoogleAnalytics
Rack::Cache (standard)
Rack::CacheBuster
@dnagir
dnagir / gist:996813
Created May 28, 2011 11:52
incompatible character encodings: UTF-8 and ASCII-8BIT
dima@me:~$ rvm gemset create rc1
'rc1' gemset created (/home/dima/.rvm/gems/ruby-1.9.2-p180@rc1).
dima@me:~$ rvm gemset use rc1
Now using gemset 'rc1'
dima@me:~$ gem update --system
Latest version currently installed. Aborting.
dima@me:~$ gem install rails --pre
@dnagir
dnagir / application.js
Created August 19, 2011 09:12
HAML example with pakunok gem
// app/assets/javascripts/application.js
// Include the template into the app
//= require_tree backbone/templates
// And here's how you do the templating
var html = JST.comment(commentModel.attributes);
$(".comments").append(html);
Users
should save record when losing focus from input
Expected spy updateFromForm to have been called.
Error: Expected spy updateFromForm to have been called.