Skip to content

Instantly share code, notes, and snippets.

View imjacobclark's full-sized avatar
:shipit:
Shipping

Jacob Clark imjacobclark

:shipit:
Shipping
View GitHub Profile
{-# LANGUAGE OverloadedStrings #-}
module Lib
( recify,
getAccessTokenFromPayload
) where
import Web.Scotty
import Network.HTTP.Types (status302)
import Control.Monad.IO.Class
@imjacobclark
imjacobclark / README.md
Last active March 25, 2019 16:23
Doing the OAuth Dance for Spotify in Haskell with Scotty, Wreq and Aeson

This is still a work in progress, currently successfully authorises a user and exchanges that authorisation token for an access token.

(require 'sb-bsd-sockets)
; Create an inet-socket instance
(defparameter *socket* (make-instance 'sb-bsd-sockets:inet-socket :type :stream :protocol :tcp))
; Define our address to be 0.0.0.0 (public interface)
(defparameter *address* '(0 0 0 0))
; Define our port to be 8080
(defparameter *port* 8080)
; Connections to hold on the backlog
(defparameter *socket-backlog* 100)
(require 'sb-bsd-sockets)
; Create an inet-socket instance
(defparameter *socket* (make-instance 'sb-bsd-sockets:inet-socket :type :stream :protocol :tcp))
; Define our address to be 0.0.0.0 (public interface)
(defparameter *address* '(0 0 0 0))
; Define our port to be 8080
(defparameter *port* 8080)
; Connections to hold on the backlog
(defparameter *socket-backlog* 100)
@imjacobclark
imjacobclark / pad-numbers-to-same-length.lisp
Last active February 3, 2019 17:57
Pad numbers to same length
(defun pad(thing)
(concatenate 'string "0" thing))
(defun pad-if-length-not-same(thing length)
(cond
((not
(= (length thing) length))
(pad thing))
(t thing)))
@imjacobclark
imjacobclark / number-pad.lisp
Created February 2, 2019 23:34
Number padder in Lisp
(defun pad(num)
(concatenate 'string "0" num))
(defun should-pad(num)
(= (length num) 1))
(defun apply-padding(num)
(cond
((should-pad num) (pad num))
(t num)))
@imjacobclark
imjacobclark / DFA.hs
Created January 21, 2019 13:51
Simple DFA in Haskell
module DFASpec (spec) where
import Test.Hspec
data State = S1 | S2 deriving (Eq, Show)
data Symbols = Zero | One deriving (Eq, Show)
data Alphabet = Alphabet [Symbols] deriving (Eq, Show)
data FiniteStates = FiniteStates [State] deriving (Eq, Show)
@imjacobclark
imjacobclark / lex.rs
Last active January 11, 2019 22:45
A Lexer in Rust
#[derive(Debug, PartialEq)]
enum Token {
Symbol(Symbol),
Type(Type),
Keyword(Keyword),
Word(Word),
Char(char),
}
#[derive(Debug, PartialEq)]
package xyz.jacobclark.day3;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
@imjacobclark
imjacobclark / index.js
Created December 7, 2018 12:01
API Gateway -> Lambda -> Apollo -> AppSync -> GitHub API
const query = require('./query.js');
require('es6-promise').polyfill();
exports.handler = function(event, context, callback) {
query(event["queryStringParameters"]['username']).then(function(data){
var resp = {
"isBase64Encoded": false,
"statusCode": 200,