Skip to content

Instantly share code, notes, and snippets.

View rohitpaulk's full-sized avatar

Paul Kuruvilla rohitpaulk

View GitHub Profile
@rohitpaulk
rohitpaulk / backgroundpanning.js
Created May 12, 2014 21:14
jQuery Background Panning
$('.panbg').mousemove(function(e){
//Let's find the midpoints of the screen
var midpointX = $(window).width()/2
var midpointY = $(window).height()/2
//Now the pointer's deviation as a percentage.
var mousePosX = ((e.pageX-midpointX)/$(window).width())*100;
var mousePosY = ((e.pageY-midpointY)/$(window).height())*100;
//Let's dilute it by a factor of 40
var xPos = mousePosX/40 + 50;
var yPos = mousePosY/40 + 50;
@rohitpaulk
rohitpaulk / gist:168561a49732604fa6f2
Last active August 29, 2015 14:12
Migration for rocket_tag -> AATO
class ReplaceRocketTagWithAato < ActiveRecord::Migration
def up
# This was created by rocket_tag but not used anywhere.
drop_table :alias_tags
# This is something that AATO has that rocket_tag doesn't.
add_column :tags, :taggings_count, :integer, default: 0
# Populate the taggings_count properly
ActsAsTaggableOn::Tag.reset_column_information
@rohitpaulk
rohitpaulk / counter_cache_test.rb
Last active August 29, 2015 14:17
Rails `counter_cache` test
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
@rohitpaulk
rohitpaulk / main.rb
Created January 31, 2017 04:25
Race condition in Ruby's puts
irb > a = (1..5)
# Printing sequentially
irb > a.map { |x| puts x }
1
2
3
4
5
@rohitpaulk
rohitpaulk / ruby.md
Created June 1, 2017 15:06
Ruby Level-Up

Ruby Level-Up

First and foremost, code style. This is one thing that people look for first, and no matter how well designed your classes are - a misplaced indent is just unacceptable. Ruby doesn’t have a style guide as solid as Python’s PEP8, but the most commonly followed one is https://github.com/bbatsov/ruby-style-guide. Also, checkout Rubocop to automate these style checks as part of your CI process.

Learn to use rdoc (https://github.com/rdoc/rdoc) properly. Get used to viewing the generated HTML documentation for your code. It is important that readers of your code are able to ‘grasp’ the big picture of what your code is about - well-structured comments make that easier. Also, look into http://www.literateprogramming.com/ - Even if you don’t go all the way, a lot of those principles could be useful.

Make sure your Ruby basics are clear - especially important if you discovered Ruby through Rails. I’d recommend ‘The Well-Grounded Rubyist’ from Manning publications.

Get a hold of common web frameworks

@rohitpaulk
rohitpaulk / Simplate.sublime-syntax
Last active June 24, 2017 22:20
Simplate Sublime Syntax File
%YAML 1.2
---
name: Simplate - Python
file_extensions: [spt]
scope: source.spt
contexts:
main:
- match: ""
@rohitpaulk
rohitpaulk / wget_strip_query.rb
Last active July 7, 2017 09:22
Strip Query parameters from wget --page-requisites output
Dir.glob("**/*").each do |filename|
next unless filename.include?("?")
new_filename = filename.split("?").first
puts "Renaming #{filename} to #{new_filename}"
File.rename(filename, new_filename)
end
@rohitpaulk
rohitpaulk / git_clean.sh
Created July 8, 2017 14:02
Delete old merged git branches
git branch --merged | egrep -v "(^\*|master)" | xargs git branch -d
@rohitpaulk
rohitpaulk / filename
Created July 15, 2017 21:45
.gitignore locally for a project
.git/info/exclude
@rohitpaulk
rohitpaulk / tmux.cmd
Created August 6, 2017 08:06
Tmux set current directory to pane path
attach -c "#{pane_current_path}"