Skip to content

Instantly share code, notes, and snippets.

User.new.job # => unsaved Job
User.create!.job # => saved Job
User.last.job # => existing Job
@nilbus
nilbus / npm_install_error.txt
Created July 20, 2017 15:24 — forked from anonymous/npm_install_error.txt
npm install fails to symlink in Docker for Windows with app in mounted filesystem
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install"
npm ERR! node v4.8.4
npm ERR! npm v2.15.11
npm ERR! path ../coffee-script/bin/coffee
npm ERR! code EINVAL
npm ERR! errno -22
npm ERR! syscall symlink
npm ERR! EINVAL: invalid argument, symlink '../coffee-script/bin/coffee' -> '/exercism/node_modules/lineman/node_modules/.bin/coffee'
@nilbus
nilbus / garbage_collect_block_vs_string.rb
Last active July 14, 2017 16:48
Surprise! In JRuby, Hash#fetch with a block to specify a default string is slower than passing the string as a 2nd argument.
require 'benchmark'
def fetch_with_block(arg)
arg.fetch(:sym) { "str" }
end
def fetch_with_str(arg)
arg.fetch(:sym, "str")
end
@nilbus
nilbus / results.md
Last active May 7, 2017 14:18
Benchmark to prove the validity of Avdi's approach to methods as constants

Summary

Feel free to use Avdi-style constants as methods when not calling the method repeatedly in a short period of time. Otherwise, consider the performance trade-off.

  • GC for this example took about 1.8ms per 1000 calls.
  • For significant numbers of iterations, using constants sped this example by 10x in reduced GC overhead
  • Each call in this test required GC of 10 short strings and 1 Hash.
@nilbus
nilbus / data.rake
Created April 10, 2017 02:44
Generate comments using existing data for performance testing
namespace :generate do
desc "generate N comments, typically for performance testing"
task comments: [:connection] do
n = ENV['N'].to_i
abort 'specify the number of comments to generate: N=<count>' if n.zero?
puts "Generating #{n} comments"
ActiveRecord::Base.connection.execute <<~SQL
INSERT INTO comments (submission_id, user_id, body, html_body, created_at, updated_at) (
SELECT
submission_id,
@nilbus
nilbus / deploy.sh
Created February 11, 2017 21:12
nilbus.com docker service update script
#!/bin/sh
# Used with https://github.com/nilbus/docker-hook to deploy $IMAGE
# when triggered by a Docker Hub webhook.
IMAGE='nilbus/nilbus.com'
docker pull $IMAGE
docker service update http --image $IMAGE
@nilbus
nilbus / brew-doctor.txt
Last active November 13, 2016 02:18
Relevant info related to homebrew-fuse issue
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!
Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/libcspec.0.dylib
def update
find_user
if @user.update_attributes(user_params)
respond_to do |format|
format.html {
redirect_to admin_user_path(@user)
flash[:notice] = 'User updated'
}
format.js {
@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