Monthly Archives: June 2011

flickr with rails3

rails new flickr_sample cd flickr_sample In your gemfile gem ‘flickraw’ bundle install ~ rails g controller photos In app/controller/photos_controller.rb class PhotosController < ApplicationController require ‘flickraw’ def index render end def show FlickRaw.api_key=”YOUR FLICKR API KEY” FlickRaw.shared_secret=”YOUR FLICKR SECRET” url=params[:url] info … Continue reading

Posted in Uncategorized | Leave a comment

embed youtube video in rails application

rails new youtube_sample cd youtube_sample rails g controller videos rake db:create In your Gemfile gem ‘youtube-g’ bundle install ~ app/controller/videos_controller.rb class VideosController < ApplicationController require ‘youtube_g’ def index render end def show url=params[:url] @embed_video={} client=YouTubeG::Client.new video=client.video_by(url.scan(/v=(.*)[&|?]*/).to_s.split(‘&’)[0]) rescue nil @embed_video[“video”]=video ? … Continue reading

Posted in Uncategorized | 1 Comment

Break string after particular length

test_string=”rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr” test_string.split(”).in_groups_of(10).map{|x| x.join}.join(“\n”) run it in console. or,try the below method def wrap_text(txt, col = 40) unless txt.nil? txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/, “\\1\\3\n”) end end puts wrap_text(‘fdgfdgfdgdfgdfgdfgfdgdfgfdgdfgdfgfd’,10)

Posted in Uncategorized | Leave a comment

Ruby RegEXp

Alphanumeric => /^[a-zA-Z0-9 ]+$/ String => /^[a-zA-Z ]+$/ IntegerĀ  => /^(\d*)$/ Decimal => /^(\d*)(\.)+(\d+)$/ Url =>/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?/ PositiveInteger =>/(^\d*\.?\d*[1-9]+\d*$)|(^[1-9]+\d*\.\d*$)/ PositiveIntegerIncludingZero =>/(^\d*\.?\d*[0-9]+\d*$)|(^[0-9]+\d*\.\d*$)/ /\\/.match(“string”) to identify escape sequence in a string (i.e “\”)

Posted in Uncategorized | Leave a comment