Skip to content

Instantly share code, notes, and snippets.

View jhbabon's full-sized avatar
🦊

Juan Hernández jhbabon

🦊
View GitHub Profile
@jhbabon
jhbabon / option.ts
Created February 11, 2022 12:58
Result and Option types in TypeScript
/**
* Type Option represents an optional value: every option is either Some and contains a value,
* or None, and does not.
*
* The main idea behind Option is to prevent the abuse of null|undefined through the code
* and to enforce safe value checking through the type system. The absence of something is
* explicit thanks to None.
*
* @example Using basic is* methods
*
@jhbabon
jhbabon / env-vars.ts
Created September 18, 2020 08:08
A small environment variables parser in TypeScript
import { env } from 'process'
function isNumber(n: unknown): n is number {
if (typeof n !== 'number' || Number.isNaN(n)) {
return false
}
return true
}
@jhbabon
jhbabon / scout-history.zsh
Created June 3, 2020 08:53
Filter ZSH history with scout
setopt hist_ignore_all_dups
# based on: https://gist.github.com/dohq/9b97e07c865bb608108dd254b5e32fea
function scout-history() {
BUFFER=$(history -n -r 1 | scout --inline --lines=10 --search="$LBUFFER")
CURSOR=$#BUFFER
zle clear-screen
}
zle -N scout-history
bindkey '^r' scout-history
@jhbabon
jhbabon / vscout.vim
Last active December 12, 2018 10:10
scout.vim visual selection
" see: http://vimcasts.org/episodes/search-for-the-selected-text/
function! s:VScoutSearch(cmdtype)
let temp = @s
norm! gv"sy
let s:selection = @s
let @s = temp
if a:cmdtype == 'files'
call scout#files#run({ 'search': s:selection })
endif

Keybase proof

I hereby claim:

  • I am jhbabon on github.
  • I am jhbabon (https://keybase.io/jhbabon) on keybase.
  • I have a public key ASAjX5xO3GLE4GUqMipG9mhji5tjhMfAFM9MVfe1ZdTyiAo

To claim this, I am signing this object:

@jhbabon
jhbabon / test.rb
Last active December 4, 2015 10:48
Visitor pattern (double dispatch) on Ruby
require_relative 'visitor'
require_relative 'visitable'
class Object
include Visitable
end
class Log < Visitor
def visit_Array(array)
puts 'Logging array:'
@jhbabon
jhbabon / 2.2.3-railsexpress
Created August 25, 2015 06:11
ruby-build recipe for 2.2.3-railsexpress
build_package_reconfigure() {
test -f configure || autoconf
}
build_package_patch_ruby_railsexpress() {
fetch_git rvm-patchsets git://github.com/skaes/rvm-patchsets.git master
patch -p1 < rvm-patchsets/patches/ruby/2.2.3/railsexpress/01-zero-broken-tests.patch
patch -p1 < rvm-patchsets/patches/ruby/2.2.3/railsexpress/02-improve-gc-stats.patch
patch -p1 < rvm-patchsets/patches/ruby/2.2.3/railsexpress/03-display-more-detailed-stack-trace.patch
@jhbabon
jhbabon / 2.1.6-railsexpress
Created April 21, 2015 10:35
ruby-build recipe for 2.1.6-railsexpress
build_package_reconfigure() {
test -f configure || autoconf
}
build_package_patch_ruby_railsexpress() {
fetch_git rvm-patchsets git://github.com/skaes/rvm-patchsets.git master
patch -p1 < rvm-patchsets/patches/ruby/2.1.6/railsexpress/01-zero-broken-tests.patch
patch -p1 < rvm-patchsets/patches/ruby/2.1.6/railsexpress/02-improve-gc-stats.patch
patch -p1 < rvm-patchsets/patches/ruby/2.1.6/railsexpress/03-display-more-detailed-stack-trace.patch
@jhbabon
jhbabon / 2.1.5-railsexpress
Created December 2, 2014 17:02
ruby-build recipe for 2.1.5-railsexpress
build_package_reconfigure() {
test -f configure || autoconf
}
build_package_patch_ruby_railsexpress() {
fetch_git rvm-patchsets git://github.com/skaes/rvm-patchsets.git master
patch -p1 < rvm-patchsets/patches/ruby/2.1.5/railsexpress/01-zero-broken-tests.patch
patch -p1 < rvm-patchsets/patches/ruby/2.1.5/railsexpress/02-improve-gc-stats.patch
patch -p1 < rvm-patchsets/patches/ruby/2.1.5/railsexpress/03-display-more-detailed-stack-trace.patch
@jhbabon
jhbabon / 2.1.4-railsexpress
Created November 13, 2014 15:34
ruby-build recipe for 2.1.4-railsexpress
build_package_reconfigure() {
test -f configure || autoconf
}
build_package_patch_ruby_railsexpress() {
fetch_git rvm-patchsets git://github.com/skaes/rvm-patchsets.git master
patch -p1 < rvm-patchsets/patches/ruby/2.1.4/railsexpress/01-zero-broken-tests.patch
patch -p1 < rvm-patchsets/patches/ruby/2.1.4/railsexpress/02-improve-gc-stats.patch
patch -p1 < rvm-patchsets/patches/ruby/2.1.4/railsexpress/03-display-more-detailed-stack-trace.patch