Skip to content

Instantly share code, notes, and snippets.

View aruprakshit's full-sized avatar
🏠
Working from home

Arup Rakshit aruprakshit

🏠
Working from home
View GitHub Profile
@aruprakshit
aruprakshit / db.rake
Last active August 29, 2015 14:13 — forked from hopsoft/db.rake
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
#!/usr/bin/ruby -w
FILE_NAME = "x"
printf "%-20s %p\n%-20s %p\n",
"Default external", Encoding.default_external,
"Default internal", Encoding.default_internal
# p File.instance_methods.grep(/enc|opt/)
@aruprakshit
aruprakshit / custom_klass.rb
Last active August 29, 2015 14:15
Creating a method which has the same name as its class name..like Integer(), Array() etc.
module Kernel
module_function
def CustomClass()
CustomKlass.new
end
end
class CustomKlass
end
class CarElement
def accept(visitor)
raise NotImpelementedError.new
end
end
module Visitable
def accept(visitor)
visitor.visit(self)
end
@aruprakshit
aruprakshit / document.rb
Created February 11, 2015 06:25
difference between Nokogiri::HTML::DocumentFragment and Nokogiri::HTML::Document
require 'nokogiri'
doc = Nokogiri::HTML::Document.parse <<-html
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
@aruprakshit
aruprakshit / CORP.rb
Last active August 29, 2015 14:15
Chain-of-responsibility pattern in Ruby
module PurchasePower
BASE = 500
private
attr_accessor :successor
end
class Manager
include PurchasePower
class PurchaseApprover
# Implements the chain of responsibility pattern. Does not know anything
# about the approval process, merely whether the current handler can approve
# the request, or must pass it to a successor.
attr_reader :successor
def initialize successor
@successor = successor
end
@aruprakshit
aruprakshit / bash_git.md
Last active August 29, 2015 14:15
Git and Bash shell customizations

Get the git-promt.sh script here. Put it somewhere like ~/.git-prompt.sh. If you want to be all CLI about it, you could just run:

curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -o ~/.git-prompt.sh

Now modify your your bash profile (it’s at ~/.bash-profile, in case you’re new to this stuff). Before the part of the file that declares what your prompt will look like (PS1=[...]), load in the script you just downloaded, like so:

# Load in the git branch prompt script.
@aruprakshit
aruprakshit / import.rake
Last active August 29, 2015 14:21
Rake task to import data from text file to Postgresl table.
desc "import task"
task :import, [:username, :password, :dbname, :path] do |t, args|
sh <<-SQL
PGPASSWORD=#{args[:password]} psql --username=#{args[:username]} --dbname=#{args[:dbname]} << EOF
\\copy films from #{args[:path]} (DELIMITER E'\t');
EOF
SQL
end
@aruprakshit
aruprakshit / multiple_ssh_setting.md
Last active August 29, 2015 14:28 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "[email protected]"