Archive for the ‘geekery’ Category

Usdo. Misspellings turn into gem-fu practice

Saturday, November 14th, 2009

Indian Paintbrush
A few weeks ago, during a period of frustration, I found myself repeatedly mistyping ’sudo.’ So, in a fit of silliness I wrote a short script to insult me when I did it, and put it in the path.

Later, I packaged it as a gem, because a) I had never built a gem with an executable and b) gems are a great way to share things.

The end result?

http://github.com/baroquebobcat/usdo

It isn’t particularly smart, but I happen to find it funny. It also showed to me how far gem packaging has come. Gemcutter and Jeweler make building and distributing ruby gems freakishly easy. This is especially awesome in light of the recent announcement that gemcutter is going to be the default gems host(though at rubygems.org)

How I put it together

I ran jeweler to create the default directory structure and added a bin dir to it, for the files I wanted to end up in the path.

$ jeweler usdo
cd usdo
mkdir bin

I put my gist from before in the bin directory, and set up git.

Set up my gem info in my Rakefile

#...
Jeweler::Tasks.new do |gem|
  gem.name = "usdo"
  gem.summary = %Q{adds usdo command to ridicule mispellings of sudo}
  gem.description = %Q{...}
  gem.email = "ndh@baroquebobcat.com"
  gem.homepage = "http://github.com/baroquebobcat/usdo"
  gem.authors = ["Nick Howard"]
end

then did the jeweler gem initialization dance

rake version:write
rake gemspec
rake install

Testing it out:

$ usdo -l
----USDO----
    You mispelled sudo
    You can't do anything, you can't even spell sudo
    are you really sure you want to try running
    'sudo -l'????

Now that was working, to send it up for distribution.

Jeweler is awesome and now has gemcutter support. I followed the jeweler README’s directions on uploading to gemcutter. Which makes pushing your gem as simple as

$ rake gemcutter:release

Awesome.

Check out my code if you want.

I loves me some music geeks

Thursday, November 12th, 2009

I saw OK Go last night at the Canopy Club. The show was a blast. The songs were awesome, fucking loud; there was much kick assery to be had. My favorite moments though, were the silly ones.

Went to ALA in Chicago

Friday, July 24th, 2009

Living with a library science graduate student has its perks.

Not Too Crowded

Two weeks ago I went to Chicago to see the big ALA conference. I came by train, armed with a backpack stuffed with clothes etc. And generally made off with the adventure having.

Friday evening I gathered up all the necessaries I had laid out in the living room the night before and stuffed them in my backpack. I walked to the station, a bit less than mile, through the neighboring neighborhoods.

It was the first time I rode in coach on an American train. It was slower and more cramped than the shinkansen, but felt more train-like with it’s conductors calling out the stations and big diesel engines.

I laughed at the Montana advertisement over the door into the terminal. Something like

- Few People Come Here
+ Few People Come Here

I took a taxi to the hotel. It was a little more complicated than I thought it would be because there were quite a few people on the train–significantly more than there were taxis. Also there were taxi barkers or something trying to get tips from people for helping them get a cab. It was a little crazy.

Saturday Morning 8 am

I snuck in to see Gregory Maguire talk about what he has been doing recently among other things. I wish I had taken notes because I don’t really remember much of it now. Depressing.

Afterwards, Sara and I went into the exhibition hall, fittingly called The Stacks. We looked at children’s books for a while and grabbed some galleys…

Did you know you can get free books at ALA?

Sara eventually went off to some official sessions and left me by myself in the stacks, until lunch.

Initially, I just wandered around. I had this strange suspicion that I would not be able to find an honest to goodness technical software book in the place and I wanted to test that suspicion.(Later I learned that O’Reilly usually shows up, but didn’t this year for some reason)

The reason I wanted to find software books or their lack was that my local public library’s section on software was rather meager and I suspected it had something to do with technical publishers not marketing software books to libraries.

