Skip to content

Instantly share code, notes, and snippets.

View bronson's full-sized avatar

Scott Bronson bronson

  • Santa Cruz, CA
View GitHub Profile
# In reply to http://www.ultrasaurus.com/sarahblog/2009/08/ruby-unit-test-frameworks/
# Put this in test_helper.rb to compare two arbitrarily nested structures.
# Usage: compare_objects(o1, o2). Raises an exception if it finds any differences.
# recursivly compare two objects. raise if a difference was found, return if not.
def compare_objects(wanted, actual, path=[])
if wanted.kind_of?(Hash)
raise "Objects differ at #{path.join(".")}: extra keys in wanted: #{(wanted.keys - actual.keys).inspect}" if (wanted.keys - actual.keys).length > 0
raise "Objects differ at #{path.join(".")}: extra keys in actual: #{(actual.keys - wanted.keys).inspect}" if (actual.keys - wanted.keys).length > 0
wanted.keys.sort.each do |key|
module RestClient
# Compatibility : make the Response act like a Net::HTTPResponse when needed
module ResponseForException
def method_missing symbol, *args
puts "called: #{:symbol}"
end
end
end
# produces: undefined method `whatev' for RestClient::ResponseForException:Module (NoMethodError)
# minor improvement to http://blog.js.hu/2010/01/07/unobtrusive-jqgrid-on-rails-a-la-2dconcept-but-with-searchlogic/
# (would have commented but blog.js.hu isn't sending me a registration email)
if params[:_search].present?
filters = {}
if params[:_search] == "true"
searchable_columns.each do |param|
filters["#{param}_like"] = params[param] if params[param].present?
end
Named scopes are great. You can compose huge queries by gluing
parts together.
u = User
u = u.employee if params[:employee]
u = u.unvested if params[:unvested]
... etc.
u.length -- returns the number of users matching the query.
Works great if you specify either parameter. You end up with one of:
" Make \w toggle through the three wrapping modes.
" Add this to your vimrc:
:function ToggleWrap()
: if (&wrap == 1)
: if (&linebreak == 0)
: set linebreak
: else
: set nowrap
: endif
My attempt (bad):
function s:FixWhitespace() range
for lineno in range(a:firstline, a:lastline)
call setline(lineno, substitute(getline(lineno), '\s\+$', '', ''))
endfor
endfunction
" Run :FixWhitespace to remove end of line white space.
command! -range=% FixWhitespace silent! <line1>,<line2>call <SID>FixWhitespace
~/sc2/sproutcore20$ cat .git/HEAD
a1564cd5a554f14f451c83671e3084be0cf54e16
~/sc2/sproutcore20$ git status
# Not currently on any branch.
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
@bronson
bronson / gist:1040671
Created June 22, 2011 17:52
git checkout v2.0.beta.1 && diff -ub sproutcore-2.0.beta.1.js tmp/sproutcore.js
--- sproutcore-2.0.beta.1.js 2011-06-22 10:48:40.000000000 -0700
+++ /home/bronson/sc2/sproutcore20/tmp/sproutcore.js 2011-06-22 10:45:02.000000000 -0700
@@ -2303,839 +2303,629 @@
-var USE_ACCESSORS = SC.USE_ACCESSORS;
-var GUID_KEY = SC.GUID_KEY;
-var META_KEY = SC.META_KEY;
-var meta = SC.meta;
~/sc2/sproutcore20$ git describe --tags
v2.0.beta.1
~/sc2/sproutcore20$ git status
# Not currently on any branch.
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: packages/sproutcore-metal/lib/watching.js
#
@bronson
bronson / gist:1043190
Created June 23, 2011 18:24
Listing Git tags by date
Why does it have to be this hard?
$ git for-each-ref --sort='*authordate' --format='%(tag)%09%(*authordate)' refs/tags
0.2 Wed Oct 27 22:48:10 2010 -0700
0.3 Fri Oct 29 13:06:48 2010 -0700
0.3.1 Sat Oct 30 13:00:42 2010 -0700
0.4.0 Sun Mar 6 18:10:43 2011 -0800
http://nickol.as/post/5838704298/git-tags-by-date