Skip to content

Instantly share code, notes, and snippets.

@nilbus
nilbus / code_sample.md
Last active May 12, 2016 20:12
On-Site Code Sample

Coding challenge or existing code?

The coding challenge is optional if you already have some code that you're proud of and can share with us.

Existing code

If you have existing code, please follow the following guidelines:

" Load pathogen plugins and reload their help files call pathogen#infect() call pathogen#helptags() " Set leader key to space nmap <Space> <NOP> let mapleader = "\<Space>"" " Indent with 2 spaces set shiftwidth=2 set softtabstop=2 set tabstop=2 set expandtab " Set width to 85 chars set textwidth=85 " Highlight things you've searched for, and press enter or - to un-highlight set hlsearch noremap - -:nohl<cr> noremap <cr> <cr>:nohl<cr> " Highlight matching braces/parenthesis set showmatch set matchtime=1 " Syntax highlighting syntax on au BufNewFile,BufRead *.tmpl set filetype=html " Wait for .5 sec before deciding you weren't trying a key sequence set timeoutlen=500 " Improved tab completion when using :e to open a file, etc. set wildmode=list:longest set wildignore+=*.class " (optional) Keep buffers open in memory (preserve undo history, etc) and just hide them when you close them (but not fugitive buffers) set hidden autocmd BufReadPost fugitive://* set bufhidden=delete " Ignore case when searching
tracking = DateTime.strptime(row['tracking'], '%Y%m%d%H%M%S')
Correspondence.where(
tracking: tracking,
sender: row['remetente'],
receiver: row['destinatario']).first_or_create(
tracking: tracking,
sender: row['remetente'],
receiver: row['destinatario'],
department: row['depto'],
bay: row['baia'],
@nilbus
nilbus / pause_after_exit
Last active December 22, 2015 18:59
Pause after running a command
#!/bin/bash
$* # Run the program passed in the args
EXIT=$? # Preserve the exit status
read -p "Press ENTER to exit."
exit $EXIT
@nilbus
nilbus / missing.rb
Last active December 11, 2015 13:26
def seed
1 # standing in for a non-numeric object that also responds to #next
end
# missing: Return enough items fill an array of existing items so that it has 10
# (multiple implementations)
# Test: assert_equal([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], missing([]))
# Test: assert_equal([9, 10], missing([1, 2, 3, 4, 5, 6, 7, 8]))
# @param queue: an Array with up to 10 items
@nilbus
nilbus / .vimrc
Created December 8, 2015 03:13
VIM config
" Load pathogen plugins and reload their help files
call pathogen#infect()
call pathogen#helptags()
" Set leader key to space
nmap <Space> <NOP>
let mapleader = "\<Space>""
" Indent with 2 spaces
set shiftwidth=2
@nilbus
nilbus / git-recently-checkout-branches.sh
Created November 23, 2015 16:48 — forked from mislav/git-recently-checkout-branches.sh
Show list of recently checked-out branches in reverse-chronological order
#!/bin/bash
set -e
git reflog -n100 --pretty='%cr|%gs' --grep-reflog='checkout: moving' HEAD | {
seen=":"
git_dir="$(git rev-parse --git-dir)"
while read line; do
date="${line%%|*}"
branch="${line##* }"
if ! [[ $seen == *:"${branch}":* ]]; then
@nilbus
nilbus / request.md
Last active November 11, 2015 22:40
Proposed changes to tcrayford/Values

This gem is great. Thanks for releasing it!

We're running into 2 issues using Values, however.

  1. Inheritance from other classes is impossible
  2. No support for optional arguments to ValueClass.with

What I'm suggesting is a significant deviation from current usage and would require a major version release. That said, I think the benefits are worth it. Please review these ideas, and let me know if you would consider accepting these changes into the project, providing that the changes are simple and elegant enough to stay in line with the project's goal for simplicity. If not, we'll fork and release under a different name.

Inheritance

Design Problem

I'm struggling to balance encapsulation with managing side effects in a specific scenario described here.

Classes

  • PriceSettings < ActiveRecord::Base (side-effect-based class methods, value-based instances) stores user parameters for price calculations
  • APIClient (adapter object) fetches statistics from an external API to use in price calculations
@nilbus
nilbus / will_not_execute.txt
Created August 11, 2015 15:01
Playing with @codefinger's mjruby
~ $ uname -a
Linux v 3.11.0-15-generic #25~precise1-Ubuntu SMP Thu Jan 30 17:39:31 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
~ $ unzip mjruby_linux_bin.zip
Archive: mjruby_linux_bin.zip
inflating: mjruby
~ $ ls -l ./mjruby
-rwxr-xr-x 1 nilbus nilbus 498245 Aug 10 14:13 ./mjruby