Skip to content

Instantly share code, notes, and snippets.

View jgarber's full-sized avatar

Jason Garber jgarber

View GitHub Profile
set background=dark
set guifont=Menlo\ for\ Powerline:h14
colorscheme solarized
set guioptions=egmt
let &colorcolumn=join(range(80,999),",")
@jgarber
jgarber / check_heroku_apps.rb
Created December 3, 2013 14:48
Find Heroku apps that haven't been patched for CVE-2013-4164
GOOD_VERSIONS = %w[1.8.7p375 1.9.2p321 1.9.3p484 2.0.0p353]
apps = `heroku apps`.split("\n")
apps.each do |app|
next if app.include? "My Apps"
app = app.split(" ")[0]
output = `heroku run "ruby -v" -a #{app} 2>&1`
match = output.match(/ruby ([\d.p]+)/)
version = match ? match[1] : "unknown"
puts "#{app}\t#{version}\t#{GOOD_VERSIONS.include?(version) ? "OK" : "UPGRADE"}"
end
namespace :bundle do
def intersection
return @outdated if @outdated
@outdated = `bundle outdated`
@outdated = @outdated.split("\n").select{|line| line.include?("*")}
@outdated = @outdated.map{|gem| gem.match(/\* ([a-zA-Z0-9_-]+) /)[1]}
app_gems = File.readlines("Gemfile").select{|line| line.include?("gem ")}
app_gems = app_gems.map{|gem| gem.match(/gem '([a-zA-Z0-9_-]+)/)[1]}
@jgarber
jgarber / gist:7488951
Last active December 28, 2015 10:49
Ruby, Chef, and Cucumber links

Ruby

  • Ruby Language site
  • Try Ruby
  • RubyGems – Gems are Ruby’s packages
  • Bundler – Application dependency management
  • RubyInstaller – Easy installation on Windows.
    • You will want to check the box to add Ruby to your PATH
    • You may also want to install the Development Kit so you can compile C extensions
  • Rubular – Online Ruby regular expression tester
@jgarber
jgarber / gist:7452338
Created November 13, 2013 16:50
One of my students just asked about the behavior below and I didn't have a good answer. Do you have an explanation?
2.0.0p247 :001 > a = [1, 2]
=> [1, 2]
2.0.0p247 :002 > a[1]
=> 2
2.0.0p247 :003 > a[2]
=> nil
2.0.0p247 :004 > a[1,1]
=> [2]
2.0.0p247 :005 > a[2,1]
=> [] ## <- Why is this not nil?
@jgarber
jgarber / make_one_dimensional.rb
Created September 14, 2013 18:05
Flatten deep hash of attributes into readable keys and values.
def make_one_dimensional(input = {}, output = {}, prefix = nil)
if input.respond_to?(:each)
input.each do |key, value|
key = [prefix, key].compact.join('.')
case value
when Hash
make_one_dimensional(value, output, key)
when Array
value.each_with_index do |v, index|
array_key = "#{key}[#{index}]"
@jgarber
jgarber / pias-ff.rb
Created August 27, 2013 02:34
PIAS fast-forward
require 'json'
def replace_json(node, &replacement_action)
case node
when Hash
node.each_value do |item|
yield item
replace_json(item, &replacement_action)
end
when Array
run_list(
'recipe[chef-solo-search]',
'recipe[rails_application]'
)
default_attributes(
rails: {
app: {name: "sample_app"},
deploy: {
repository: "https://github.com/jgarber/sample_app_2nd_ed.git"
@jgarber
jgarber / gist:5893179
Last active December 19, 2015 03:49
Setting up motion with a raspberry pi camera
ssh-copy-id pi@192.168.X.X
# on the pi
sudo su -
cat <<EOF >> /etc/wpa_supplicant/wpa_supplicant.conf
network={
ssid="Your SSID Here"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
@jgarber
jgarber / gist:5698080
Created June 3, 2013 13:16
Work-in-progress: Democratic rebuttal to "Welcome to the Republican Party"
The original:
Father-Daughter Talk
A young woman was about to finish her first year of college. Like so many others her age, she considered herself to be a very liberal Democrat, and was very much in favor of the redistribution of wealth. She was deeply ashamed that her father was a rather staunch Republican, a feeling she openly expressed. Based on the lectures that she had participated in, and the occasional chat with a professor, she felt that her father had for years harbored an evil, selfish desire to keep what he thought should be his.
One day she was challenging her father on his opposition to higher taxes on the rich and the addition of more government welfare programs. The self-professed objectivity proclaimed by her professors had to be the truth and she indicated so to her father. He responded by asking how she was doing in school. Taken aback, she answered rather haughtily that she had a 4.0 GPA, and let him know that it was tough to maintain, insisting that she was taking a very difficult cours