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
<ul id='choices'>
<li id='choice-horror'>
<a href='javascript:reward("horror")'>Horror</a>
</li>
<li id='choice-comedy'>
<a href='javascript:reward("comedy")'>Comedy</a>
</li>
<li id='choice-drama'>
<a href='javascript:reward("drama")'>Drama</a>
</li>
function reward(id) {
var rewardRequest = {
reward_id: rewardIDs[id],
value: 1
}
var url = options.suggestionboxAddr+'/models/'+options.modelID+'/rewards'
makeRequest('post', url, rewardRequest, function(){
alert('Reward sent - TODO: Redirect user to page /genres/' + id)
})
}
var choicesEl = document.getElementById('choices')
for (var choice in response.choices) {
var choice = response.choices[choice]
// keep track of this reward ID
rewardIDs[choice.id] = choice.reward_id
var choiceEl = document.getElementById('choice-'+choice.id)
choicesEl.appendChild(choiceEl)
}
{
"success": true,
"choices": [
{
"id": "documentary",
"score": 0.76,
"reward_id": "5ad7438c11eccdd34ab156e205b69c62"
},
{
"id": "comedy",
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}
]
}
@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.
@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 / 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 / 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 / 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()