This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ChkTok is middleware that validates that the required | |
// security token is present. | |
func ChkTok(handler http.HandlerFunc) http.HandlerFunc { | |
return func(rw http.ResponseWriter, req *http.Request) { | |
sessionid := req.Header.Get(AUTHTOKEN) | |
if sessionid == "" { | |
util.WriteNewWebError(rw, http.StatusForbidden, "U-107", "x-anet-token is required.") | |
return | |
} | |
handler(rw, req) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CountRequests is middleware for standard handler functions | |
func (vc *VascoClient) CountRequests(handler http.HandlerFunc) http.HandlerFunc { | |
return func(rw http.ResponseWriter, req *http.Request) { | |
// we use a recorder as our response writer so we can inspect it | |
recorder := httptest.NewRecorder() | |
// now call the original handler with our recorder | |
handler(recorder, req) | |
// switch on the result | |
code := recorder.Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
.chart div { | |
font: 10px sans-serif; | |
background-color: green; | |
text-align: right; | |
padding: 3px; | |
margin: 1px; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"crypto" | |
"crypto/rsa" | |
"crypto/sha256" | |
"encoding/base64" | |
"encoding/binary" | |
"encoding/json" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var output = {} | |
for (var i=0; i<input.length; i++) { | |
if (output[input[i].owner] == undefined) { | |
output[input[i].owner] = [input[i].pet] | |
} else { | |
output[input[i].owner].push(input[i].pet) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var output = {} | |
input.forEach(function(element) { | |
if (output.hasOwnProperty(element.owner)) { | |
output[element.owner].push(element.pet) | |
} else { | |
output[element.owner] = [element.pet] | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let output = {} | |
for (const element of input) { | |
if (output.hasOwnProperty(element.owner)) { | |
output[element.owner].push(element.pet) | |
} else { | |
output[element.owner] = [element.pet] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
output = {} | |
for element in input: | |
if output.has_key(element["owner"]): | |
output[element["owner"]].append(element["pet"]) | |
else: | |
output[element["owner"]] = [element["pet"]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
output = dict() | |
for element in input: | |
try: | |
output[element["owner"]].append(element["pet"]) | |
except KeyError: | |
output[element["owner"]] = [element["pet"]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
output = dict() | |
for element in input: | |
item = output.get(element["owner"], []) | |
item.append(element["pet"]) | |
output[element["owner"]] = item |