Skip to content

Instantly share code, notes, and snippets.

Adam Cuppy acuppy

View GitHub Profile
View monkey-patching.rb
class A
def foo
:bar
end
end
a = A.new
puts a.foo # => :bar
@acuppy
acuppy / rake_logger_example.rb
Created Jul 26, 2016
An example of how to tap into Rake and run a log line prior to every Rake Task run.
View rake_logger_example.rb
# lib/rake/logging.rb
require 'rake'
module Rake
module Logging
def invoke_task *args
puts "Running: #{parse_task_string args.first}" # ...or do whatever
super
end
View data-migrations-arborist-step1.rb
class AddFirstNameAndLastNameToUsers < Arborist::Migration
model :User
data do
model.find_each do |user|
first_name, last_name = user.full_name.split ' '
user.first_name = first_name
user.last_name = last_name
user.save!
View data-migrations-split-fullname.rake
namespace :data do
desc "Split the user's fullname into first and last names"
task :split_fullname => :environment do
User.reset_column_information
User.find_each do |user|
first_name, last_name = user.full_name.split ''
user.first_name = first_name
user.last_name = last_name
user.save!
View data-migrations-temp-model-association.rb
class AddCategoriesToPosts < ActiveRecord::Migration
# Fill the void
class ::Category < ActiveRecord::Base
end unless defined? ::Category
def change
Post.find_each do |p|
p.categories.create
end
View data-migrations-temp-model.rb
class AddAdminToUsers < ActiveRecord::Migration
# Fill the void
class User < ActiveRecord::Base
end unless defined? ::User
def change
add_column :users, :admin, :boolean, default: false
# convert existing users to admin
View data-migrations.rb
class AddAdminToUsers < ActiveRecord::Migration
def change
add_column :users, :admin, :boolean, default: false
# convert existing users to admin
User.reset_column_information
User.find_each do |u|
u.update admin: true
end
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:

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 .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>
You can’t perform that action at this time.