View named_var.go
1 2 3 4 5 6 7 8 9
//An experiment using `runtime/debug` package to see what info can
//be gotten in runtime.
package main
 
import (
"log"
"runtime/debug"
"strings"
)
View fish.config
1 2 3 4 5 6 7 8 9 10
#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)
View fib.go
1 2 3 4 5 6 7 8 9 10
//Example showing off `pprof` in Go.
package main
 
import (
"os"
"os/signal"
"runtime/pprof"
)
 
func fib(num int) (result int) {
View go_vroom
1 2 3 4 5 6 7 8 9 10
" 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
View gist:6259773
1 2 3 4 5 6 7 8 9
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>
View go_style.txt
1 2 3 4 5 6 7 8 9 10
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) {
View rvm
1 2 3 4 5 6 7 8 9
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
View gist:4641437
1 2 3 4 5 6 7 8 9 10
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))`
View open_auth2_refactor_lessons.md

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.

View issue_with_modules.md

When working through unknown code method, ask:

What does a given method do?
What is the current object context that I am in?
What other methods can I call here?
module Purchasable
  def purchase
    result = Braintree::Transaction.sale(amount: total, credit_card: card)
Something went wrong with that request. Please try again.