January 2012
6 posts
Customizing zshrc prompt to have git info in Ruby
I’ve been using Gary B’s dotfiles ever since I saw his PeepCode screencast, especially like his zshrc prompt, which looks like: bin(0min|master?) $ bin - folder name 0 min - time since last commit master - name of current branch ! - there untracked files in the repo. Its pretty helpful since I use terminal a lot, but one problem is the speed when switching to new repos, especially ones not...
Jan 25th
1 tag
Moving away from Singleton pattern for...
Whenever I wanted to stored some config options for a gem, I go with the singleton pattern. Usually this involves creating a class called Config and letting users configure that with configure block. Think I learned that from Mongoid, don’t remember. require 'singleton' module ShinyGem class Config attr_accessor :options include Singleton end class << self def config ...
Jan 23rd
Easy plugin system for your gem in less than 100...
For my OpenAuth2 gem I wanted to let users customize the endpoints and various other options. At first I had a simple configure block, something like: def configure yield self self end Here users could define options, even procs. Unfortunately every OAuth2 provider seem to have its own take on the implementation and needless to say this leads to lot of headaches. Which is why I decided to...
Jan 23rd
Extract out a block into a proc
Say you’ve something like: [1,3,5].map do |x| x + 1 end # => [2,4,6] What if you want to reuse the block? You can use a proc to do that. even_to_odd = proc do |x| x + 1 end Now you can pass in even_to_odd to the method with &. [1,3,5].map(&even_to_odd) # => [2,4,6] What if you don’t have an array, but just a single object and you still...
Jan 13th
Getting rspec's "let" method to work in pry
Backstory: Was writing a google calendar api wrapper gem, since I just worked on a project that required it and also there are no existing gems and very few examples available. Needless to say that led to lot of hair pulling. Guess rubyists don’t care about google api. Anyway, I got a prototype up and running using bdd, and was switching over to pry for manual testing. I use lot of let methods in...
Jan 10th
Disappointed at the state of ruby/oauth2
Just one oauth2 gem with scarse examples. Very few helpful Stackoverflow answers. Don’t even get me started on ruby/google api. No gems, no examples, but plenty of headache. No worries. I’m planning to do something about it very soon.
Jan 10th
December 2011
3 posts
Only goal for 2012
My one goal for 2012 is to be free. I am not slave in a physical sense, I am free to go where I want and do whatever I want for the most part. No master bought me in market or inherited me, yet I feel like one. When I say free I mean freedom from compulsions. Not just obvious ones like browsing too many social media/news sites or watching too many bad sitcoms or buying the latest unnecessary...
Dec 31st
DummyTestPattern made into a gem →
I created a new gem based on last night’s post called dummy_testing_pattern. So far it contains dummies for Stalker and MongoMapper. To use it simply do: require 'dummy_testing_pattern/stalker' require 'dummy_testing_pattern/mongo_mapper' If you want to include all the dummies, simply do: require 'dummy_testing_pattern/all' I recommend using it in your spec_helper.rb. If you notice, the...
Dec 29th
Faster specs with DummyTestingPattern
I’m developing a project for a client that involves a lot of libraries, worse, slow loading libraries that makes doing fast tdd a real pain. One way is to use something like spork, which I do use in Rails, but for a standalone ruby library, it seemed like a overkill, so I decided to use DummyTestingPattern. No, that’s not a real name and yes I just made it up. Btw, I learned this from watching...
Dec 28th
November 2011
2 posts
1 tag
Thoughts, concerns and tribulations this Monday
Code:The Hidden Language of Computer Hardware and Software is by far the best book I’ve read on computer science. It jumps from Braille to Morse code to RAM to Von Neumann. I’ve managed to finish chapters 1-8 with ease, but 9 is a bit confusing (Ha! get it? If you read the book, you’ll see the chapter is titled ‘Bit by Bit by Bit’). I highly recommend it if you want...
Nov 8th
Introducing Less::Social and Less::Tumblr
Two half backed Ruby libraries written in spur of the moment. Less::Social is currently an email digest for HackerNews and Tumblr, while Less::Tumblr is a get only Tumblr api wrapper. It all started when I wrote my last post about a perfect social media client that only updated once/twice every day, so as to avoid addiction to them. Implementing HackerNews api was rather very simple with...
Nov 5th
October 2011
3 posts
Question driven learning
I can never sit still enough to finish a class or read a book cover to cover. Yes this could be attributed to our ever decreasing attention span thanks to 100 word articles and top 10 lists or maybe its just my personality, destined to jump from subject to subject, never finish anything. For a while I did feel bad about this and rightly so. After 2 years of learning to program, all I had to show...
Oct 30th
A perfect social media client →
A similar cycle happens each time I try a new social site: 1. Will signup thinking about all the advantage of networking and connected it brings. 2. First couple weeks will be marked by increasing number of logins. But its okay, I’m learning more things. 3. Soon individual post quality will go down, the social actions “liking”, “reblogging”,...
Oct 30th
Rules
Hello folks! This is my third tumblr. I had to delete the first two because they were way too addictive for me (Good job Tumblr UX folks). In order to avoid the same pitfalls this time around, I made up couple rules: 1. No checking web interface ever! All posts will be via email. All followers posts will be sent to RSS feeder. Apologies if I don’t reply to your comments or reciprocate your...
Oct 30th