Skip to content

Instantly share code, notes, and snippets.

View xeoncross's full-sized avatar

David Pennington xeoncross

View GitHub Profile
@xeoncross
xeoncross / struct_embedding.go
Last active April 1, 2021 02:07
Example of using struct enbeding to implement an interface: https://play.golang.org/p/9RAY8RI7_N7
package main
import (
"fmt"
)
type A struct {
B string
}
const LONG = 26;
const SHORT = 12;
const MID = 9;
function sum(inputs) {
return inputs.reduce((s, v) => s + v, 0);
}
function average(N, inputs) {
return sum(inputs.slice(0, N)) / N;
@xeoncross
xeoncross / .block
Created March 12, 2021 15:27 — forked from rrag/.block
CandleStickChart with MACD Indicator
license: MIT
height: 620
@xeoncross
xeoncross / vscode_go_snippets.json
Created January 21, 2021 20:12
VSCode Go snippets
{
// Place your snippets for go here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
@xeoncross
xeoncross / YouTubeURLFormats.txt
Created January 16, 2021 03:55 — forked from rodrigoborgesdeoliveira/ActiveYouTubeURLFormats.txt
Example of the various YouTube url formats
http://www.youtube.com/watch?v=-wtIMTCHWuI
http://www.youtube.com/v/-wtIMTCHWuI?version=3&autohide=1
http://youtu.be/-wtIMTCHWuI
http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3D-wtIMTCHWuI&format=json
http://www.youtube.com/attribution_link?a=JdfC0C9V6ZI&u=%2Fwatch%3Fv%3DEhxJLojIE_o%26feature%3Dshare
@xeoncross
xeoncross / static_server.go
Last active January 1, 2021 00:07
Example of using httprouter or gorilla/mux to serve static assets (JS, Images, CSS, etc..) cached in the app binary using github.com/markbates/pkger
// https://github.com/julienschmidt/httprouter
router := httprouter.New()
router.HandlerFunc("GET", "/", index())
router.Handler("GET", "/static/*filepath", http.StripPrefix("/static/", http.FileServer(pkger.Dir("/public/static"))))
// https://github.com/gorilla/mux
router := mux.NewRouter()
router.HandleFunc("/", index())
router.PathPrefix("/static").Handler(http.StripPrefix("/static/", http.FileServer(pkger.Dir("/public/static"))))
@xeoncross
xeoncross / remove_ubuntu.sh
Created November 7, 2020 15:58
Remove Ubuntu, Debian, Android, etc... from windows computer
# You can do this using cmd run as administrator from the desktop
# (or if using a Windows 10 S-Mode computer from the startup repair or a USB drive).
$ diskpart
> list vol
# Find the Fat32, 100MB/260MB EFI volume and select it:
> select volume 3
> assign letter=z
> exit
@xeoncross
xeoncross / aes.go
Created October 16, 2020 03:00 — forked from tscholl2/aes.go
simple AES encryption/decryption example with PBKDF2 key derivation in Go, Javascript, and Python
package main
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"crypto/sha256"
"encoding/hex"
"fmt"
"strings"
@xeoncross
xeoncross / crypto-sha.js
Created August 19, 2020 19:18 — forked from chrisveness/crypto-sha.js
Uses the SubtleCrypto interface of the Web Cryptography API to hash a message using SHA-256.
/**
* Returns SHA-256 hash from supplied message.
*
* @param {String} message.
* @returns {String} hash as hex string.
*
* @example
* sha256('abc').then(hash => console.log(hash));
* const hash = await sha256('abc');
*/
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
)
// https://pkg.go.dev/go/ast?tab=doc#Object.Type