Posts

Making a http/https post request under a proxy

Here is my post on how to make a https call. http://srikanthjeeva.blogspot.in/2010/06/making-httphttps-post-request.html Spent a long time in figuring out how to send a https request under a proxy Here is how it is, require 'net/http' require 'net/https' require 'uri' uri  = URI('https://IP/api/V1/USERS') proxy_class = Net::HTTP::Proxy(PROXY_ADDRESS, PROXY_PORT, USERNAME, PASSWORD) proxy_class.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) { |http|   request = Net::HTTP::Get.new uri.request_uri   response = http.request request   puts response.body } Hope this helps. Thanks!
Image
Ruby Conference Pune, India - March 24, 25 - 2012

Caching in Rails

Rails has wonderful inbuilt caching methods. This is how i implemented caching for a particular action.   Requirement : Cache a page for 12 hours. After 12 hrs Caching must expire.   before_filter :clear_cache   caches_action :index, :layout => false def index       #code     # Write expiry time to cache (12 hours)     Rails.cache.write('expiry_time', Time.now + 12.hours) end def clear_cache     #Fetch time from cache and check with current time     t = Rails.cache.fetch('expiry_time') || Time.now     t = Time.parse(t) if t.is_a?(String)     # Expire action if current time > Cached time     expire_action :action => :index if Time.now > t  end Thanks!

Roles implemented with easy_roles plugin

Plugin git repo : https://github.com/platform45/easy_roles     Step 1 : Install Plugin script/plugin install git://github.com/platform45/easy_roles.git Step 2 : Generate migration to create column called roles in user's table rails g easy_roles user roles   Step 3 : Run. rake db:migrate to run the migration   Step 4 : Add this line to the user's model   class User < ActiveRecord::Base easy_roles :roles end Add users role, remove, check role as follows. @user = User.first  @user.add_role 'admin'  @user.is_admin?  => true      @user.has_role? 'admin'  => true    @user.is_awesome?  => false    @user.add_role 'awesome'    @user.is_awesome?  => true    @user.remove_role 'admin'    @user.is_admin?  => false 

How to fix Unrecognized command line argument: 'package'

>> rvm package install zlib ERROR: Unrecognized command line argument: 'package' ( see: 'rvm usage' ) The keyword 'package' is renamed to 'pkg' Try, >> rvm pkg install zlib Njjoy :)

How to fix 'make' is not recognized as an internal or external command

Hi, I have got this below error. $ gem install rhodes-3.1.0.gem -l Building native extensions.  This could take a while... ERROR:  Error installing rhodes-3.1.0.gem:         ERROR: Failed to build gem native extension. c:/InstantRhodes/ruby/bin/ruby.exe extconf.rb make 'make' is not recognized as an internal or external command, operable program or batch file. Gem files will remain installed in c:/InstantRhodes/ruby/lib/ruby/gems/1.8/gems/ rhodes-3.1.0 for inspection. Results logged to c:/InstantRhodes/ruby/lib/ruby/gems/1.8/gems/rhodes-3.1.0/ext/ gem_make.out Here is the Fix: install Devkit for windows by following the steps, https://github.com/oneclick/rubyinstaller/wiki/development-kit -- Srikanth

Rhodes + Blackberry + Fixing error + No such file or directory Simulator

  Hi, I have got this error No such file or directory 'Simulator' ltadmin@LT008029 ~/projects/SocialTango_Mobile (master) $ rake run:bb rake/rdoctask is deprecated.  Use rdoc/task instead (in RDoc 2.4.2+) $use_sqlite : false rake aborted! No such file or directory - C:/bb/5.0.0.621_9650/simulator This is how to Fix this, Fix 1. Check if you have installed the Blackberry JDE. If you have installed Blackberry JDE there will be a simulator folder and MDS folder inside the installed directory. (In case if you have not installed JDE, here is where you need to download http://us.blackberry.com/developers/javaappdev/javadevenv.jsp ) Fix 2. If you have installed JDE and got the error. Go to Rhodes installation path and find the rhobuild.yml. In my system the path is, C:\InstantRhodes\ruby\lib\ruby\gems\1.8\gems\rhodes-3.0.2\rhobuild.yml  check if this paths are correct in rhobuild.yml:     6.0:       jde: C:/Program Files/Research In ...