Skip to content

Instantly share code, notes, and snippets.

View vargheseraphy's full-sized avatar

Raphy Varghese vargheseraphy

View GitHub Profile
@vargheseraphy
vargheseraphy / dir_glob_File_basename.rb
Created January 30, 2015 07:00
Dir.glob - File.basename
Dir.glob(“#{dir_path}/*").map{|x| File.basename(x, '.xlsx') }
@vargheseraphy
vargheseraphy / map_flaten.js
Created January 30, 2015 07:03
Lodash code to map flatten and get values
var _ = require('lodash');
results_2009 = [
{ ap:42, inc:33, bjp:0, trs:2, tdp:6, others:1 },
{ ar:2, inc:2, bjp:0, others:0 },
{ as:14, inc:7, bjp:4, others:3 }
];
var result_1 = _.map( results_2009 , function (result) { return _.values(result); });
var result_2 = _.flatten(_.map( results_2009 , function (result) { return _.values(result); }));
console.log("result_1",'\n', result_1);
@vargheseraphy
vargheseraphy / prametarize.rb
Created January 30, 2015 07:09
Ruby script to Parameterize the the string
require 'rubygems'
require 'active_support/all'
restaurants = [ "name 1",
"Karachi's",
"Kai D",
"Kaar- on ()",
"KaracDarbar",
]
@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')
@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 / pdf_compreion
Created January 30, 2015 07:26
Pdf Compression and reduction
qpdf --linearize input.pdf output.pdf
@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 / 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 / learn_ruby_links.rb
Last active August 29, 2015 14:14
Web site links to learn ruby
@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