Skip to content

Instantly share code, notes, and snippets.

View matryer's full-sized avatar
🔨
Building things at @grafana

Mat Ryer matryer

🔨
Building things at @grafana
View GitHub Profile
@matryer
matryer / handle_greeter.go
Created August 1, 2017 12:15
Functions that return handlers let you neatly set things up
func handleGreeter() http.Handler {
// TODO: do any setup stuff here
//... like prepare a template:
tpl, err := template.ParseFiles("pages/_layout.html", "pages/gopher.html")
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if err != nil {
// parsing the template failed?
@matryer
matryer / gopherize.me.artwork.json
Created August 1, 2017 12:36
Response of Artwork API for Gopherize.me
{
"categories": [{
"id": "artwork/010-Body",
"name": "Body",
"images": [{
"id": "artwork/010-Body/blue_gopher.png",
"name": "blue gopher",
"href": "https://storage.googleapis.com/gopherizeme.appspot.com/artwork/010-Body/blue_gopher.png",
"thumbnail_href": "https://lh3.googleusercontent.com/2WSrI5x6u8LqWQ-xBzogIu3QrthPiawLH2zCPvrOgpMPU0K240di8pOKSwhz_IL0xiq5I2pBJkWrhyZDJeAPWD4=s71"
}, {
@matryer
matryer / artwork.go
Created August 1, 2017 12:41
Gopherize.me's artwork API response structure
type ArtworkResponse struct {
Categories []Category `json:"categories"`
TotalCombinations int `json:"total_combinations"`
}
type Category struct {
ID string `json:"id"`
Name string `json:"name"`
Images []Image `json:"images"`
}
@matryer
matryer / gopher.json
Last active August 1, 2017 13:32
Gopherize.me Gopher JSON endpoint
{
"id": "8d784442c57fa1647259a37c277c6738b2d79d6a",
"images": [
"artwork/010-Body/blue_gopher.png",
"artwork/020-Eyes/crazy_eyes.png",
"artwork/024-Glasses/all_black_sunglasses.png",
"artwork/027-Extras/laptop.png"
],
"original_url": "https://storage.googleapis.com/gopherizeme.appspot.com/gophers/8d784442c57fa1647259a37c277c6738b2d79d6a.png",
"url": "https://lh3.googleusercontent.com/dnKffPVPSYSIXhelVR8q88IM2tHxTQ8GgxlCezQjjqLrGvQI9roQIF71NfaOYN5m3txAfbpzyA48nklQMTZ5wgvG",
@matryer
matryer / gentle-scroll.jquery.js
Created August 27, 2017 18:22
Automatic gentle scroll
// gentle scrolling
// Anything with an href that points to something on the page
// is gently scrolled to, rather than jumping.
// Everything else is left alone.
$("a[href]").click(function(e) {
var dest = $(this).attr('href')
dest = dest.substr(dest.indexOf('#')+1)
var destEl = $('[id="'+dest+'"]')
if (destEl.length > 0) {
e.preventDefault()
@matryer
matryer / waitForVideoboxResults.go
Last active January 15, 2018 14:13
Go function to wait for Videobox task to complete
func waitForVideoboxResults(vb *videobox.Client, id string) (*videobox.VideoAnalysis, *videobox.Video, error) {
var video *videobox.Video
err := func() error {
defer fmt.Println()
for {
time.Sleep(2 * time.Second)
var err error
video, err = vb.Status(id)
if err != nil {
return err
@matryer
matryer / anonymise.go
Created January 16, 2018 13:22
Anonymise images using rectangles obtained by facial detection provided by Facebox (by machinebox.io)
// anonymise produces a new image with faces redacted.
// see https://becominghuman.ai/anonymising-images-with-go-and-machine-box-fd0866adb9f5
func anonymise(src image.Image, faces []facebox.Face) image.Image {
dstImage := image.NewRGBA(src.Bounds())
draw.Draw(dstImage, src.Bounds(), src, image.ZP, draw.Src)
for _, face := range faces {
faceRect := image.Rect(
face.Rect.Left,
face.Rect.Top,
face.Rect.Left+face.Rect.Width,
@matryer
matryer / face-verify-demo.js
Last active March 12, 2018 10:17
Face Verify Demo
<script>
var fv = new machinebox.FaceVerify({
facebox: "http://localhost:8080",
videoSelector: '#facePreview',
snapshotInterval: 1000,
error: function(error) {
if (!error) {
$('.ui.error.message').hide()
return
}
@matryer
matryer / logclass.go
Last active April 16, 2018 11:06
Classify log items using Classificationbox by Machine Box - https://machinebox.io/
/*
logclass
1. Run Classificationbox (see https://machinebox.io/docs/classificationbox)
2. Create a model and train it two classes with IDs: "noise" and "interesting"
3. Execute this command and pipe logs through it
Any logs that are not "noise" are passed through, others will be dimmed.
function makePrediction() {
// create a prediction request that includes some facts about
// the user.
var predictRequest = {
"inputs": [
{"key": "user_age", "type": "number", "value": ""+user.age},
{"key": "user_interests", "type": "list", "value": user.interests.join(',')},
{"key": "user_location", "type": "keyword", "value": user.city}
]
}