Skip to content

Instantly share code, notes, and snippets.

View d1str0's full-sized avatar

Brady Sullivan d1str0

  • TECH5 USA
  • Portland, Oregon
View GitHub Profile
#!/usr/bin/python
import os
def print_directory_contents(sPath):
"""
This function takes the name of a directory
and prints out the paths of files within that
directory as well as any files contained within
contained directories.
This function is similar to os.walk. Please don't
#!/usr/bin/python
from xml.etree import ElementTree
from operator import itemgetter
import urllib2
import sys
import time
start = time.time()
// Get newest price and update the price label.
func getPrice() {
let requestURL: NSURL = NSURL(string: "https://whatdoesabitcoincost.com/api/current")!
let urlRequest: NSMutableURLRequest = NSMutableURLRequest(url: requestURL as URL)
let session = URLSession.shared
let task = session.dataTask(with: urlRequest as URLRequest) {
(data, response, error) -> Void in
if let httpResponse = response as? HTTPURLResponse {
let statusCode = httpResponse.statusCode
type Price struct {
Current string `json:"currentPrice"`
}
var price Price
// To be run as a goroutine, because infinite loop
func priceUpdate() {
ticker := time.NewTicker(5 * time.Second)
@d1str0
d1str0 / current.go
Last active December 17, 2016 05:32
func currentPriceHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
w.Header().Add("Allowed", "GET")
http.Error(w, "Method not allowed.", http.StatusMethodNotAllowed)
return
}
resp := "{\"currentPrice\":\"1337.00\"}"
w.WriteHeader(http.StatusOK)
@IBAction func submitEmail(sender: AnyObject) {
showSpinner()
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
ProprietaryAsyncNetworkCall(self.emailTextField.text, success: {
dispatch_async(dispatch_get_main_queue(), {
self.hideSpinner()
})
}, failure: { (err) in
var error: String
@IBAction func submitEmail(sender: AnyObject) {
showSpinner()
SomeSpecialAsyncNetwork.Call(emailTextField.text, success: {
self.hideSpinner()
// something to do
}, failure: { (err) in
self.hideSpinner()
//something else
})
#slide-page .bcg2 {
background-image: url("https://cdn.shopify.com/s/files/1/1298/8647/files/Screen_Shot_2016-05-23_at_20.02.58.png?14915981676915710152");
background-repeat: no-repeat;
background-position: center;
background-color: #1c262f;
}
#slide-page .bcg2 {
background-image: url("https://cdn.shopify.com/s/files/1/1298/8647/files/Screen_Shot_2016-05-23_at_20.02.58.png?14915981676915710152");
background-repeat: no-repeat;
background-position: center;
background-color: #09bdfd;
}
[11:34:29] <gophoff> So. why is request.Form["xyz"] returning a []string ? (https://play.golang.org/p/0oxzjWQHSk)
[11:35:49] <awly> try r.FormValue("xyz")
[11:36:47] <Tv`> gophoff: because http forms can repeat fields
[11:37:06] <gophoff> awly: yes.. that works..
[11:37:39] <awly> http://foo.bar/baz?a=1&a=2&a=3 <- this is why url.Values uses []string for values[11:38:51] <gophoff> awly: sry. your link is not working
[11:39:03] <awly> that's not a real link
[11:39:21] <awly> just an example of form submission with multiple values for the same key
[11:39:26] <gophoff> ohhh... doing :-\