Skip to content

Instantly share code, notes, and snippets.

@squarism
squarism / fav_gems.sh
Created September 10, 2012 20:15
Rubygem favorites
# here's my latest gem install-fest appropos of nothing
# might give you ideas what gems are interesting (self plug included in there)
gem install rspec rails nokogiri mysql2
gem install eventmachine watchr rev guard autotest
gem install mongoid wirble hirb pry
gem install autotest-rails-pure
gem install autotest-standalone
@squarism
squarism / one_line_guard.rb
Created September 14, 2012 01:51
One line guard with watchr
watchr -e 'watch("walrus.*\.rb") {|m| system("clear && rspec -c #{m};") }'
@squarism
squarism / update_all_the_things.rb
Created October 24, 2012 02:15
Update All Git Vendor Repositories
#!/usr/bin/env ruby
# UPDATE ALL THE THINGS!
# go into each all the git projects and do a `git pull`
# this is mainly used to update apps which use git to deliver updates
# for example, rbenv & vim plugins
# change this here thing-o below. use an asterisk glob for a bunch of submodules.
projects = %w(
@squarism
squarism / see_python_through_ruby.py
Created October 25, 2012 17:05
This is what Python looks like to Ruby dudes
why(do(I(have.to()))):
call(functions(in.different()))
ways()
class NerdRage(selfselfselfself):
def _________init___________:
i_hate_underscores_in_methods(selfselfself)
if _________name__________ == "_______main_______":
this_is_a_cool_trick_but_underscores = "sad panda"
@squarism
squarism / see_ruby_through_python.rb
Created October 25, 2012 17:09
This is what Ruby looks like to Python dudes
list = [1,2,3] # we're cool here, but it's called a list, not an array
list.each.do.what.in.the.hell{}||{} do each ||is all||| this magic that goes right?
# do something in one line, i don't know what a multi-line lambda is, that's crazy
end end end end end endendendend
eend end
end
end
@squarism
squarism / SeeJavaThroughRuby.java
Created October 25, 2012 17:17
This is what Java looks like to Ruby dudes
import *.util**.;;;;
import everything.anyway.**.*;;;;;
import com.why.is.my.import.a.web.address.backwards.***;;;;;;
import this.goes.on.forever.*;
@/* documentation method main -
* this @should go in a README.md on
* GitHub but these @symbols everywhere are cool too
* compiling my documentation is totally cool with me
****//////@@@@
@squarism
squarism / pry_pollution.rb
Last active December 10, 2015 01:38
Why does this happen?
# In some situations, methods on objects in irb and pry really aren't there.
# Fire up a rails app in pry. Actually, in my case this was a CLI app.
# It happens in pry and irb. In rails and outside of rails.
# I think the key is the where statement.
>> rows = User.where('email is not null')
# hit [tab] [tab] after typing 'path' as an example
>> rows.first.path
@squarism
squarism / xml_to_hash_example.rb
Last active December 14, 2015 14:48
xml to hash real easy
# how can we quickly get to a Hash object from XML?
# what's the disadvantages? what do we throw away?
# maybe sometimes we want to use nokogiri's xpath and other API methods ...
require 'nori'
parser = Nori.new(
:parser => :nokogiri,
:convert_tags_to => lambda { |tag| tag.snakecase.to_sym }
)
@squarism
squarism / delete_ruby_index.rb
Created March 23, 2013 18:58
Delete elements from a ruby array based on index
# I can't believe this works this elegantly.
a = [1,2,3,1,3,3,7]
# => [1, 2, 3, 1, 3, 3, 7]
a.reject.with_index {|element, i| i < 3}
# => [1, 3, 3, 7]
@squarism
squarism / redis_vs_mysql.txt
Last active December 15, 2015 08:59
Please don't read too much into this. This is not a benchmark! This is a load test on a particular use case. If I were to use both for an ecommerce app, how would I do it? How fast is it?
---------------------------------------------------------------------------------------------------
Summary
---------------------------------------------------------------------------------------------------
(PL = pipelined redis operation)
Loading one million random names (full names) like John Smith, Patty Gerbee Sr)
MySQL: 06:05
Redis: 02:45
Redis C ext 01:32
Redis pipelined: 00:56