Skip to content

Instantly share code, notes, and snippets.

View cpuguy83's full-sized avatar
🐶

Brian Goff cpuguy83

🐶
View GitHub Profile
# Serializes model for use with pivot.js
# https://github.com/rjackson/pivot.js
require 'csv'
module Concerns::Pivotable
extend ActiveSupport::Concern
included do
attr_reader :pivotable_attrs
@pivotable_field_options ||= []
end
class ApplicationController < ActionController::Base
#... stuff
private
def resource_params
if params[:action] == 'new'
[]
elsif current_user.admin?
params.require(resource_instance_name).permit!
else
params.require(resource_instance_name).permit( *policy_attributes(resource_class) )
@cpuguy83
cpuguy83 / ruby.rb
Created August 19, 2013 19:45
Chef rbenv
include_recipe "rbenv::default"
include_recipe "rbenv::ruby_build"
@my_ruby_version = node[:_common_system][:ruby][:version]
rbenv_ruby @my_ruby_version do |rbenv|
rbenv.ruby_version @my_ruby_version
rbenv.global true
end
def gem_install(gem)
execute 'foo' do
command 'some_command_that_doesnt_create_its_own_file && touch /some/location/foo'
creates '/some/location/foo'
end
# or
execute 'foo' do
command 'this_command_creates_a_file_foo_in_etc'
creates '/etc/foo'
@cpuguy83
cpuguy83 / ridley_output
Created August 7, 2013 21:15
ridley crash on ruby 2.0
Brians-MacBook-Pro:~ bgoff$ which ruby
/Users/bgoff/.rubies/ruby-2.0.0-p247/bin/ruby
Brians-MacBook-Pro:~ bgoff$ irb
irb(main):001:0> require 'ridley'
/Users/bgoff/.gem/ruby/2.0.0/gems/json-1.8.0/lib/json/common.rb:67: [BUG] Segmentation fault
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
-- Crash Report log information --------------------------------------------
See Crash Report log file under the one of following:
* ~/Library/Logs/CrashReporter
@cpuguy83
cpuguy83 / knife_output
Created August 7, 2013 17:04
knife bootstrap windows fail
Brians-MacBook-Pro:~ bgoff$ knife bootstrap windows winrm 10.0.1.130 -x OCD
WARNING: Could not load IOV methods. Check your GSSAPI C library for an update
WARNING: Could not load AEAD methods. Check your GSSAPI C library for an update
Bootstrapping Chef on 10.0.1.130
Enter your password:
10.0.1.130 "Rendering &#39;C:\Users\OCD\AppData\Local\Temp\bootstrap-15078-1375894896.bat&#39; chunk 1"
10.0.1.130 "Rendering &#39;C:\Users\OCD\AppData\Local\Temp\bootstrap-15078-1375894896.bat&#39; chunk 2"
10.0.1.130 '#39' is not recognized as an internal or external command,
10.0.1.130 operable program or batch file.
10.0.1.130 "Rendering &#39;C:\Users\OCD\AppData\Local\Temp\bootstrap-15078-1375894896.bat&#39; chunk 3"
@cpuguy83
cpuguy83 / nginx location
Created July 31, 2013 16:06
nginx dynamic reverse proxy
location /reverse {
location ~ ^/(.*)/(.*) {
set $parsed_upstream $1;
set $url_remainder $2;
proxy_pass http://$parsed_upstream/$url_remainder;
}
proxy_pass http://$parsed_upstream/$url_remainder;
}
@cpuguy83
cpuguy83 / with_ruby_debug
Last active December 20, 2015 04:29
Chef 11.6 not searching in templates folder for apt response files
cookbook_file[/var/chef/cache/preseed/ldap/slapd-2.4.28-1.1ubuntu4.3.seed] (dynamically defined) had an error: Chef::Exceptions::FileNotFound: Cookbook 'ldap' (0.1.0) does not contain a file at any of these locations:
files/ubuntu-12.04/slapd.seed.erb
files/ubuntu/slapd.seed.erb
files/default/slapd.seed.erb
This cookbook _does_ contain: ['/tmp/vagrant-chef-1/chef-solo-1/cookbooks/ldap/files/default/ldap.conf'
Resource Declaration:
---------------------
Thread 29 (Thread 0x7fff86ffb700 (LWP 17872)):
#0 0x00007ffff72840fe in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib/x86_64-linux-gnu/libpthread.so.0
#1 0x0000000000658fba in wait_until (ts=0x7fff86ff9c70, mutex=..., this=0x7fff7c014490) at vm/util/thread.hpp:446
#2 rubinius::Park::park_timed (this=0x7fff7c014490, state=0x7fff86ffae10, call_frame=0x7fff86ff9ff0, ts=0x7fff86ff9c70)
at vm/park.cpp:49
#3 0x00000000006ef567 in rubinius::System::vm_sleep (state=0x7fff86ffae10, gct=..., duration=<optimized out>,
calling_environment=0x7fff86ff9ff0) at vm/builtin/system.cpp:754
#4 0x0000000000614c03 in rubinius::Primitives::vm_sleep (state=0x7fff86ffae10, call_frame=0x7fff86ff9ff0, exec=0x7ffff5a4e370,
mod=0x1695900, args=...) at vm/gen/method_primitives.cpp:22764
@cpuguy83
cpuguy83 / ruby.rb
Created July 18, 2013 13:44
My ruby recipe
include_recipe "rbenv::default"
include_recipe "rbenv::ruby_build"
ruby_version = node[:_common_system][:ruby][:version]
rbenv_ruby ruby_version do |rbenv|
rbenv.ruby_version ruby_version
rbenv.global true
end
def gem_install(gem, ruby)