Skip to content

Instantly share code, notes, and snippets.

@sagnew
Last active May 23, 2017 22:56
Show Gist options
  • Save sagnew/2fa3cccf9f055bad8f93b7b737d076e5 to your computer and use it in GitHub Desktop.
Save sagnew/2fa3cccf9f055bad8f93b7b737d076e5 to your computer and use it in GitHub Desktop.
Debugging code challenges for ShipIt! at $BASH
enum VNodeFlag: UInt32 {
case Delete = 0x00000001
case Write = 0x00000002
case Extended = 0x00000004
case Attrib = 0x00000008
case Link = 0x00000010
case Rename = 0x00000020
case None = 0x00000080
}
struct Flag {
var flagType: VNodeFlag
var description: String
}
var actions = [
Flag(flagType: .Delete, description: "deletes stuff"),
Flag(flagType: .Revoke, description: "revokes a permission"), // There is no .Revoke Flag in the enum.
Flag(flagType: .Link, description: "links nodes"),
Flag(flagType: .Delete, description: "deletes more stuff"),
]
for action in actions {
print("This \(action.flag) flag \(action.description)") // action.flag should be action.flagType
}
func jediGreet(name: String, ability: String) -> (farewell: String, mayTheForceBeWithYou: String) {
return ("Good bye, /(name).", " May the /(ability) be with you.") // String interpolation in Swift is done with "\" not "/"
}
let retValue = jediGreet(name: "old friend", ability: "Force")
print(retValue.farewell)
print(retValue.MayTheForceBeWithYou) // should be retValue.mayTheForceBeWithYou (uppercase M is the error)
import re
def hex_number_is_valid(number):
hex_pattern = re.compile('^[0-9a-F]+$') # This regex is straight up invalid.
return hex_pattern.match(number)
if hex_number_is_valid('AEF779'):
print('This is a valid hexadecimal number.')
import requests
rover_url = 'https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos'
parameters = {'api_key': 'DEMO_KEY', 'sol': '1324'}
response = requests.get(rover_url, params=parameters)
for photo in response['photos']: # response is just a Response object. The JSON was never parsed.
print(photo['img_src'])
func applyMutliplication(value: Int, multFunction: (Int) -> Int) -> Int {
return multFunction(value)
}
for i in [1, 2, 3, 4 5, 6, 7, 8, 9, 10] { // Missing comma in the array
var result = applyMutliplication(value: i, multFunction: {value in
num * 3 // There is no variable named "num"
})
print(result)
}
function read_file(file)
local input = io.open(file, r) -- the 'r' flag should be a string.
if input ~= nil then
io.input(input)
local content = io.read()
io.close(input)
end
return content -- content is a local variable, so it can't be accessed here.
end
import socket
UDP_IP = 127.0.0.1 # this needs to be a string.
UDP_PORT = 5000
sock = socket.socket(socket.AF_INET,
socket.SOCK_DGRAM)
socket.bind((UDP_IP, UDP_PORT)) # should be sock.bind
while True:
data, addr = sock.recvfrom(1024)
print("received message: {}".format(data))) # One extra closing paren
let timeMachines = ["DeLorean", "Epoch", "Bill and Ted's Phone Booth"]
var activations = timeMachines.map({
(timeMachine: String) -> String in
"\(timeMachine) has been activated!"
})
print(activation) // Variable name doesn't exist because it should be "activations" plural.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment