Skip to content

Instantly share code, notes, and snippets.

View xeoncross's full-sized avatar

David Pennington xeoncross

View GitHub Profile
@xeoncross
xeoncross / settings.json
Last active December 18, 2019 16:43
VSCode settings to setup solarized light theme
{
"workbench.startupEditor": "newUntitledFile",
"workbench.colorTheme": "Solarized Light",
// "editor.defaultFormatter,
"workbench.colorCustomizations": {
// "sideBar.background": "#444",
// "sideBar.foreground": "#CCC",
// "list.activeSelectionBackground": "#777",
// "list.activeSelectionForeground": "#ffffff",
// "list.focusForeground": "#000",
@xeoncross
xeoncross / go_auth_library.md
Last active January 7, 2020 16:27
Ideas for an authentication library in Go to handle login, sessions, and request protection for HTML forms as well as single-page apps (or other clients)

Login / Auth System

Protect against:

  • DoS
  • Lock accounts after failed attempts
  • forgotten password tokens (or remeber me, CSRF, etc..) being used as logins (hash them all)
  • someone faking a login attempt and that action loging out valid user sessions
@xeoncross
xeoncross / go_mod_private_vps.md
Last active January 2, 2021 23:17
Access private repositiories in Go projects hosted on a remote server (using SSH)

Setup private Go modules

You have a git repositiory on a remote server. This is probably a VPS you have online at Digital Ocean, AWS, or some other hosting company. Could also be a docker container or raspberrypi under your desk.

Regardless, you can include the repositiory in your go projects by helping git (which Go uses) to know how to access the code over SSH.

Edit your ~/.gitconfig and make sure your host is listed. Below are examples for github, bitbucket, and my own custom VPS.

@xeoncross
xeoncross / dynamodb-setup.sh
Created November 20, 2019 17:21 — forked from kwilczynski/dynamodb-setup.sh
Something put together quickly to automatically associate Elastic IP address with the current EC2 instance.
aws dynamodb create-table --region <REGION> --profile <PROFILE> --table-name "<TABLE>" --attribute-definitions "AttributeName=key,AttributeType=S" --key-schema "AttributeName=key,KeyType=HASH" --billing-mode "PAY_PER_REQUEST"
aws dynamodb create-table --region <REGION> --profile <PROFILE> --table-name "<TABLE>" --attribute-definitions "AttributeName=key,AttributeType=S" --key-schema "AttributeName=key,KeyType=HASH" --billing-mode "PROVISIONED" --provisioned-throughput "ReadCapacityUnits=1,WriteCapacityUnits=1"
aws dynamodb update-time-to-live --region <REGION> --profile <PROFILE> --table-name "<TABLE>" --time-to-live-specification "Enabled=true,AttributeName=ttl"
aws dynamodb scan --region <REGION> --profile <PROFILE> --table-name "<TABLE>"
@xeoncross
xeoncross / mariadb_generator.sql
Created November 11, 2019 18:20
Example of writing a MariaDB query to generate 100k records
-- See more at https://stackoverflow.com/a/49446214/99923
INSERT INTO T1 (id, created_on, domain, seen_on)
SELECT one.X, two.X, three.X, two.X
FROM (select seq, seq X from seq_1_to_100000) one
LEFT JOIN (select seq, NOW() - INTERVAL seq MINUTE X from seq_1_to_100000) two ON one.seq = two.seq
LEFT JOIN (select seq, CONCAT(seq,'.',seq) X from seq_1_to_100000) three ON one.seq = three.seq;
@xeoncross
xeoncross / int_to_byteslice.go
Last active November 2, 2019 17:58
Writing a large number of ints to a byte slice is slower when using https://golang.org/pkg/encoding/binary/#Write
package bytewriter
import (
"bytes"
"encoding/binary"
"testing"
)
func BenchmarkBinary(b *testing.B) {
@xeoncross
xeoncross / lexer_in_go.md
Created October 22, 2019 18:43
Existing survey of text parsers / lexers in Go.
@xeoncross
xeoncross / lockmap.go
Last active October 22, 2019 14:45
Map of N locks contented by X goroutines. Use to limit access to a given function based on a key.
package syncmaptest
import (
"fmt"
"sync"
"testing"
"time"
)
var lockMap = &sync.Map{}
@xeoncross
xeoncross / http_server_filesystem.go
Last active October 21, 2019 15:41
Example of serving templates using both the system filesystem and an in-memory fake filesystem along with custom routes
package main
import (
"log"
"net/http"
"github.com/spf13/afero"
)
func main() {
@xeoncross
xeoncross / add_certs_to_pool.go
Created October 17, 2019 14:59
Golang: Self-signed certs: Get the system's certpool then append your cert into that pool, and use the new pool in your http/websocket clients
package main
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"log"
"net/http"
"net/textproto"
"net/url"