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
// StartServer serves Handler over HTTPS(443) with a redirect on 80 | |
// using an ACME certificate it creates & is cached in ./certs/ | |
// and has sensible timeouts to avoid nasty clients. | |
// Note the timeouts don't work for slow transfers, | |
// but oddly are ok for websockets. | |
func StartServer(engine http.Handler, ...hostname string) | |
certManager := autocert.Manager{ | |
Prompt: autocert.AcceptTOS, | |
HostPolicy: autocert.HostWhitelist(hostname...), | |
Cache: autocert.DirCache("certs"), |
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
Bash: | |
curl -Ls golang.org/dl | grep -ohm1 htt[^\"]*linux-amd64.tar.gz | |
Returns just the line of the latest stable linux-amd64 build, like: | |
https://redirector.gvt1.com/edgedl/go/go1.9.2.linux-amd64.tar.gz | |
Make a ./go/ with the latest compiler ($GOROOT): | |
# Get the latest stable GoLang. |
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
window.detect={ | |
parse: function() { | |
var o = 'orientation' in window, prop, br, pre=['ms', 'moz','webkit']; | |
return { | |
isMobile: o, | |
browser: { | |
family: (o? "Mobile ":"Desktop ") + (function() { | |
for (prop in navigator) { | |
for (br in pre) { | |
if (!prop.indexOf(br)) { // IE 9 - Edge has "ms", else moz or webkit |
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 "fmt" | |
func main() { | |
a := 1 | |
b := 2 | |
max := map[bool]int{true: a, false: b}[a > b] | |
fmt.Println(max) | |
} |
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
function dataUrlToBlob(dUrl) { | |
return new Blob([new Uint8Array(atob(dUrl.slice( | |
dUrl.indexOf(',') + 1)).split(/\b|\B/).map(function(c){return c.charCodeAt(0)}))], | |
{type:dUrl.match(/\:([^;]*)/)[1]}); | |
} | |
// Example: | |
var OneByTwoRo_data_url = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4QBiRXhpZgAATU0AKgAAAAgABQESAAMAAAABAAYAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAAITAAMAAAABAAEAAAAAAAAAAABIAAAAAQAAAEgAAAAB/9sAQwADAgIDAgIDAwMDBAMDBAUIBQUEBAUKBwcGCAwKDAwLCgsLDQ4SEA0OEQ4LCxAWEBETFBUVFQwPFxgWFBgSFBUU/8IACwgAAgABAQERAP/EABQAAQAAAAAAAAAAAAAAAAAAAAj/2gAIAQEAAAABP/8A/8QAFhAAAwAAAAAAAAAAAAAAAAAAAAUW/9oACAEBAAEFAqx4f//EABkQAAEFAAAAAAAAAAAAAAAAAAACBTWU0f/aAAgBAQAGPwKZcLS9P//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAT8hQv/aAAgBAQAAABB//8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQABPxAV/9k="; | |
var blob_url = URL.createObjectURL(dataUrlToBlob(OneByTwoRo_data_url)); |
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
angular.module('autofocusAngularPolyfill', []) | |
.directive('autofocus', function() { | |
var timer; | |
return function(scope, elm, attr) { | |
if (timer) clearTimeout(timer); | |
timer = setTimeout(function() { | |
elm[0].focus(); | |
}); | |
}; |