-
Notifications
You must be signed in to change notification settings - Fork 32
/
commit-msg
executable file
·183 lines (165 loc) · 6.14 KB
/
commit-msg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/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