Skip to content

Instantly share code, notes, and snippets.

View Mothirajha's full-sized avatar

Mothirajha Mothirajha

View GitHub Profile
@Mothirajha
Mothirajha / db_migration
Last active August 29, 2015 14:11
Migration from old to new database
-- bundle exec rake db:migrate
-- Level 1
-- Migrating Country
INSERT INTO countries(name)
SELECT DISTINCT(CountryName)
FROM 527433_iec.iec_country;
-- Migrating Branch
@Mothirajha
Mothirajha / mysql
Last active August 29, 2015 14:11
MySQL migrations
Get into organizor database
TRUNCATE countries;
ALTER TABLE countries CHANGE id id INT(11) NOT NULL;
insert into organizor.countries (id, name) select CountryId, CountryName from 527433_iec.iec_country;
ALTER TABLE countries MODIFY id INTEGER NOT NULL AUTO_INCREMENT;
TRUNCATE branches;
ALTER TABLE branches CHANGE id id INT(11) NOT NULL;
insert into organizor.branches (id, name, address_line1, email, country_id) select BranchId, BranchName, Address, Email, country from 527433_iec.iec_branch;
@Mothirajha
Mothirajha / crawler_mp.rb
Last active August 29, 2015 14:10
Get aff_url
require 'mechanize'
sample_url = "www.example.com"
agent = Mechanize.new
page = agent.get sample_url
raw_link = []
@Mothirajha
Mothirajha / Vimrc
Created November 17, 2014 03:28
Vimrc config file using Vundle
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" size of a hard tabstop
set tabstop=2
" size of an indent"
set shiftwidth=2
@Mothirajha
Mothirajha / seo.rb
Last active August 29, 2015 14:08
To get the keyword position of certain domain
require 'mechanize'
url = "https://www.google.co.in/"
agent = Mechanize.new
page = agent.get url
google_form = page.form
google_form['q'] = 'hot deal'
search_page_1 = google_form.submit
search_page_1.uri.to_s
url = "/url?q=http://www.infibeam.com/Hot_Deals/search&sa=U&ei=xOxZVKyuFM6IuwSDs4LgAQ&ved=0CCYQFjAA&usg=AFQjCNFTGXidISz5Op1fDPDkbDTYf9-Nwg"
@Mothirajha
Mothirajha / category_crawler.rb
Last active August 29, 2015 14:08
Generic crawler to get categories...
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open("http://shop.8and9.com/"))
data = []
urls = doc.search('a')
urls.each do |x|
url = x['href']
if !url.nil? and url.match('^\/collections')
data << x
end
@Mothirajha
Mothirajha / table data from sql dump
Created October 16, 2014 09:58
Restoring individual table data from a Postgres dump
sed -n "/^COPY mytable/,/^\\\.$/p" mysqldump.sql > mytable.sql
Steps:
Truncate your existing table.
Import mytable.sql to your database.
psql -U username -d database_name -f mytable.sql
Now, all your mytable data from huge mysqldump.sql is moved to database.
@Mothirajha
Mothirajha / Rake - DB back_up
Created September 26, 2014 08:43
Rack Task for DB BackUp
namespace :backup do
task db: :environment do
if ENV['RAILS_ENV']
file = YAML.load_file("#{Rails.root}/config/database.yml")
db = file[ENV['RAILS_ENV']]
time = Time.now.strftime("%Y%m%d%H%M")
pgdump = "cd && PGPASSWORD=#{db['password']} pg_dump -U #{db['username']} -f #{time}_backup.sql #{db['database']}"
system(pgdump)
else
p "Please provide RAILS_ENV=(development or production or test)"