This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/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) | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/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 | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |