Skip to content

Instantly share code, notes, and snippets.

@stuartnelson3
stuartnelson3 / decode.md
Created October 10, 2016 06:58 — forked from yang-wei/decode.md
Elm Json.Decode tutorial and cheatsheet

When receiving JSON data from other resources(server API etc), we need Json.Decode to convert the JSON values into Elm values. This gist let you quickly learn how to do that.

I like to follow working example code so this is how the boilerplate will look like:

import Graphics.Element exposing (Element, show)
import Task exposing (Task, andThen)
import Json.Decode exposing (Decoder, int, string, object3, (:=))

import Http
@stuartnelson3
stuartnelson3 / upload.js
Created July 31, 2014 18:24
Upload file on textarea drop
function addImageMarkdown(e, altText, imagePath) {
var startPos = e.selectionStart;
var endPos = e.selectionEnd;
e.value = e.value.substring(0, startPos)
+ "![" + altText + "](" + imagePath + ")"
+ e.value.substring(endPos, e.value.length);
}
$(document).on('drop', 'textarea', function(e) {
e.preventDefault();
@stuartnelson3
stuartnelson3 / resize.go
Last active August 29, 2015 14:01
golang resize image
package main
import (
"os"
"fmt"
"github.com/nfnt/resize"
"image/jpeg"
"image"
)
@stuartnelson3
stuartnelson3 / killall
Created January 21, 2014 16:17
kill -9 everything
#!bin/bash
ps aux |
grep $1 |
ruby -ne 'print $_.split[1]+"\n"' |
xargs kill -9
@stuartnelson3
stuartnelson3 / audite.rb
Created December 6, 2013 15:50
play mp3s passed as command line arguments
require 'audite'
player = Audite.new
player.events.on(:complete) do
# actions to complete after song finishes
end
player.events.on(:position_change) do |pos|
# puts "POSITION: #{pos} seconds level #{player.level}"
@stuartnelson3
stuartnelson3 / remove_old_branches.rb
Created June 10, 2013 19:30
set file to executable and drop in /usr/local/bin/
#!/usr/bin/env ruby
require 'date'
commit_branches_and_dates = `git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname) %(committerdate)'`.split("\n").map {|e| e[11..-1] }.map {|e| e.split(' ', 2) }
one_month_in_seconds = 60*60*24*30
parsable_time = (Time.now - one_month_in_seconds).to_s
one_month_before_now = Date.parse(parsable_time)
deleted_branch_count = 0
commit_branches_and_dates.each do |branch, date|
date = Date.parse date