As I was working on my open source page, I got tired of copying
and pasting the names of the pull requests and adding the link and so on. I
wanted to generate them dynamically, so I whipped up a quick script to do just
that.
I decided I wanted to have a YAML file which had project paths as keys, and
pull request numbers as entries, which could later store the pull request
titles. I ended up with a file like this:
contribs.yml
12345678910
---brentd/gitploy:"1":"2":philc/vimium:"216":cucumber/aruba:"17":"19":# and so on...
Now I wanted to take that file, fetch the title for each pull request and write
the changes back to the file. Really simple to do thanks to the awesome GitHub
API and the Octokit gem:
contribs.rb Step 1 - Update YAML
12345678910111213141516171819202122
require'yaml'require'octokit'YAML_FILE='contribs.yml'y=YAML.load(File.read(YAML_FILE))# I didn't enter them alphabetically, but I want them to berepos=y.keys.sortrepos.eachdo|repo|y[repo].each_pairdo|issue,title|# Only fetch the title if we need toiftitle.nil?y[repo][issue]=Octokit.pull(repo,issue).titleendendend# Write back any changesFile.open(YAML_FILE,'w')do|f|f.putsy.to_yamlend
Now that we’ve got projects, pull request numbers and pull request titles, we can update
the blog page:
When Delicious originally shut down, Chris Heald
whipped up a site called 1r7 to pick up its slack. I used it
for a while, but recently discovered Pinboard and wanted
to move over my bookmarks from 1r7. The bad news was that 1r7’s export feature
was throwing a 500 error for me, but the good news was that between 1r7’s
semantic markup and Pinboard’s API, it was crazy simple to write a quick script
to transfer them.
1234567891011121314151617181920212223242526272829
#!/usr/bin/env rubyrequire'cgi'require'nokogiri'api_base="https://user:pass@api.pinboard.in/v1/posts/add"# Pre-assumes that you've exported each HTML page of your 1r7 bookmarks to# "1r7p1.html", "1r7p2.html", "1r7p3.html", etc.1.upto(2)do|page|doc=Nokogiri::HTML(File.read("1r7p#{page}.html"))# Extracts bookmark data; note that '1r7' is added to each bookmark's tags# for easier filtering on Pinboarddoc.css('#content li').eachdo|li|args={url:li.at_css('h1 a')['href'],description:li.at_css('h1 a').content,extended:li.search('q').text.strip,tags:(li.css('span.tags span.tag a').collect(&:content)<<'1r7').join(' '),dt:li.at_css('time')['datetime']}# Map our arguments to a query stringq="?"+args.map{|k,v|"#{k}=#{CGI::escape(v)}"}.join('&')`curl "#{api_base}#{q}"`endend
Padrino as a framework is an interesting middle
ground between Rails and Sinatra. However, it breaks from the norm in that it
doesn’t have a traditional Rakefile, opting instead to pass everything through
its padrino command (e.g., padrino rake console). Ordinarily this isn’t a
problem, but it slightly conflicts with the excellent
whenever gem for managing crontabs on a
production server, since whenever’s default rake job type assumes there’s a
traditional Rakefile.
Luckily whenever offers a simple solution by defining a custom job_type:
meta_search lets you perform advanced
queries on your ActiveRecord models, and
Formtastic helps in building
semantic forms quickly and easily.
Today I had need to build an advanced search form that would let the user
define a search where an attribute was between two values. For example,
finding users whose age is between 20 and 30.
MetaSearch defines the multiparameter_field form helper method, but getting
that helper to work with Formtastic required some doing:
First, define the :between where as described in the README:
Today I had need to alphabetize a block of code in Vim, but on each line there
was text which I didn’t want to be part of the sort. An example describes it
best:
Currently the lines are sorted numerically. I needed the lines to be sorted
alphabetically based on the content of the comments (the stuff after the #).
Vim made this stupid-easy:
I’m in the process of upgrading a Rails 2.3.8 app to Rails 3, and part of that
process involved upgrading to RSpec2. I made use of
Shoulda, mostly in my controller
tests, and I ran into a frustrating issue that hopefully I can prevent for
other people with this post.
A simple example controller spec looked like this:
Running this spec with RSpec2 generated this error:
12345678910111213141516171819202122
Failures:
1) AchievementsController GET index
Failure/Error: it { should respond_with(:success) }
undefined method `response_code' for nil:NilClass
# gems/activesupport-3.0.0/lib/active_support/whiny_nil.rb:48:in `method_missing'
# (path)shoulda/lib/shoulda/action_controller/matchers/respond_with_matcher.rb:57:in `response_code'
# (path)shoulda/lib/shoulda/action_controller/matchers/respond_with_matcher.rb:48:in `correct_status_code?'
# (path)shoulda/lib/shoulda/action_controller/matchers/respond_with_matcher.rb:30:in `matches?'
# ./spec/controllers/achievements_controller_spec.rb:12
# gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `inject'
2) AchievementsController GET index
Failure/Error: it { should assign_to(:achievements).with_kind_of(Array) }
Expected action to assign a value for @achievements
# ./spec/controllers/achievements_controller_spec.rb:13
# gems/ree-1.8.7-2010.02@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `inject'
3) AchievementsController GET index
Failure/Error: it { should assign_to(:members).with_kind_of(Array) }
Expected action to assign a value for @members
# ./spec/controllers/achievements_controller_spec.rb:14
# gems/ree-1.8.7-2010.02@rails3/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `inject'
It makes perfect sense in retrospect, but it’s a little frustrating that in
order to find this solution, I had to look through Shoulda’s commit log for a
mention of rspec2, which noted a change to its Cucumber features, which
included this subject line.