Skip to content

Instantly share code, notes, and snippets.

View kentquirk's full-sized avatar

Kent Quirk kentquirk

View GitHub Profile
@kentquirk
kentquirk / petowner_tuple.py
Last active September 10, 2016 18:02
Concatenation and tuples
output = dict()
for element in input:
output[element["owner"]] = output.get(element["owner"], ()) + (element["pet"],)
@kentquirk
kentquirk / petowner_comprehension1.py
Last active September 16, 2016 19:02
Set up output first
output = dict([[e["owner"], []] for e in input])
for element in input:
output[element["owner"]].append(element["pet"])
@kentquirk
kentquirk / using_lodash.js
Created September 10, 2016 18:19
Using lodash we can make it look like Python
// requires lodash.js
var output = {}
_.each(input, function(element){
a = _.get(output, element.owner, [])
a.push(element.pet)
output[element.owner] = a
})
@kentquirk
kentquirk / petowner_1.go
Last active September 11, 2016 03:56
Go implementation with non-JSON input
package main
import "fmt"
type Pet struct {
Owner string `json:"owner"`
Pet string `json:"pet"`
}
func main() {
@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(`[
@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_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_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 / 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 / .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=