Skip to content

Instantly share code, notes, and snippets.

View sent-hil's full-sized avatar

Senthil Arivudainambi sent-hil

View GitHub Profile
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 <[email protected]>
# 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:

//An experiment using `runtime/debug` package to see what info can
//be gotten in runtime.
package main
import (
"log"
"runtime/debug"
"strings"
)
#My fish prompt that I stole from somewhere and don't remember where to give credit. Sorry :(
#It's rather simple `senthil:~/p/es_console:master$`, shows current git branch if in a git repo.
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)
@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))`