Skip to content

Instantly share code, notes, and snippets.

@cloud8421
cloud8421 / future.rb
Last active August 29, 2015 14:02
Lightweight futures in Ruby (with Rails example)
class Future < Thread
def result
join
value
end
end
@cloud8421
cloud8421 / postgres_upgrade
Last active December 23, 2015 17:19 — forked from EdwardTippett/postgres_upgrade
Osx upgrade postgres from 9.2.4 to 9.3
Steps to install and run PostgreSQL 9.3 using Homebrew (Mac OS X)
(if you aren't using version 9.2.4, change to the correct version)
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
mv /usr/local/var/postgres /usr/local/var/postgres92
brew upgrade postgresql
initdb /usr/local/var/postgres -E utf8
pg_upgrade -b /usr/local/Cellar/postgresql/9.2.4/bin -B /usr/local/Cellar/postgresql/9.3.0/bin -d /usr/local/var/postgres92 -D /usr/local/var/postgres
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
@cloud8421
cloud8421 / .vimrc
Last active December 18, 2015 02:09
Basic .vimrc file for efficient editing in any situation. No plugins, but it assumes a 256 color terminal.
set nocompatible
set nobackup
set nowritebackup
set notimeout
set ttimeout
set ttimeoutlen=10
set noswapfile
set history=50
set ruler
set showcmd
@cloud8421
cloud8421 / mastering_basics.md
Created June 1, 2013 11:15
Mastering defaults in Vim - Cooking Lessons with Vim and Tmux - RubyDay.it 2013

Find

:find <filename>

Splitting and tabbing

:sp
:vsp
:tabnew

:tabe

@cloud8421
cloud8421 / gist:5510765
Created May 3, 2013 16:32
Sample ctrl-p configuration block to use with Greyhound
let g:greyhound_path = '/path/to/greyhound'
let g:ctrlp_use_caching = 0
let g:greyhound_exclude_paths = ".git,public/system,public/uploads,.svn,tmp/,vendor/cache,vendor/bundle,log/,.bundle,coverage/"
let g:ctrlp_user_command = g:greyhound_path." --exclude ".g:greyhound_exclude_paths
let g:ctrlp_match_func = { 'match': 'Greyhound' }
function! Greyhound(items, str, limit, mmode, ispath, crfile, regex)
let cmd = g:greyhound_path.' --exclude '.g:greyhound_exclude_paths
@cloud8421
cloud8421 / .vimrc
Created April 30, 2013 16:49
Rails.vim 5.0 projections sample files for London Vim user group
let g:rails_projections = {
\ "config/projections.json": {
\ "command": "projections"
\ }}
let g:rails_gem_projections = {
\ "active_model_serializers": {
\ "app/serializers/*_serializer.rb": {
\ "command": "serializer",
\ "affinity": "model"
@cloud8421
cloud8421 / stacktrace
Created April 30, 2013 15:24
Running assets precompile on Ruby 2.0.0 on Heroku, random stacktrace
/tmp/build_2tdvv2hv9kbdt/vendor/ruby-2.0.0/lib/ruby/2.0.0/fileutils.rb:1378: [BUG] Segmentation fault
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0065 p:---- s:0253 e:000252 CFUNC :stat
c:0064 p:0037 s:0249 e:000248 METHOD /tmp/build_2tdvv2hv9kbdt/vendor/ruby-2.0.0/lib/ruby/2.0.0/fileutils.rb:1378
c:0063 p:0007 s:0246 e:000245 METHOD /tmp/build_2tdvv2hv9kbdt/vendor/ruby-2.0.0/lib/ruby/2.0.0/fileutils.rb:1385
c:0062 p:0007 s:0243 e:000242 METHOD /tmp/build_2tdvv2hv9kbdt/vendor/ruby-2.0.0/lib/ruby/2.0.0/fileutils.rb:1301
c:0061 p:0028 s:0240 e:000239 BLOCK /tmp/build_2tdvv2hv9kbdt/vendor/ruby-2.0.0/lib/ruby/2.0.0/fileutils.rb:583
c:0060 p:0055 s:0235 e:000234 BLOCK /tmp/build_2tdvv2hv9kbdt/vendor/ruby-2.0.0/lib/ruby/2.0.0/fileutils.rb:1620
c:0059 p:0107 s:0231 e:000230 METHOD /tmp/build_2tdvv2hv9kbdt/vendor/ruby-2.0.0/lib/ruby/2.0.0/fileutils.rb:1635
@cloud8421
cloud8421 / deferred_garbage_collection.rb
Created April 11, 2013 14:53
Enable deferred garbage collection.
# spec/support/deferred_garbage_collection.rb
class DeferredGarbageCollection
DEFERRED_GC_THRESHOLD = (ENV['DEFER_GC'] || 15.0).to_f
@@last_gc_run = Time.now
def self.start
GC.disable if DEFERRED_GC_THRESHOLD > 0
@cloud8421
cloud8421 / how_to.md
Created October 6, 2012 08:55
Running commands with local variables on the fish shell

When using the Fish shell, you may need to run commands with local variables, like the following (Bash):

RAILS_ENV=staging rake db:migrate

This doesn't work in Fish, as setting a local variable follows another syntax, using the set command.

You can achieve the same result with the following syntax:

set -lx RAILS_ENV staging; rake db:migrate
@cloud8421
cloud8421 / how_to.md
Created September 18, 2012 15:03
Vim and Tmux workshop - 06 - Tmux and Vim

Setup

The following setup is pretty custom, but works pretty good for me.

The only caveat is that it requires a version of Vim compiled with ruby support, so you need to install it through Homebrew:

brew install macvim --override-system-vim

Next, you need to install a few plugins: