Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 184 lines (165 sloc) 6.289 kB
#!/usr/bin/env ruby
#
# Git hook for breathalyzing before commmitting
require 'serialport'
require 'io/console'
require 'tumblr_client'
CONFIG = ".gitdown"
NORMAL = 0.05
BALLMER_MIN = 0.13
BALLMER_MAX = 0.15
mode_descriptions = {"normal" => "You best not be tipsy. Not even one bit.",
"krunk" => "If you ain't WASTED, you ain't COMMITTIN'",
"baller" => "BALL(m)ER PEAK: A narrow spike of blood alcohol content (0.13% - 0.15%) leading to high programming productivity.",
"math" => "A hobbled mode for those who haven't acquired their DrinkShield yet. Answer math problems to gain commit privileges."}
VOWELS = ['a', 'e', 'i', 'u', 'o', 'y', 'A', 'E', 'I', 'O', 'U', 'Y']
TUMBLRHOST = "gitdownhackny.tumblr.com"
API_KEY = "ZDJOwTnJd3SnXlGWjo8NyFORqcyc7wyjg0pAMIAHO2shdw9S6N"
API_SECRET = "p8R3nxfAG9QvOUCoOPmZz25N5YEnufwSdPt7aJ6gQDgfkdzqds"
OAUTH_TOKEN = "yyGjyA0zXPVSfccadcotOzjyTZchB3T8njx1hlDHx5Y7Mt8dup"
OAUTH_TOKEN_SECRET = "MLcD5STnDdhXrmBoKTHFZCJlEEOsiLmFmqIgPXc5FwmNTkfVlH"
IMAGES = ['http://www.societyofrobots.com/images/programming_PID_drunkdog.jpg',
'http://24.media.tumblr.com/49863e872d499205a9960d87cdbc0e8e/tumblr_mkvzhgpYSS1s7qixko1_500.gif',
'http://i.imgur.com/ueVZc.jpg',
'http://3.bp.blogspot.com/-FYIrCemUVwY/TxWlcgw1J5I/AAAAAAAAAY8/NfOS5aiHyzA/s1600/beer-drinker.jpg',
'http://25.media.tumblr.com/tumblr_ljgx4s9l4x1qipm4jo1_500.jpg',
'http://img514.imageshack.us/img514/2074/drunk0124kj.jpg',
'http://farm1.staticflickr.com/178/452713612_01ecbce27a_z.jpg']
BALLER_IMAGE = 'http://scm-l3.technorati.com/11/01/31/25951/steve-ballmer.jpg'
Tumblr.configure do |config|
config.consumer_key = API_KEY
config.consumer_secret = API_SECRET
config.oauth_token = OAUTH_TOKEN
config.oauth_token_secret = OAUTH_TOKEN_SECRET
end
mode = ""
port_str = ""
verbose = false
if File.exist?(CONFIG)
File.open(CONFIG).each do |line|
if line =~ /^mode.*/
mode = line.split(':')[1].strip
elsif line =~ /^port.*/
port_str = line.split(':')[1].strip
elsif line =~ /^verbose.*/
if line.split(':')[1].strip.downcase == 'true'
verbose = true
else
verbose = false
end
end
end
else
puts "No .gitdown file found"
exit 1
end
if mode.empty? or port_str.empty?
puts ".gitdown file contains errors."
puts "Make sure it contains a mode and port."
exit 1
end
puts "---------------- Time to GITDOWN!!! ----------------"
puts "You are in #{mode.upcase} mode."
puts mode_descriptions[mode]
puts "------------------------------------------------------"
#Serial port init variables
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
# Taking control of the serial port resets the Arduino.
# Wait 4 seconds for it to start up and autocalibrate
puts "Calibrating breathalyzer sensor..."
sleep(4)
puts "Prepare to blow into the breathalyzer! Breathalyzing starting in 3 seconds..."
sleep(3)
puts "Blow blow blow!!!"
#get bac from breathalizer
sp.write "a" #For the moment, the specific letter sent doesn't matter
sleep(6) #breathalyzer takes 5 seconds to measure, plus 1 for good measure
bac = sp.gets.chomp.to_f / 100.0
puts "\nYour BAC is: #{bac}%.\n"
if verbose
puts "BAC Effect Analysis:"
if bac < 0.03
puts "At this BAC, the average individual appears normal."
elsif bac >= 0.03 and bac < 0.06
puts "At this BAC, you are experiencing mild euphoria, relaxation, and talkativeness. Concentration is impaired."
elsif bac >= 0.06 and bac < 0.09
puts "At this BAC, you are experiencing disinhibition and extroversion. Reasoning, depth perception, and peripheral vision are impaired."
elsif bac >= 0.09 and bac < 0.20
puts "At this BAC, you are experiencing anger or sadness, boisterousness, and decreased libido. Reflexes and motor control are impaired. Slurred speech is possible."
elsif bac >= 0.20
puts "At this BAC, you are experiencing stupor, loss of understanding, and impaired sensations. Loss of consciousness and memory blackout are possible. Don't drink more!"
end
puts "\n"
end
commit_file = ARGV[0]
message = File.read(commit_file).strip
case mode
when "normal"
if bac > NORMAL
puts "I'm sorry Dave, I can't let you do that...you're too drunk."
puts "COMMIT ABORTED"
exit 1
else
puts "You are sober. Good job!"
puts "COMMIT SUCCESS"
exit 0
end
when "krunk"
if bac < NORMAL
puts "Sorry, you still have #{NORMAL - bac}%BAC to go until you're properly drunk..."
puts "COMMIT ABORTED"
exit 1
else
client = Tumblr::Client.new
puts "You are drunk! Good job."
puts "COMMIT SUCCESS"
name = `git config user.name`
now = DateTime.now
date = now.strftime("%B %e, %l:%M%p")
title = "#{name} - #{date} - BAC: #{bac}%"
drunk_message = "<p><strong>#{title}</strong>:</p> <p>\""
new_commit = ""
message.each_char do |c|
if VOWELS.include?(c)
new_commit += c * Random.rand(2..5)
else
new_commit += c
end
end
drunk_message += "#{new_commit}\"</p>"
img_url = IMAGES[Random.rand(IMAGES.count - 1)]
drunk_message += "<img src=#{img_url}>"
File.open(commit_file, 'w') { |f| f.write(new_commit) }
post = client.text(TUMBLRHOST, body: drunk_message)
exit 0
end
when "baller"
if bac >= BALLMER_MIN && bac <= BALLMER_MAX
client = Tumblr::Client.new
name = `git config user.name`
now = DateTime.now
date = now.strftime("%B %e, %l:%M%p")
title = "#{name} (Ballin') - #{date} - BAC: #{bac}%"
drunk_message = "<p><strong>#{title}</strong>:</p> <p>\""
new_commit = "HITTING THE BALLMER PEAK YO #{message}augifeoifh"
drunk_message += "#{new_commit}\"</p>"
img_url = BALLER_IMAGE
drunk_message += "<img src=#{img_url}>"
File.open(commit_file, 'w') { |f| f.write(new_commit) }
post = client.text(TUMBLRHOST, body: drunk_message)
puts "You are at the Ballmer peak. Awesome!"
puts "COMMIT SUCCESS"
exit 0
else
puts "You're not at the Ballmer peak...get between 0.13% and 0.15% to get in the zone!"
puts "COMMIT ABORTED"
exit 1
end
else
puts "Incorrect mode, check .gitdown file for examples"
exit 1
end
Jump to Line
Something went wrong with that request. Please try again.