Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Arup Rakshit aruprakshit

🏠
Working from home
Block or report user

Report or block aruprakshit

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@aruprakshit
aruprakshit / CORP.rb
Last active Aug 29, 2015
Chain-of-responsibility pattern in Ruby
View CORP.rb
module PurchasePower
BASE = 500
private
attr_accessor :successor
end
class Manager
include PurchasePower
@aruprakshit
aruprakshit / document.rb
Created Feb 11, 2015
difference between Nokogiri::HTML::DocumentFragment and Nokogiri::HTML::Document
View document.rb
require 'nokogiri'
doc = Nokogiri::HTML::Document.parse <<-html
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
View visitor_pattern_example.rb
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 Aug 29, 2015
Creating a method which has the same name as its class name..like Integer(), Array() etc.
View custom_klass.rb
module Kernel
module_function
def CustomClass()
CustomKlass.new
end
end
class CustomKlass
end
View encoding-line-break-test.rb
#!/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/)
View 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
View delete-heroku-apps.sh
for app in $(heroku apps); do heroku apps:destroy --app $app --confirm $app; done
View 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.

View .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
View reset_primary_key.md
$ ActiveRecord::Base.connection.reset_pk_sequence!('table_name')

If you need the table names:

$ ActiveRecord::Base.connection.tables
=> ["accounts", "assets", ...]
You can’t perform that action at this time.