Skip to content

Instantly share code, notes, and snippets.

View xeoncross's full-sized avatar

David Pennington xeoncross

View GitHub Profile
@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
@xeoncross
xeoncross / 64bit_hash_collisions_test.go
Last active June 3, 2020 02:37
Tests to see how 64bit hash functions perform in Go.
package main
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"hash/fnv"
"testing"
"time"
@xeoncross
xeoncross / LSA.py
Created May 22, 2020 22:55 — forked from vgoklani/LSA.py
Latent Semantic Analysis (LSA) [simple example]
#!/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 19:25 — forked from stungeye/crypto_news.json
News Site RSS Feeds
[
{
"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 January 20, 2025 14:23
Example database class for wrapping mysql-connector for python
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 April 30, 2020 21:38
Be careful when setting docker compose environment variables

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 April 8, 2020 18:26
MySQL / MariaDB bitmap operations on records
-- 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 February 18, 2020 22:54
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.
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()
}()
package contextmiddleware
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/peterbourgon/ctxdata/v2"
)