This file contains 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
const WRITE_TIME = 10 * time.Second | |
const PING_TIME = 60 * time.Second | |
const PONG_TIME = PING_TIME + WRITE_TIME | |
func pingPong(conn *websocket.Conn) { | |
ticker := time.NewTicker(PING_TIME) | |
defer func() { | |
ticker.Stop() | |
conn.Close() |
This file contains 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
#!/bin/bash | |
# Generate a new private key of size 4096 (with no pass phrase) | |
openssl genrsa -out server-key.pem 4096 | |
# Generate a self-signed cert using the key (valid for 10 years) | |
openssl req -new -x509 -key server-key.pem -out server-cert.pem -days 3650 | |
# Inspect the new cert | |
openssl x509 -in server-cert.pem -noout -text |
This file contains 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
// Source: https://github.com/mattn/go-sqlite3/pull/116 | |
if err.(sqlite3.Error).Code == sqlite3.ErrConstraint { | |
// clumsily compare err.Error() against strings to figure out what the heck happened... | |
} | |
// Additionally, the following is now possible: | |
if err.(sqlite3.Error).ExtendedCode == sqlite3.ErrConstraintUnique { | |
// oh! my unique constraint failed? |
This file contains 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" | |
"io" | |
"os" | |
"golang.org/x/crypto/ssh/terminal" | |
) |
This file contains 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
x, y = float | |
radians = atan2(y,x) | |
degrees = radians * (180 / pi) |
This file contains 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
Source: https://en.wikipedia.org/wiki/Circle#Equations | |
In an x–y Cartesian coordinate system, the circle with centre coordinates (a, b) | |
and radius r is the set of all points (x, y) such that: | |
x = a + r * cos t | |
y = b + r * sin t | |
where t is in the range 0 to 2π, interpreted geometrically as the angle that the | |
ray from (a, b) to (x, y) makes with the positive x-axis. |
This file contains 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 genid | |
import ( | |
"crypto/sha512" | |
"encoding/hex" | |
) | |
// NOTICE: DO NOT RELY ON THIS BEING SECURE! | |
// 16 hex chars = 64 entropy bits (in other words, worse than MD5 = 128 bits) | |
// but theoretically we should be good when using less than 10K ids? |
This file contains 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
// Copyright © 2016 Alex | |
// | |
// This program is free software: you can redistribute it and/or modify it under | |
// the terms of the GNU Affero General Public License as published by the Free | |
// Software Foundation, either version 3 of the License, or (at your option) any | |
// later version. | |
// | |
// This program is distributed in the hope that it will be useful, but WITHOUT | |
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
This file contains 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
<a href="/delete/ITEM" onClick="return confirm('You sure you want to delete this item?');">Delete</a> | |
requires only vanilla js | |
shows a ok/cancel popup box with a msg | |
clicking ok makes the user continue to the link |
This file contains 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 | |
// Generate 16 bytes long IDs. | |
// 9 bytes time and 7 bytes random, and then base36 encoded for nice URL safety. | |
// | |
// With heavy inspiration from: | |
// https://github.com/oklog/ulid | |
import ( | |
"crypto/rand" |