Skip to content

Instantly share code, notes, and snippets.

David Pennington Xeoncross

Block or report user

Report or block Xeoncross

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Xeoncross
Xeoncross / dynamodb-setup.sh
Created Nov 20, 2019 — forked from kwilczynski/dynamodb-setup.sh
Something put together quickly to automatically associate Elastic IP address with the current EC2 instance.
View dynamodb-setup.sh
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 Nov 11, 2019
Example of writing a MariaDB query to generate 100k records
View mariadb_generator.sql
-- 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 Nov 2, 2019
Writing a large number of ints to a byte slice is slower when using https://golang.org/pkg/encoding/binary/#Write
View int_to_byteslice.go
package bytewriter
import (
"bytes"
"encoding/binary"
"testing"
)
func BenchmarkBinary(b *testing.B) {
@Xeoncross
Xeoncross / lexer_in_go.md
Created Oct 22, 2019
Existing survey of text parsers / lexers in Go.
View lexer_in_go.md
@Xeoncross
Xeoncross / lockmap.go
Last active Oct 22, 2019
Map of N locks contented by X goroutines. Use to limit access to a given function based on a key.
View lockmap.go
package syncmaptest
import (
"fmt"
"sync"
"testing"
"time"
)
var lockMap = &sync.Map{}
@Xeoncross
Xeoncross / http_server_filesystem.go
Last active Oct 21, 2019
Example of serving templates using both the system filesystem and an in-memory fake filesystem along with custom routes
View http_server_filesystem.go
package main
import (
"log"
"net/http"
"github.com/spf13/afero"
)
func main() {
@Xeoncross
Xeoncross / add_certs_to_pool.go
Created Oct 17, 2019
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
View add_certs_to_pool.go
package main
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"log"
"net/http"
"net/textproto"
"net/url"
@Xeoncross
Xeoncross / ubuntu_setup.sh
Last active Oct 14, 2019
Setup a new user on Ubuntu 18+ VPS
View ubuntu_setup.sh
# Assuming you are logged in as root and the ssh key you want to use already installed for root (i.e. new Digital Ocean VPS)
adduser deploy
usermod -aG sudo deploy
mkdir /home/deploy/.ssh
cp /root/.ssh/authorized_keys /home/deploy/.ssh/
chmod 700 /home/deploy/.ssh
chown deploy:deploy -R /home/deploy/.ssh
View eventBus.js
/**
* subscriptions data format:
* { eventType: { id: callback } }
*/
const subscriptions = { }
const getNextUniqueId = getIdGenerator()
function subscribe(eventType, callback) {
const id = getNextUniqueId()
@Xeoncross
Xeoncross / sed cheatsheet
Created Oct 9, 2019 — forked from un33k/sed cheatsheet
magic of sed -- find and replace "text" in a string or a file
View sed cheatsheet
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
You can’t perform that action at this time.