Skip to content

Instantly share code, notes, and snippets.

David Pennington Xeoncross

View GitHub Profile
View gist:cdb501a44eacda865b00b4806dcb318a
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
)
// https://pkg.go.dev/go/ast?tab=doc#Object.Type
@Xeoncross
Xeoncross / 64bit_hash_collisions_test.go
Last active Jun 3, 2020
Tests to see how 64bit hash functions perform in Go.
View 64bit_hash_collisions_test.go
package main
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"hash/fnv"
"testing"
"time"
@Xeoncross
Xeoncross / LSA.py
Created May 22, 2020 — forked from vgoklani/LSA.py
Latent Semantic Analysis (LSA) [simple example]
View LSA.py
#!/usr/bin/python
# reference => http://www.puffinwarellc.com/index.php/news-and-articles/articles/33.html
from numpy import zeros
from scipy.linalg import svd
from math import log # needed for TFIDF
from numpy import asarray, sum
titles = ["The Neatest Little Guide to Stock Market Investing",
@Xeoncross
Xeoncross / crypto_news.json
Created May 22, 2020 — forked from stungeye/crypto_news.json
News Site RSS Feeds
View crypto_news.json
[
{
"url": "http://money.cnn.com",
"rss": "http://rss.cnn.com/rss/money_topstories.rss"
},
{
"url": "http://thehill.com",
"rss": "http://thehill.com/rss/syndicator/19110"
},
{
@Xeoncross
Xeoncross / mysql.py
Last active May 7, 2020
Example database class for wrapping mysql-connector for python
View mysql.py
import mysql.connector
# from mysql.connector import Error
# pip3 install mysql-connector
# https://dev.mysql.com/doc/connector-python/en/connector-python-reference.html
class DB():
def __init__(self, config):
self.connection = None
self.connection = mysql.connector.connect(**config)
@Xeoncross
Xeoncross / docker_environment.md
Created Apr 30, 2020
Be careful when setting docker compose environment variables
View docker_environment.md

The following shows the right and wrong way to specify the environment flags. Be careful using Key: Value format depending on the docker version.

version: "3.2"
services:
    mariadb:
        image: mariadb:10.5
        ports:
            - "3306:3306"
        environment:
@Xeoncross
Xeoncross / mysql_bitmap.sql
Created Apr 8, 2020
MySQL / MariaDB bitmap operations on records
View mysql_bitmap.sql
-- https://stackoverflow.com/questions/60645538/how-do-you-store-and-mutate-a-bitmap-bitset-using-mysql
create table test(id int, b blob);
insert into test(id, b) select 1, 0x000000;
insert into test(id, b) select 2, 0xffffff;
delimiter //
create function set_bit(b blob, pos int, val int) returns blob reads sql data
comment 'changes the bit at position <pos> (0: right most bit) to <val> in the blob <b>'
begin
@Xeoncross
Xeoncross / interruptcontext.go
Created Feb 18, 2020
Example of using os.Signal interrupts (or CTRL+C) to stop context which can be used to end a process, database query, or http server.
View interruptcontext.go
func InterruptContext() context.Context {
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
ctx, cancel := context.WithCancel(context.Background())
go func() {
<-quit
cancel()
}()
View context_middleware.go
package contextmiddleware
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/peterbourgon/ctxdata/v2"
)
@Xeoncross
Xeoncross / aurora_serverless.md
Created Feb 12, 2020
Amazon AWS Aurora Serverless - Summary
View aurora_serverless.md

I have a pretty constant-use case in mind for collecting client metrics with different loads and spikes throughout the day and am mostly interested in paying a little extra to not have to manage the RDS/Aurora server instances. I basically just need a k/v store but need to do report queries/scans so DynamoDB isn’t a good fit. (COUNT(*) FROM, SUM, etc..)

Slow start

Looks like a minimum of 5 minutes of usage each time the database is activated and I’m pretty sure my load will never let the database shutdown so that might solve the cold-start issue.

https://aws.amazon.com/rds/aurora/faqs/?nc=sn&loc=6

You can’t perform that action at this time.