Skip to content

Instantly share code, notes, and snippets.

View maxim's full-sized avatar
🛠️

Max Chernyak maxim

🛠️
View GitHub Profile
@maxim
maxim / the wtf
Created June 6, 2012 00:58
These are commands I ran...
♢ ✗ bundle outdated
[...]
* resque (1.20.0 > 1.8.2)
♢ ✗ bundle update resque
[...]
♢ ✗ bundle outdated
@maxim
maxim / gist:2244442
Created March 29, 2012 22:36
Bookmarklets to switch between ruby docs versions
@maxim
maxim / gist:1886617
Created February 22, 2012 18:51
Drier integration testing with RSpec and Capybara
# Drier integration testing with RSpec and Capybara
# Not happy with this
page.should have_content("foo")
page.should have_content("bar")
page.should have_unchecked_field("baz")
# Better
@maxim
maxim / gist:1872879
Created February 21, 2012 01:48
Passing classes vs objects
# Passing classes
class Item
def apply_coupon(coupon_class)
coupon_class.new(self).apply
end
end
class Coupon
attr_reader :target
>> foo = proc { bar }
=> #<Proc:0x0000000101c444b8@(pry):1>
>> foo.call
NameError: undefined local variable or method `bar' for #<Object:0x1001dc288>
from (pry):1
>> def bar
>> "bar"
>> end
@maxim
maxim / Rules
Created February 9, 2012 19:59
Convenient redirects with nanoc
#!/usr/bin/env ruby
# ...
preprocess do
RedirectGenerator.generate(config[:redirects], items)
end
route '/old_posts/*' do
item.identifier.sub('old_posts/', '') + 'index.html'
@maxim
maxim / schema.rb
Created December 18, 2011 09:10
Quick schema.rb lookup
# Quick schema.rb lookup shell function.
#
# Usage
# schema — print all tables in schema.rb
# schema [table] — print particular table in schema.rb
function schema() {
if test "$1" = ""; then
grep 'create_table' db/schema.rb | cut -d \" -f2
else
@maxim
maxim / gist:1225452
Created September 18, 2011 19:34
Delete buffer if last window, otherwise close window
" Closes window if there are more windows opened to the same buffer.
" Otherwise deletes buffer.
fun! WinQuitOrBufDelete ()
let win_cnt = 0
for wnr in range(1, winnr("$"))
if winbufnr(wnr) == bufnr("%")
let win_cnt += 1
endif
@maxim
maxim / manifest.yml
Created July 29, 2011 22:15
Resque worker script for development, written for takeup
# This is what would be in your takeup manifest to run this script.
# Find takeup at http://github.com/maxim/takeup
- name: "resque"
pid_file: ":project_root/tmp/pids/resque.pid"
start: "LOG=':project_root/log/resque.log' PIDFILE=:pid_file :support_root/resque_worker &"
stop: "kill `cat :pid_file`"
# Ways to assign a timestamp:
@user.logged_in_at = Time.current
@user.logged_in_at = Time.now
@user.update_attribute(:logged_in_at, Time.now)
@user.update_attribute(:logged_in_at, Time.current)
@user.update_attributes(:logged_in_at => Time.now)
# Also consider variations of those.
# Or just...