Skip to content

Instantly share code, notes, and snippets.

View arnab's full-sized avatar

Arnab Deka arnab

View GitHub Profile
@arnab
arnab / octopress_migration.sh
Last active December 11, 2015 10:08
Things I had to do "differently" to migrate site to octopress
# Without setting thr LANG, I'd get errors from Ruby like this:
# YAML Exception reading 2012-09-23-state-of-e-commerce-in-india.md: invalid byte sequence in US-ASCII
# /Users/arnabdeka/Dropbox/websites/arnab.github.com/plugins/backtick_code_block.rb:13:in `gsub': invalid byte sequence in US-ASCII (ArgumentError)
# from /Users/arnabdeka/Dropbox/websites/arnab.github.com/plugins/backtick_code_block.rb:13:in `render_code_block'
# ...
# I got the idea while reading this rubygems issue: https://github.com/rubygems/rubygems/issues/314
export LANG=en_US.utf-8
@arnab
arnab / dynamic-fonts.el
Created September 24, 2012 04:08
Dynamically adjust fonts in emacs based on screen resolution (Retina vs. Thunderbolt)
;; Gist-ed from in https://github.com/arnab/emacs-starter-kit
(defun fontify-frame (frame)
(interactive)
(if window-system
(progn
(if (> (x-display-pixel-width) 2000)
(set-frame-parameter frame 'font "Inconsolata 19") ;; Cinema Display
(set-frame-parameter frame 'font "Inconsolata 16")))))
@arnab
arnab / controller.rb
Last active April 6, 2021 15:02
Allow & test CORS requests in Rails
before_filter: allow_cors_requests
def allow_cors
headers["Access-Control-Allow-Origin"] = "*"
headers["Access-Control-Allow-Methods"] = %w{GET POST PUT DELETE}.join(",")
headers["Access-Control-Allow-Headers"] = %w{Origin Accept Content-Type X-Requested-With X-CSRF-Token}.join(",")
head(:ok) if request.request_method == "OPTIONS"
# or, render text: ''
# if that's more your style
end
@arnab
arnab / open_last_capybara_page.sh
Created June 27, 2012 06:41
Capybara's launchy integration, without installing the launchy gem
# From inside a Rails root directory
# After you call save_and_open_page in Capybara (and you don't have or want launchy)
open -a "Google Chrome" "tmp/capybara/"`ls -tr tmp/capybara/ | head -2 | tail -1`
@arnab
arnab / setup.sh
Created June 11, 2012 10:49
Set up Rails 3.2 with Rspec and Cucumber
# Works with Rails 3.2.x (and this keeps changing due to the large amounts of gems and their author's philosophies differing all the time)
# 1. Create new Rails app
rails new <thing> --skip-testunit
# 2. Add the following to Gemfile:
group :development, :test do
gem 'rspec-rails'
gem 'cucumber-rails', :require => false
@arnab
arnab / get-emacs-starter-kit.sh
Created June 3, 2012 10:29
Emacs setup steps (for GNU Emacs with Clojure and CommonLisp). See http://www.arnab-deka.com/notes/emacs-setup/
mv ~/.emacs.d ~/.emacs.d.bak
cd ~/.emacs.d
git clone <your-clone-of-esk>
@arnab
arnab / .travis.yml
Created March 25, 2012 20:11
set up test db before running tests in travis.ci
before_script: "bundle exec rake db:migrate"
@arnab
arnab / show_available_errors.rb
Created February 23, 2012 17:29
Show available errors in a Ruby environment (so you know to raise the right error)
# From http://weblog.jamisbuck.org/2007/3/7/raising-the-right-exception
exceptions = []
tree = {}
ObjectSpace.each_object(Class) do |cls|
next unless cls.ancestors.include? Exception
next if exceptions.include? cls
next if cls.superclass == SystemCallError # avoid dumping Errno's
exceptions << cls
cls.ancestors.delete_if {|e| [Object, Kernel].include? e }.reverse.inject(tree) {|memo,cls| memo[cls] ||= {}}
def some_method(other_method, args)
puts "before"
other_method.call args
puts "after"
end
def other_method(stuff)
puts "other_method called with #{stuff.inspect}"
end
@arnab
arnab / .tmux.conf
Created January 25, 2012 20:23
My dotfiles
# set-option -g prefix C-a
bind-key C-b last-window
unbind % # Remove default binding since we’re replacing
bind | split-window -h
bind - split-window -v
# Set status bar
set -g status-bg black
set -g status-fg white