In the end I found a number of technical publishers, but they were mostly peddling their database solutions, and they bring any of their software wares to show off.

Eventually that got boring so I started to talk to the software vendors.

Note: Lunch occurs somewhere in this period.

To summarize:

  • numerous data base vendors
  • ebook peddlers
  • language packages
  • SMS gateway services tailored to libraries
  • And an awkward demo of a set of keyboards intended to facilitate communications between deaf people

Telling people I was not a librarian, but instead a Software Developer sometimes elicited awe or confusion and other times a kind of oh well sort of feeling.

The best bit of the conference for me was the Newbery Caldecott Award Banquet. I shook hands with Neil Gaiman. I was among the 1200. And Sara got her graveyard book signed.

The second best bits were all the shoe conversations:

Shoes | Strange Comment Attractors?

“Whoah, those are crazy shoes.”
“My friend and I were wondering, are those comfortable?”
“Cool Shoes.”

Some Final Links
Integrated Library Systems:
Koha
Evergreen
Ex Libris
Cool Org/Com’s sites
Nolo
NASW

RubyNation Etc

Tuesday, June 16th, 2009

I am back from RubyNation and reapplying my nose to the grindstone, wheel to the asphalt and hands to the keyboard. I am still planning a big summary and commentary post based on my notes, but as I started working on that, I realized it might need more than one night to see to completion.

So, I give you this:

Me
Hyatt Ceiling Pastry and Me in My Hat

Carrot Cake(Thanks Hyatt catering)

Mmm Carrot Cake

And Lys, the cat who is strangely fond of white ceramics.

Lys, Sink and You

Tune in some indeterminate point in the future for a fuller update. Or, you could just read this guy’s take.

Ruby is awesome–lazy scripting

Monday, April 20th, 2009

Sometimes I find myself doing tedious things like trying to grab the dollar amounts from text copied from the web. More and more often I turn to irb for these sort of things. For example, a few minutes ago, when I wanted to analyze my spending habits I copied the data into a file and manipulated it.

I grabbed the lines from the file

irb(main):001:0> lines = File.readlines 'transactions'


And selected those with dollar signs (with a little effort–sometimes I forget whether it is =~ or ~=).

irb(main):002:0> monies = lines.select {|l| l ~=  /\$(.*)/}
SyntaxError: compile error
(irb):2: syntax error, unexpected '='
monies = lines.select {|l| l ~=  /\$(.*)/}
                               ^
	from (irb):2
	from :0
irb(main):003:0> monies = lines.select {|l| l =~  /\$(.*)/}

Then I grabbed the numbers using map.

irb(main):008:0> nums =monies.map {|m| m.sub( /\$(.*)/,$1).to_f}

From there, I could do all sorts of things.

I could sum numbers.

 total =nums.inject(0){|sum,i|sum+i}

I could get the average.

total/nums.length

I could even see how much of the total was due to transactions under $20.

nums.reject {|i|i>20}.inject{|s,i|s+i}

In short, I like ruby.

Ruby in Practice is Good

Thursday, April 16th, 2009

I have been reading Ruby in Practice over the past week or so as you know. Currently, I am on page 114 which talks about using active resource to consume RESTful webservices( you could use RESTClient, but thats another story) and has a box about the ever awesome BlankSlate class.

I haven’t really learned many “whoah, ruby does what?? Sweet” things from it, most of those are behind me. Now, I get more “Whoah, X project really abstracts that annoying thing into a nice interface.” kind of feelings, which are more satisfying in some ways and less in others. I guess what I am saying is that I have grown to know ruby much better over the past six months or so using it at work every day, than the past, uh, five? years. Which is sweet.

But back to the book( I ramble when I feel braindead):

The things I have learned from reading this book remind me of ruby itself. It has glued together various bits of ruby that I know, in the same way you can use ruby to glue together other technologies. Most of my ruby smarts have been picked up through hacking at things and reading blog posts by knowledgeable people, but that sometimes leaves some gaps in my knowledge. This book has helped me to tie some of the things I have learned together(w00t Hebbian Learning).

