Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small delay fixes to the implementations of fucking-coffee, + a swift implementation of the scripts. #167

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added Swift/fucking-coffee.swift
Empty file.
40 changes: 40 additions & 0 deletions Swift/hangover.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Foundation

let accountSID = "TWILLIO_ACCOUNT_SID"
let authToken = "TWILLIO_AUTH_TOKEN"

let myNumber = "+XXX"
let bossNumber = "+XXX"

func Smackmybitch(){
let url = "https://api.twilio.com/2010-04-01/Accounts/\(accountSID)/Messages"
let parameters = ["From": "\(myNumber)", "To": "\(herNumber)", "Body": "\(message)"]
let auth = ["user": accountSID, "password": authToken]


var request = URLRequest(url: url)
request.setValue("Application/json", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
guard let httpBody = try? JSONSerialization.data(withJSONObject: parameters, options: []) else {
return
}
request.httpBody = httpBody
var authEncoded = "\(auth[user]!):\(auth[password]!)".dataUsingEncoding(NSASCIIStringEncoding, allowLossyConversion: true)!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.allZeros);
var authValue = "Basic \(authEncoded)"
urlRequest.setValue(authValue, forHTTPHeaderField: "Authorization")

let session = NSURLSession(configuration: config)
session.dataTaskWithRequest(request) { (data, response, error) -> Void in }.resume()
}

let excuses = [
"Locked out.",
"Pipes Broke.",
"Food Poisoning",
"Not feeling well"
]

let random = Int(arc4random_uniform(2))
let randomReason = reasons[random]
let message = "Gonna work from Home, \(randomReason)"
Smackmybitch()
Empty file added Swift/kumar-asshole.swift
Empty file.
39 changes: 39 additions & 0 deletions Swift/smack-my-bitch-up.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Foundation

let accountSID = "TWILLIO_ACCOUNT_SID"
let authToken = "TWILLIO_AUTH_TOKEN"

let myNumber = "+XXX"
let herNumber = "+XXX"

func Smackmybitch(){
let url = "https://api.twilio.com/2010-04-01/Accounts/\(accountSID)/Messages"
let parameters = ["From": "\(myNumber)", "To": "\(herNumber)", "Body": "\(message)"]
let auth = ["user": accountSID, "password": authToken]


var request = URLRequest(url: url)
request.setValue("Application/json", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
guard let httpBody = try? JSONSerialization.data(withJSONObject: parameters, options: []) else {
return
}
request.httpBody = httpBody
var authEncoded = "\(auth[user]!):\(auth[password]!)".dataUsingEncoding(NSASCIIStringEncoding, allowLossyConversion: true)!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.allZeros);
var authValue = "Basic \(authEncoded)"
urlRequest.setValue(authValue, forHTTPHeaderField: "Authorization")

let session = NSURLSession(configuration: config)
session.dataTaskWithRequest(request) { (data, response, error) -> Void in }.resume()
}

let reasons = [
"Working Hard",
"Gotta ship this feature",
"Somebody fucked the system again."
]

let random = Int(arc4random_uniform(2))
let randomReason = reasons[random]
let message = "Late at work. \(randomReason)"
Smackmybitch()
25 changes: 14 additions & 11 deletions nodejs/fucking_coffee.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,25 @@ exec("who", function(error, stdout, stderr) {
var password = 'xxxx';
var con = new telnet();


con.on('ready', function(prompt) {
con.exec('Password: ' + password, function(error, res) {
setTimeout(function(){
con.exec('Password: ' + password, function(error, res) {

// Brew Coffee!
con.exec('sys brew', function(error, res) {
// Brew Coffee!
con.exec('sys brew', function(error, res) {

// Wait for 24s
setTimeout(function() {
// Wait for 24s
setTimeout(function() {

// Pour Coffee!
con.exec('sys pour', function(error, res) {
con.end();
});
}, 24000);
// Pour Coffee!
con.exec('sys pour', function(error, res) {
con.end();
});
}, 24000);
});
});
});
},17000);
});

con.connect({host: coffee_machine_ip});
Expand Down
3 changes: 2 additions & 1 deletion python/fucking_coffee.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
password = '1234'
password_prompt = 'Password: '

time.sleep(17)
con = telnetlib.Telnet(coffee_machine_ip)
con.read_until(password_prompt)
con.write(password + "\n")

# Make some coffee!
con.write("sys brew\n")
time.sleep(64)
time.sleep(24)

# love the smell!
con.write("sys pour\n")
Expand Down
3 changes: 1 addition & 2 deletions python3/fucking_coffee.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ def main():
return

time.sleep(17)

conn = telnetlib.Telnet(host=COFFEE_MACHINE_ADDR)
conn.open()
conn.expect([COFFEE_MACHINE_PROM])
conn.write(COFFEE_MACHINE_PASS)

conn.write('sys brew')
time.sleep(64)
time.sleep(24)

conn.write('sys pour')
conn.close()
Expand Down