Skip to content

Instantly share code, notes, and snippets.

View bronson's full-sized avatar

Scott Bronson bronson

  • Santa Cruz, CA
View GitHub Profile
bronson@t500-jaunty:~$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:1c:25:97:40:e0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Memory:fc000000-fc020000
lo Link encap:Local Loopback
# download the command
cd /tmp
wget http://github.com/bronson/git-subtree/raw/6aa0e3e116daafd3292b862555b7a0da81352070/git-subtree
chmod a+x /tmp/git-subtree
# and put another git project as a subtree into myrepo
cd ~/myrepo/
VERBOSE=1 /tmp/git-subtree clone git://blah/subproject.git
# (VERBOSE shows the git commands that it's using)
@bronson
bronson / example.erb
Created October 9, 2009 02:31 — forked from sbr/example.erb
<div class="list">
<ul>
<% @items.each do |item| %>
<li class="<%= item_classes_for_user(item, @current_user) %>">
<%= image_tag "/icons/#{item.state}.png" %>
<span class="name">
<%= item.name %>
</span>
</li>
<% end %>
<div class="list">
<ul>
<% @items.each do |item| %>
<li class="<%= item_classes_for_user(item, @current_user) %>">
<%= image_tag "/icons/#{item.state}.png" %>
<span class="name">
<%= item.name %>
</span>
</li>
<% end %>
# 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