Skip to content

Instantly share code, notes, and snippets.

View sent-hil's full-sized avatar

Senthil Arivudainambi sent-hil

View GitHub Profile
@sent-hil
sent-hil / pictures.markdown
Created August 24, 2012 02:18
River (getriver.com): Keep a programming journal.

One of my favorite past times is to look at the notebooks of famous scientists. Da Vinci's notebook is well known, but there plenty others. Worshipping Da Vinci like no other, I bought a Think/Create/Record journal, used it mostly to keep jot down random thoughts and take notes. This was great in the beginning, but the conformity of lines drove me nuts. Only moleskines made blank notebooks, so I had to buy one.

At the same time I started a freelance project. The project itself is irrelevant, but suffice to say it was very complex and spanned several months. It seemed like a perfect opportunity to use the moleskine. Looking back, all my entries fell under few categories:

  • Todo
  • Question
  • Thought
  • Bug
  • Feature
The following below are what *I* think are best principles (after going through the last dozen mostly commented PRs):
1. Principle of least astonishment: does every single line follow principle of least astonishment?
This means if you, as a "reasonable" Rails programmer would be confused about this change, then this code either needs to be refactored or documented properly (there are situations that require us to break best practices, but these situations are very, very rare).
2. Readability: can I understand everything in PR (title, description, comments, code and tests) without having to ask the PR author to explain to me what it means?
And if there are edge case, are they documented properly?
3. Are edge cases, user input errors accounted for?
If the code relies on user input, what happens if the user is trying to sabotage? ie https://xkcd.com/327/
@sent-hil
sent-hil / suitesync_wipe_metadata_fields.rb
Created July 3, 2017 17:05 — forked from iloveitaly/suitesync_wipe_metadata_fields.rb
Wipe all metadata fields from Stripe used by http://SuiteSync.io/ when a sandbox refresh is performed
# Mike Bianco <mike@suitesync.io>
# Description: Wipe all metadata fields from Stripe used by SuiteSync.
# Helpful after a sandbox refresh.
#
# Usage:
# export STRIPE_KEY=sk_test_
# ruby suitesync_wipe_metadata_fields.rb
require 'stripe'

Keybase proof

I hereby claim:

  • I am sent-hil on github.
  • I am senthil196 (https://keybase.io/senthil196) on keybase.
  • I have a public key ASCi9RUVVKDkkW-LPPaJ_N6h6jccWFLmO5DaoSyUVc4sJAo

To claim this, I am signing this object:

@sent-hil
sent-hil / go_vroom
Last active December 21, 2015 05:49
First vim plugin
" Vim plugin for running the current test under cursor. I wrote it on a friday night
" when I was bored and sort of curious about vim plugin development. Needless to say
" I don't want to write any more vim plugins.
if exists("g:loaded_go_vroom")
finish
endif
if &compatible
echohl ErrorMsg
@sent-hil
sent-hil / gist:6259773
Created August 18, 2013 03:33
Run go test under cursor
function RunGoTestUnderLine()
let line_text = getline(".")
let raw_test_name = matchstr(getline("."), "Test.*\(")
if raw_test_name != -1
let test_name = substitute(raw_test_name, "\(", "", "")
exec '!go test -run ' . test_name
endif
endfunction
autocmd FileType go nnoremap <leader>s :call RunGoTestUnderLine()<cr>
1. Comments prefixed with // & space.
// right
//wrong
2. No blank lines between for & next line.
for _, name := range notAllowedSuffixes {
if strings.HasSuffix(sourceName, name) || strings.HasSuffix(targetName, name) {
@sent-hil
sent-hil / rvm
Last active December 17, 2015 00:19
Fish shell config
function fish_prompt --description 'Write out the prompt'
# Just calculate these once, to save a few cycles when displaying the prompt
if not set -q __fish_prompt_hostname
# set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
end
if not set -q __fish_prompt_normal
set -g __fish_prompt_normal (set_color normal)
end
@sent-hil
sent-hil / gist:4641437
Last active December 11, 2015 18:28
zsh function to show specs to code ratio in a rails folder, anything over 0.75 is good.
prompt_rspec_stats() {
if [[ ((-d app || -d lib) && -d spec) ]]; then
if [[ (-d app) ]]; then
local app=`wc -l app/**/*.rb | grep -oE "[0-9]+" | tail -n 1`
else
local app=`wc -l lib/**/*.rb | grep -oE "[0-9]+" | tail -n 1`
fi
local spec=$((`wc -l spec/**/*.rb | grep -oE "[0-9]+" | tail -n 1`))+0.01
local ratio=`printf "%.2f\n" $((spec/app))`
@sent-hil
sent-hil / open_auth2_refactor_lessons.md
Last active December 11, 2015 04:28
A list of lessons learned from refactoring my open_auth2 library to make it a better OOP citizen.

Recently I've been learning a lot about OOP, especially how to structure code to make it easier to change in the future. The following are some of the ways I refactored my open_auth2 library.

Don't optimize prematurely

I did the mistake of assuming what sugars were required, only to realize I never used them. Source.

Inject dependencies

The Token object accesses Config object for information. Before it was hard coded into Token, so they're highly coupled, so now I pass it as an argument to #initialize. Better yet it defaults to OpenAuth2::Config.new so it's only optional. Source.