Skip to main content

Posts

Showing posts from 2015

Adding code to Rails projects other than MVC

I wanted to have development code separate from the M V C of the rails code so I added a folder lib/rubyscripts Then in config/application.rb, added this line to load the code there automatically config.autoload_paths << Rails .root.join( " lib/rubyscripts " ) After this, I can access code from this area in my controllers etc by using require "class_name" What is funny about this setup though is that, unlike in the controllers (where I can just use require "class_name" ) I still have to use the relative location rubyscripts/class_name in my spec files when referring to this code, don't exactly know why! For example, spec/lib/rubyscripts/count_finder_spec.rb @@ -0,0 +1,14 @@ + require " spec_helper " + require " rubyscripts/countFinder " + + # Test for lib/rubyscripts/count_finder.rb + + RSpec .describe " CountFinder " do + it " calculates counts " do + cc = Cou

Track Twitter feeds live in your console with Ruby, Rake and Awesome print

Tools used   Twitter streaming api in Ruby : https://github.com/tweetstream/tweetstream    Rake (I am using this in a Rails application but you can use just ruby/rake)   Awesome print Ruby Gem (prints objects in a nice format into standard out): https://github.com/michaeldv/awesome_print  Sign up for a Twitter app at apps.twitter.com to get your auth keys to use in the code. Setup ruby, then install the awesome_print gem and tweetstream gem gem install tweetstream gem install awesome_print or if using Rails, add to your Gemfile gem 'awesome_print' gem 'tweetstream' then run bundle install If you run this task as rake tweets:tweet1, you can live track tweets of your choosing on your console, sweet. See this gist I posted with the tracker code, very very simple, try it out! https://gist.github.com/binodpanta/d577b24bb776a99a43aa