Skip to content

Instantly share code, notes, and snippets.

Avatar

Adam Cuppy acuppy

View GitHub Profile
@acuppy
acuppy / hash_compact.rb
Created Feb 6, 2014
Recursively delete hash key/value pairs where the value is nil
View hash_compact.rb
class Hash
def compact(opts={})
inject({}) do |new_hash, (k,v)|
if !v.nil?
new_hash[k] = opts[:recurse] && v.class == Hash ? v.compact(opts) : v
end
new_hash
end
end
end
View es.sh
cd ~
sudo apt-get update
sudo apt-get install openjdk-7-jre-headless -y
### Check http://www.elasticsearch.org/download/ for latest version of ElasticSearch and replace wget link below
# NEW WAY / EASY WAY
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.1.1.deb
sudo dpkg -i elasticsearch-1.1.1.deb
@acuppy
acuppy / install-ruby-redis-imagemagick-elasticsearch-ubuntu.sh
Last active Aug 29, 2015
Install Ruby, Imagemagick, Redis-server and Elasticsearch onto the development environment
View install-ruby-redis-imagemagick-elasticsearch-ubuntu.sh
#!/usr/bin/env bash
cd ~
sudo apt-get update
sudo apt-get install curl wget
# install ruby
curl -sSL https://get.rvm.io | bash -s stable --ruby="2.0.0-p353"
# install imagemagick
View purge.sh
#!/bin/sh
# Credits to:
# - http://vstone.eu/reducing-vagrant-box-size/
# - https://github.com/mitchellh/vagrant/issues/343
sudo su
aptitude -y purge ri
aptitude -y purge installation-report landscape-common wireless-tools wpasupplicant ubuntu-serverguide
@acuppy
acuppy / arguments.rb
Created Dec 11, 2014
Arguments wrapper
View arguments.rb
require "ostruct"
class Arguments
def initialize(arguments)
@whiny = arguments.delete(:whiny) || false
@arguments = arguments
@delegee = OpenStruct.new(@arguments)
end
def method_missing(method, *args)
View .vimrc.after
" shortcuts
inoremap jk <Esc>
:hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white
:hi CursorColumn cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white
:nnoremap <Leader>c :set cursorline! cursorcolumn!<CR>
autocmd BufWritePre * :%s/\s\+$//e
" close buffer
nmap <leader>d :bp<bar>sp<bar>bn<bar>bd<CR>
View delegate-event.rb
class Sampson < Character
def when(event, &block)
@events[event] ||= []
@events[event] << block
end
def bite_thumb
call_event :bite_thumb
end
View keybase.md

Keybase proof

I hereby claim:

  • I am acuppy on github.
  • I am acuppy (https://keybase.io/acuppy) on keybase.
  • I have a public key whose fingerprint is 8C8F EEEC D29D 5152 15A8 2619 46FF 4859 12E8 82B8

To claim this, I am signing this object:

@acuppy
acuppy / Hash required key assertions
Created Dec 28, 2010
Hash extension to add addition assertions
View Hash required key assertions
class Hash
# Confirms that a key is set in the Hash
def assert_required_keys(*required_keys)
missing_keys = []
[required_keys].flatten.each { |k| missing_keys << k unless keys.has_key?(k) }
raise(ArgumentError, "Missing required key(s): #{missing_keys.join(", ")}") unless missing_keys.empty?
end
# Confirms that a key is present and that is has value
@acuppy
acuppy / Unless Helpers
Created Jan 24, 2011
Adds the link_to_remote_if/unless helpers to a Rails application
View Unless Helpers
module ActionView
module Helpers
module PrototypeHelper
def link_to_remote_if(condition, name, options = {}, html_options = nil)
condition ? link_to_remote(name, options, html_options) : name
end
def link_to_remote_unless(condition, name, options = {}, html_options = nil)
!condition ? link_to_remote(name, options, html_options) : name
end