Skip to content

Instantly share code, notes, and snippets.

@freckletonj
freckletonj / BoundPlusRecursionSchemes.hs
Last active October 15, 2021 20:10
`bound` + `recursion-schemes` EDIT: this doesn't work, can't traverse into Scopes
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
module BoundRecursionSchemes where
@freckletonj
freckletonj / ConstrainedVinylRecords.hs
Last active August 7, 2017 14:59
Attempting to get values out of constrained Vinyl/Composite Extensible Records
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module ConstrainedVinylRecords where
@freckletonj
freckletonj / oauth.hs
Created April 27, 2017 21:06
Haskell Servant OAuth2.0 for GitHub
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-}
module Sand where
import Data.Aeson
@freckletonj
freckletonj / mytime.py
Created October 8, 2016 00:58
MyTime - Records a Log of My Active Window And Mouse Coordinates
"""
The MIT License (MIT)
Copyright (c) 2016 Josh Freckleton
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WIT
@freckletonj
freckletonj / logic 01.clj
Last active April 8, 2016 18:57
Clojure core.logic puzzle #01
(run* [q]
(fresh [al finn irv jim
p1 p2 p3 p4
y1 y2 y3 y4]
;; rule #1 ---------
;; Of the item that sold for $175 and the one that sold for $225,
;; one featured Irv Ingram and the other came out in 1983.
(conde
((== irv [:175 (lvar)])
(membero [:225 :1983] [al finn jim]))
@freckletonj
freckletonj / spiralizer.clj
Created March 31, 2016 18:23
Convert a sequence into spiral matrix
(defn rotate
"rotate a 2D matrix 90 degrees, it's ok if it's not a perfect square"
[mat]
(loop [remaining (map reverse mat)
result []]
(if (every? empty? remaining)
result
(recur (map rest remaining)
(conj result (remove nil? (mapv first remaining)))))))
@freckletonj
freckletonj / cljsfiddle_save.edn
Last active March 29, 2016 22:44 — forked from anonymous/cljsfiddle_save.edn
how to have an input with (essentially) two way binding
(def search-term (atom ""))
(defn input [model on-change]
(let [external-model (atom @model)
internal-model (atom (or @external-model ""))]
(fn [model on-change]
;; this is taken from recom - http://bit.ly/1SZ1OXn
(when (not= @external-model @model)
(.log js/console "changed to " @model)
(reset! external-model @model)
@freckletonj
freckletonj / notifications.cljs
Created March 25, 2016 22:12
ClojureScript Notifications
;; this is very much a gist, and it can be tweaked
;; ;; NOTIFICATIONS ----------
;; if (typeof Notification !== 'undefined') {
;; alert('Please us a modern version of Chrome, Firefox, Opera or Safari.');
;; return;
;; }
;; Notification.requestPermission(function (permission) {
;; if (permission !== 'granted') return;