Skip to content

Instantly share code, notes, and snippets.

@codemartial
codemartial / no_polymorphism.go
Last active December 22, 2015 04:58
A demo of how embedding in Go does not result in polymorphic behaviour, unlike inheritance. More here: http://tech.t9i.in/2014/01/inheritance-semantics-in-go/
package main
import (
"fmt"
)
type Foo struct {
}
type Bar struct {
@codemartial
codemartial / standardise_iso.py
Created March 13, 2014 04:29
A filter to normalise ISO values to the nearest lower standard ISO
#!/usr/bin/python
import sys
limits = [0, 100, 200, 400, 800, 1600, 3200, 6400, 12800, 25600, 51200]
if __name__ == "__main__":
for line in sys.stdin:
iso = float(line)
print max([x for x in limits if x <= iso])
@codemartial
codemartial / standardise_fl.py
Created March 13, 2014 04:31
A filter to normalise focal lengths to the nearest standard focal length
#!/usr/bin/python
import sys
limits = [16.0, 24.0, 28.0, 35.0, 50.0, 70.0, 85.0, 105.0, 135.0, 150.0, 180.0, 200.0, 210.0, 300.0, 450.0, 600.0]
if __name__ == "__main__":
for line in sys.stdin:
fl = float(line)
diffs = dict([(abs(x - fl), x) for x in limits])
print diffs[min(diffs)]
@codemartial
codemartial / analyse_fl.py
Last active May 30, 2018 00:47
A Script to Analyse Effective Focal Length in Photographs
#!/usr/bin/python
import sys
full_imgsizes = {'NIKON D750': 6000,
'NIKON D7200': 6000,
'NIKON D3300': 6000,
'NIKON D7100': 6000,
'DSC-RX100': 5472,
'NEX-5': 4592,
'NIKON D90': 4288,
'NIKON D80': 3872}
@codemartial
codemartial / extract_fl_info.sh
Created January 5, 2015 11:52
Using exiftool to extract <file>,Model,ImageSize,35mmFL CSV Records for specific Lens IDs (assumed present in 'lensids' file)
find $SEARCH_PATHS -type f -print0 | xargs -0 exiftool -csv -F -LensIDNumber 2>/dev/null | grep -f lensids | cut -d ',' -f 1 > zoompix
cat zoompix | tr '\n' '\0' | xargs -0 exiftool -csv -Model -ImageSize -FocalLengthIn35mmFormat > info-zoompix
cat info-zoompix | ./analyse-fl.py
@codemartial
codemartial / mutexvsatomic.go
Created May 28, 2015 08:59
Benchmarking sync.RWMutex vs. sync/atomic Load/Store functions in Go 1.4
package mutexvsatomic_test
import (
"sync"
"sync/atomic"
"testing"
)
var a int32
@codemartial
codemartial / protobuf-mode.el
Created December 2, 2015 11:32
Syntax highlighting for .proto (Protocol Buffers IDL) files. Includes additional keywords from proto3 syntax.
;;; protobuf-mode.el --- major mode for editing protocol buffers.
;; Author: Alexandre Vassalotti <alexandre@peadrop.com>
;; Created: 23-Apr-2009
;; Version: 0.3
;; Keywords: google protobuf languages
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions are
;; met:
@codemartial
codemartial / flatten_expvar.go
Created May 24, 2016 13:06
Flattening expvars
func FlattenVar(kv expvar.KeyValue, w io.Writer, prefix string) {
if m, ok := kv.Value.(*expvar.Map); ok {
m.Do(func(kv_ expvar.KeyValue) { FlattenVar(kv_, w, fmt.Sprintf("%s%s.", prefix, kv.Key)) })
} else {
fmt.Fprintf(w, "\"%s%s\": %s\n", prefix, kv.Key, kv.Value)
}
}
@codemartial
codemartial / flat_expvars_endpoint.go
Last active May 24, 2016 13:28
Flattening expvars, full example.
package main
import (
"expvar"
"fmt"
"io"
"net/http"
)
func FlattenVar(kv expvar.KeyValue, w io.Writer, prefix string) {
@codemartial
codemartial / dfs.go
Created November 15, 2016 10:37
A distributed filesystem prototype
package main
import (
"bytes"
"fmt"
"sync"
"strings"
)
// Stores the filesystem hierarchy, data node members and their capacity