For instance, spec tasks

While I know that rspec has a set of extensions for rake, I had not used them outside rails, in fact in the project I was working on I just wrote the following.

task :spec do
  sh "spec --colour --reverse #{FileList['spec/**/*_spec.rb']}"
end

The problem with this is that when any of the specs fail, I get a huge trace from the ran shell script that I have to scroll past before I can see the failed specs.

But, if I included the spec tasks I could do stuff more like this.

require 'spec/rake/spectask'
Spec::Rake::SpecTask.new('spec') do |task|
  task.spec_files =FileList['spec/**/*_spec.rb']
  task.spec_opts = ['--colour','--reverse']
end

Now things work like they do when you generate the tasks from within rails. I had read the lib/tasks/rspec.rake file when I was looking over the generated code in one of my rails apps, but it was a little too complicated to grok easily.

The other things I am looking for are cool projects that I should be more aware of. Sometimes, they are only mentioned but that doesn’t mean they are not awesome. Some that I would like to play with include:

  • Chronic a date string parser that tries to be able to handle stuff like: “next tuesday” and “summer”
  • FasterCSV I saw this at Mountain West Ruby Conf and made a mental note to read it at some point(so much for mental notes)
  • Heckle runs tests. Breaks your code. Sees if the tests fail like they should.

Later.

Merb in Action: Ch 1 Thoughts

Wednesday, April 8th, 2009

Last night I read the first chapter of what will become Rails 3 in Action. So far, I really am enjoying it.

One of the things that frustrates me the most in my own projects is this feeling that things need to be big and get abstracted before they can be useful. I guess it might be a hold over from being a student and wanting to over achieve, or maybe just the classic problem of the hobbyist who tinkers but never manages to really build anything.

It is a gumption trap, to use a Zen and the Art of Motorcycle Maintenance-ism; a thought that sort of stalls my work on a project.

“How will this be useful to anybody?”

“How can I get this to a usable state?”

I think I am getting better at this problem, but sometimes I feel like I have this irresistible urge to over-architect things that gets me into trouble.

What this has to do with Merb in Action?

Well, the thing I thought was really cool was where the authors linked to the pastie that started it all, clocking in at ~120 lines.

I look at that and I think two things.

  1. I usually over think things
  2. I can do this.

The beginning of merb is completely grokable. It reminds me that something doesn’t need to be fully designed. It just needs to be useful enough.

or you could just say:

YAGNI

You Ain’t Gonna Need It.

YAGNI is part of the reason why I have been trying to use BDD in a more disciplined way. By using the Feature->Spec->Implementation workflow, there is less temptation to add neat features on the backend that are never used. I have worked on a number of projects where I ended up writing more code than I needed, than was used.

Writing from the outside in helps to manage that some. After all “no code is faster than no code.”

New Books

Tuesday, April 7th, 2009

I just ordered Ruby in Practice and Rails 3 in Action from Manning(they had a one day only 45% off promo).

The Rails 3 book won’t actually be coming out for a while, but in what I think is an ingenious publishing move, people who preorder can look at drafts of chapters as the book is worked on. It reminds me a little of how Lawrence Lessig is doing the next edition of his books. Except of course totally different.

The thing that makes them similar is the added participation of future readers. It isn’t that this is a new idea. People have been soliciting comments on publications for as long as they have been around. Technology just changes the timescale and the scale of the projects.

Anyway, cool.

Right now, I have Ruby in Practice and through the fourth chapter of Merb–Rails 3 in Action. More later.

Sweet.

Mountain West Ruby Conf Day 2

Monday, March 16th, 2009

After yesterday, I have a lot of grokking to do. And, some projects to start.

The talks, like the day before were great. And having the opportunity to talk with so many people about what they do with ruby was enlightening.

