Skip to content

Instantly share code, notes, and snippets.

View vargheseraphy's full-sized avatar

Raphy Varghese vargheseraphy

View GitHub Profile
@vargheseraphy
vargheseraphy / ruby_on_rails.rb
Created February 18, 2015 04:01
Learn rails and its operations , and rails migration
http://www.tutorialspoint.com/ruby-on-rails/rails-migrations.htm
http://railsguides.net/change-data-in-migrations-like-a-boss/
http://makandracards.com/makandra/15575-how-to-write-complex-migrations-in-rails
@vargheseraphy
vargheseraphy / regex_rm_newline.rb
Last active August 29, 2015 14:15
replace new line from matching word
irb1(main):029:0> "- dredtrnedtdj - uifsdkghdkjghjh ".split(/- /)
=> ["", "dredtrnedtdj ", "uifsdkghdkjghjh "]
irb1(main):031:0> "- dredtrnedtdj - fsjfsgdgdgdffff-gdfjdgjdgdg".split(/- /).compact.reject(&:empty?).each {|t| puts "#{t}"}
dredtrnedtdj
fsjfsgdgdgdffff-gdfjdgjdgdg
=> ["dredtrnedtdj ", "uifsdkghdkjghjh ", "fsjfsgdgdgdffff-gdfjdgjdgdg"]
irb1(main):032:0> "- dredtrnedtdj - fsjfsgdgdgdffff - gdfjdgjdgdg".split(/- /).compact.reject(&:empty?).each {|t| puts "#{t}"}
dredtrnedtdj
@vargheseraphy
vargheseraphy / youtube_download.md
Last active August 29, 2015 14:15
download youtube videos from terminal in linux

Install you tube Downloader from linux terminal

sudo apt-get install youtube-dl youtube-dl

youtube-dl -cit http.....(paste the link) youtube-dl http://www.youtube.com/watch?v=_z-hEyVQDRA

You can also specify other options

@vargheseraphy
vargheseraphy / option parcer
Created February 12, 2015 11:53
ruby docs - option parcer works like a switch that runs the commands too run another command
http://ruby-doc.org/stdlib-2.1.1/libdoc/optparse/rdoc/OptionParser.html
@vargheseraphy
vargheseraphy / learn_ruby_links.rb
Last active August 29, 2015 14:14
Web site links to learn ruby
@vargheseraphy
vargheseraphy / switch_case.rb
Last active August 29, 2015 14:14
switch case in ruby
case a
when 1
puts "Single value"
when 2, 3
puts "One of comma-separated values"
when 4..6
puts "One of 4, 5, 6"
when 7...9
puts "One of 7, 8, but not 9"
when 1..4, 5
@vargheseraphy
vargheseraphy / gist:1774c569ce86471404d1
Last active August 29, 2015 14:14
'> out.txt ' All about redirection - getting file output in different ways in terminal
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html
http://ruby-doc.org/downloads/
@vargheseraphy
vargheseraphy / pdf_compreion
Created January 30, 2015 07:26
Pdf Compression and reduction
qpdf --linearize input.pdf output.pdf
@vargheseraphy
vargheseraphy / parse.rb
Created January 30, 2015 07:14
Run parse.rb to see how the HTML files are parsed.
require 'nokogiri'
Dir.foreach('/Users/geordee/Projects/Data') do |filename|
next if filename == '.' or filename == '..'
puts "Processing #{filename}"
fin = File.open(filename, "r")
html = Nokogiri::HTML(fin)
textarea = html.search("//textarea")
@vargheseraphy
vargheseraphy / organise_files.rb
Created January 30, 2015 07:11
Organize Files in Folders
require 'fileutils'
(0..99).each do |p|
p_name = 'klhcc' + (p * 1000).to_s.rjust(5, '00000')
FileUtils.mkdir_p (0..99).map{ |c| "#{p_name}/klhcc" + (p * 1000 + c * 100).to_s.rjust(5, '00000') }
end
Dir.glob("*.md") do |file|
filename = File.basename(file, '.md')
pf = 'klhcc' + "#{filename.chop.chop.chop}000".rjust(5, '00000')