Skip to content

Instantly share code, notes, and snippets.

View rohitpaulk's full-sized avatar

Paul Kuruvilla rohitpaulk

View GitHub Profile
@rohitpaulk
rohitpaulk / named_struct.rb
Last active September 8, 2019 19:33
NamedStruct
class NamedStruct < Struct
# Allows initialization via keyword arguments. By default, Ruby
# only allows positional arguments.
def initialize(**kwargs)
super(*members.map{|k| kwargs[k] })
end
end
@rohitpaulk
rohitpaulk / struct_no_keyword.rb
Last active October 8, 2017 17:30
Ruby's Struct doesn't allow keyword arguments
Point = Struct.new(:x, :y)
# Allowed by default: positional arguments
p = Point.new(1, 2)
# What I wish was allowed: keyword arguments
p = Point.new(x: 1, y: 2)
@rohitpaulk
rohitpaulk / struct.rb
Created October 8, 2017 17:21
Ruby's Struct
# Create a new class from Struct
Customer = Struct.new(:name, :address)
#=> Customer
Customer.new("Dave", "123 Main")
#=> #<struct Customer name="Dave", address="123 Main">
execute pathogen#infect()
syntax enable
filetype plugin indent on
" Set line numbers on
set number
" Solarized https://github.com/altercation/vim-colors-solarized
set background=dark
colorscheme solarized
@rohitpaulk
rohitpaulk / tmux.cmd
Created August 6, 2017 08:06
Tmux set current directory to pane path
attach -c "#{pane_current_path}"
@rohitpaulk
rohitpaulk / filename
Created July 15, 2017 21:45
.gitignore locally for a project
.git/info/exclude
@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 / 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 / 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 / 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