I wanted to write up my thoughts about yesterday, but they haven’t really congealed yet.

Short summary:

  • Ruby is awesome.(of course)
  • I need to be more aware of my metaworkflow
  • Rhodes looks really slick.
  • Adhearsion would be fun to build something with(eg a podcast engine)
  • Destroy is a funny word to users(rails)
  • Of the bicycle gears of software development,cucumber is the outmost one
  • Suite.add(test) if test.value > test.cost
  • be extremely pedantic when you first start trying to use a new methodology–even if it sucks(in the ‘man, why all this typing’ sort of suckage you know makes you want to be lazy).
  • don’t confuse concise with terse.
  • maybe I should try to make a theramin sim with the wiimote
  • energy not time is the most precious resource

Silly Simple Twitter Search App with Javascript

Friday, March 13th, 2009

I’ve been meaning to spend some time playing with twitter’s API. So, I decided to build a really simple js app on top of the search api.

Essentially, I want to show a list of statuses from a search, say ‘baroquebobcat’ and do it in the least amount of effort possible.

There are more complicated ways to do it, but I wanted to see how easy it was.

First, I thought I would do what the API docs suggest and poke around with curl.

Since all I want is to do a search, like you would using a browser, why not try that, only with json, for extra awesomeness.

$ curl 'http://search.twitter.com/search.json?q=baroquebobcat'

Running that gets me a long string of json:

{"results":[{"text":"Talkin' 'bout sandwiches", ...

Breaking that down with structurally looks like

{
  "results": [
    { "text":"Talkin' 'bout sandwiches",
      "to_user_id":null,
      "from_user":"baroquebobcat",
      "id":1307603293,
      "from_user_id":125785,
      "iso_language_code":"en",
      "source":"<a href="http:\/\/twitter.com\/">web<\/a>",
      "profile_image_url":"http:\/\/s3.amazonaws.com\/twitter_production\/profile_images\/79555083\/face02_normal.jpg",
      "created_at":"Tue, 10 Mar 2009 22:04:12 +0000"
    },
    ...
  ],
  "since_id":0,
  "max_id":1307851898,
  "refresh_url":"?since_id=1307851898&q=baroquebobcat",
  "results_per_page":15,
  "next_page":"?page=2&max_id=1307851898&q=baroquebobcat",
  "completed_in":0.033281,
  "page":1,
  "query":"baroquebobcat"
}

Results contains the statuses that match the search, the other 1st level attributes are metadata about the search.

For my silly simple js app, all I really need is a subset of this vertiable bevy of infos.

I am not even going to bother with the search metadata and am going to throw away most of the statuses data too.

For now, I only care about the text, and the user who tweeted it.

{
  "results": [
    { "text":"Talkin' 'bout sandwiches",
      "from_user":"baroquebobcat"
    },
    ...
  ]
}

So, I have this list and a url to get stuff. How does that go into the javascript?

we need a callback. Because of all that cross site scripting etc stuff, you can’t do ajax requests for data like this
(well you can as long as you proxy it through your host somehow like this guy ).
So, the way to get all this stuff so it can be executable is to add a callback parameter to the request. It wraps the json with a function call so you can use it in a script tag.

$ curl 'http://search.twitter.com/search.json?q=baroquebobcat&callback=awesome'
awesome({"results":[{"text":"Talkin' 'bout sandwiches", ...})

so in html file can do


and awesome will be executed with the response from the search.


cut to the chase

So, we need a callback.

because we lack imagination, lets call it twitter_callback.


 
 
 



Pretty cool, huh?

What that does is define a call back that just writes each status in the search with the user’s name: their tweet on each line.

Actually, that is a bit boring.

All we have is the list, and it’s not very portable but it demonstrates how it works.

You could make it more robust by using a javascript function to insert the script tag, thereby allowing you to dynamically set the query.

There are problems with using js to do all the work here. It can be slower and it also can be a security risk–if you don’t trust twitter.

Laters.