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 / 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
@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>
class CarElement
def accept(visitor)
raise NotImpelementedError.new
end
end
module Visitable
def accept(visitor)
visitor.visit(self)
end
@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
#!/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 / 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
for app in $(heroku apps); do heroku apps:destroy --app $app --confirm $app; done
@aruprakshit
aruprakshit / rules.md
Last active August 29, 2015 14:10 — forked from henrik/rules.md
  1. Your class can be no longer than 100 lines of code.
  2. Your methods can be no longer than five lines of code.
  3. You can pass no more than four parameters and you can’t just make it one big hash.
  4. When a call comes into your Rails controller, you can only instantiate one object to do whatever it is that needs to be done. And your view can only know about one instance variable.

You can break these rules if you can talk your pair into agreeing with you.

@aruprakshit
aruprakshit / .vimrc
Last active August 29, 2015 14:09 — forked from zxiest/.vimrc
set nocompatible
filetype off
" set runtime path to include vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" Let Vundle manage Vundle
$ ActiveRecord::Base.connection.reset_pk_sequence!('table_name')

If you need the table names:

$ ActiveRecord::Base.connection.tables

=> ["accounts", "assets", ...]