Skip to content

Instantly share code, notes, and snippets.

View kentquirk's full-sized avatar

Kent Quirk kentquirk

View GitHub Profile
@kentquirk
kentquirk / hashit.go
Created June 28, 2018 02:13
hashit function in go
func hashit(s string) []byte {
h := sha256.New()
h.Write([]byte(s))
return h.Sum(nil)
}
@kentquirk
kentquirk / test.js
Created June 28, 2018 01:48
Test of full hasher with promises
m = require("./objtest3.js");
h = m.newHasher("This is a test")
h.hash().then((r) => {
console.log("hash of '" + h.s + "' is:", r.slice(0, 4))
}).catch((e) => {
console.log("Error: ", e)
});
@kentquirk
kentquirk / objtest.go
Created June 28, 2018 01:44
Full hasher object with promises
package main
//go:generate gopherjs build --minify
import (
"crypto/sha256"
"errors"
"github.com/gopherjs/gopherjs/js"
"github.com/miratronix/jopher"
@kentquirk
kentquirk / fixpath.py
Created December 7, 2017 02:58
fixpath.py is a script to clean up a path
#! /usr/bin/env python
# returns a path with some special front/back values and dups removed
import os
import sys
def getenv(name):
try:
return os.environ[name].split(':')
@kentquirk
kentquirk / .bash_profile
Created December 7, 2017 01:49
sanitized_bash_profile
export JAVA_HOME="$(/usr/libexec/java_home)"
export ANDROID_HOME=/usr/local/opt/android-sdk
export GOPATH=$HOME/go
export PATH_FIRST=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:${JAVA_HOME}
export PATH_LAST=/usr/local/opt/go/libexec/bin:$GOPATH/bin
export PATH=$(fixpath.py)
export PATH_FIRST=
export PATH_LAST=
@kentquirk
kentquirk / gitstat
Created September 16, 2016 19:54
gitstat bash script
#! /bin/bash
# checks status in all the git repositories below this one
# only prints status for those that aren't on master with no changes since the last tag
alltags() {
git tag | egrep "v[0-9]+\.[0-9]+\.[0-9]+(-.+)?" |tr '.-' ' *' |sort --numeric-sort --key 1.1 --key 2 --key 3 |tr ' *' '.-'
}
lasttag() {
alltags |tail -1
@kentquirk
kentquirk / petowner_comprehension2_more_readable.py
Created September 10, 2016 19:26
Python one-liner broken down
# broken down for "readability"
output = dict(
[
(o, [e["pet"] for e in input if e["owner"] == o])
for o in
set([i["owner"] for i in input])
])
@kentquirk
kentquirk / petowner_comprehension2.py
Created September 10, 2016 19:25
Python one-liner (bad idea!)
# oneline
output = dict([(o, [e["pet"] for e in input if e["owner"] == o]) for o in set((i["owner"] for i in input))])
@kentquirk
kentquirk / petowner_json.go
Last active September 11, 2016 03:55
Go with Data structure
package main
import (
"bytes"
"encoding/json"
"fmt"
)
type Pet struct {
Owner string `json:"owner"`
@kentquirk
kentquirk / petowner_noobject.go
Last active September 11, 2016 03:55
Go without creating a type for pets
package main
import (
"bytes"
"encoding/json"
"fmt"
)
func main() {
data := bytes.NewBuffer([]byte(`[