Skip to content

Instantly share code, notes, and snippets.

View ShawnMilo's full-sized avatar

Shawn Milochik ShawnMilo

View GitHub Profile
@ShawnMilo
ShawnMilo / ksuid_to_timestamp.sql
Created May 2, 2023 18:38
Convert a ksuid to a datetime/timestamp with time zone in PostgreSQL (plpgsql)
CREATE OR REPLACE FUNCTION ksuid_to_datetime(ksuid_base62 TEXT)
RETURNS TIMESTAMP WITH TIME ZONE AS $$
DECLARE
v_alphabet CHAR ARRAY[62] := ARRAY[
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
@ShawnMilo
ShawnMilo / adoc.py
Created July 21, 2022 03:36
Convert .adoc file to PDF using AsciiDoctor
#!/usr/bin/env python3
"""
Convert .adoc files to .pdf.
Periodically check for updated tags:
https://hub.docker.com/r/asciidoctor/docker-asciidoctor/tags
"""
import sys
import os
from subprocess import check_output
@ShawnMilo
ShawnMilo / audit.py
Created October 5, 2021 13:27
audit.py
#!/usr/bin/env python3
"""
Find files to audit so that all files are looked
at regularly.
"""
from os.path import abspath, dirname, join
from os import walk
import re
#!/usr/bin/env python
import os
import sys
from time import sleep
from random import randrange
import re
fkey = re.compile(r'^F\d$')
@ShawnMilo
ShawnMilo / simple_cookies.go
Created July 26, 2019 19:25
Simple use of cookies in Go
package main
import (
"crypto/rand"
"fmt"
"log"
"net/http"
"sync"
"time"
)
package main
import (
"fmt"
"net"
"sync"
"time"
)
var addresses = make(chan string)
@ShawnMilo
ShawnMilo / webhook.go
Created October 9, 2017 15:35
Listen for GitHub webhooks and keep local repos up to date.
package main
/*
Listen for calls from GitHub and update local repositories.
*/
import (
"encoding/json"
"fmt"
"io/ioutil"
@ShawnMilo
ShawnMilo / klog.go
Created July 26, 2017 23:22
kubernetes log combiner
package main
import (
"log"
"os"
"os/exec"
"strings"
"sync"
"time"
)
from hashlib import sha512
from uuid import uuid4
from redis import StrictRedis
__all__ = (
'hash_password', 'create_user', 'login_is_valid',
)
conn = StrictRedis()
@ShawnMilo
ShawnMilo / foe.go
Created January 6, 2015 20:08
foe. A file search that opens the files found in vim.
package main
import (
"bufio"
"flag"
"log"
"net/http"
"os"
"os/exec"
"path/filepath"