Skip to content

Instantly share code, notes, and snippets.

View jonathanlking's full-sized avatar

Jonathan King jonathanlking

View GitHub Profile
@jonathanlking
jonathanlking / type.hs
Created November 6, 2016 22:20
Example code from "Type-level Web APIs with Servant" paper (http://alpmestan.com/servant/servant-wgp.pdf)
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
-- Example code from "Type-level Web APIs with Servant" paper
-- http://alpmestan.com/servant/servant-wgp.pdf
data Proxy a = Proxy

Keybase proof

I hereby claim:

  • I am jonathanlking on github.
  • I am jonathanlking (https://keybase.io/jonathanlking) on keybase.
  • I have a public key whose fingerprint is 692C 558E B366 B88E D831 91AA B09A CC18 752E 673D

To claim this, I am signing this object:

@jonathanlking
jonathanlking / change.hs
Last active April 20, 2016 13:49
Coin change problem
import Control.Applicative
import Data.Maybe
import Data.Array
import Data.List
-- UK coin values in pence
coins :: [Int]
coins = [500, 200, 100, 50, 20, 10, 5, 2, 1]
-- Helper functions
@jonathanlking
jonathanlking / machine.hs
Last active December 13, 2015 22:45
Register machine encoder/decoder
data Op = Inc Reg Label | Dec Reg Label Label | Halt deriving Eq
data Reg = Reg Integer deriving Eq
data Label = Label Integer deriving Eq
instance Show Op where
show Halt = "HALT"
show (Inc r l) = (show r) ++ "+ -> " ++ (show l)
show (Dec r l l') = (show r) ++ "- -> " ++ (show l) ++ ", " ++ (show l')
instance Show Reg where
@jonathanlking
jonathanlking / clean.hs
Last active April 20, 2016 13:56
For Linkload project
#!/usr/bin/env runhaskell
import System.Directory
import System.Environment
import Control.Monad
import System.FilePath.Windows
import Data.List
import Data.Maybe
type Name = String
@jonathanlking
jonathanlking / dice.hs
Created September 14, 2015 14:04
Calculates the possible numbers that could be thrown by `n` dice, and the number of occurrences.
import Control.Monad
import Control.Arrow
import Data.List
dice :: Int -> [(Int, Int)]
dice = freq . map sum . (flip replicateM) [1..6]
freq :: Ord a => [a] -> [(a, Int)]
freq = map (head &&& length) . group . sort
@jonathanlking
jonathanlking / bs.sh
Last active August 29, 2015 14:27
This is a bash port of the Web Economy Bullshit Generator
#!/usr/bin/env bash
# This is a bash port of the Web Economy Bullshit Generator
# http://www.dack.com/web/bullshit.html
# Now you don't have to worry about commit messages!
ARRAY1=("implement" "utilize" "integrate" "streamline" "optimize" "evolve" "transform" "embrace"
"enable" "orchestrate" "leverage" "reinvent" "aggregate" "architect" "enhance" "incentivize" "morph" "empower"
"envisioneer" "monetize" "harness" "facilitate" "seize" "disintermediate" "synergize" "strategize" "deploy"
"brand" "grow" "target" "syndicate" "synthesize" "deliver" "mesh" "incubate" "engage" "maximize" "benchmark"
#include <stdio.h>
#include <stdlib.h>
typedef enum type
{
CHAR,
INT,
LONG
} type;
@jonathanlking
jonathanlking / DeviceDetailViewController.m
Last active August 29, 2015 14:05
Ammmendments made to run UI changes on main thread using GCD
//
// DeviceDetailViewController.m
// MetaWearApiTest
//
// Created by Stephen Schiffli on 7/30/14.
// Copyright (c) 2014 MbientLab. All rights reserved.
//
// Amendments made to run UI changes on main thread using GCD by Jonathan King - 31/8/14
#import "DeviceDetailViewController.h"
<?php
function sendNotification($title,$body)
{
$AppKey = "YourUrbanAirshipAppKey";
$MasterSecret = "YourUrbanAirshipMasterSecret";
$request = curl_init();
curl_setopt($request, CURLOPT_URL, "https://go.urbanairship.com/api/push/");
curl_setopt($request, CURLOPT_USERPWD, "<$AppKey>:<$MasterSecret>");