Skip to content

Instantly share code, notes, and snippets.

View krisajenkins's full-sized avatar
💭
:: Geek

Kris Jenkins krisajenkins

💭
:: Geek
View GitHub Profile
@krisajenkins
krisajenkins / CodeMesh2016.org
Created November 7, 2016 18:05
My notes from CodeMesh 2016

CodeMesh 2016 <2016-11-03 Thu>

Space Monads

We move the effort into designing the type, so that writing the algorithm is simpler.

[#B] Look at Hoare Logic

There is a relationship between monads and Hoare Logic. Can I solve the 9-jigsaw puzzle with Monads? https://en.wikipedia.org/wiki/Hoare_logic

Look at applications of Kleisli monads.

@krisajenkins
krisajenkins / elm-make-bug.sh
Created July 10, 2016 13:42
Demostrates a dependency-checking bug in elm-make.
#!/bin/sh
############################################################
# Create a simple working program.
############################################################
cat <<EOF > Foo.elm
module Foo exposing (..)
type alias Foo = Int
EOF
@krisajenkins
krisajenkins / Demo.elm
Created May 26, 2016 11:40
Virtual dom bug test case.
module Main exposing (..)
import Html exposing (..)
import Html.App exposing (beginnerProgram)
import Html.Events exposing (onClick, on, targetChecked)
type View
= Ascending
| Descending
@krisajenkins
krisajenkins / Demo.elm
Last active May 24, 2016 10:37
elm-html runtime bug
module Main exposing (..)
import Html exposing (..)
import Html.App exposing (beginnerProgram)
import Html.Events exposing (onClick, on, targetChecked)
type View
= Ascending
| Descending
module Main (..) where
intersectingMagnitude : Line -> Position -> Angle -> List Length
intersectingMagnitude ( ( sx, sy ), ( sa, sm ) ) ( rx, ry ) ra =
let
sdx =
cos (degrees sa)
rdx =
@krisajenkins
krisajenkins / person.hs
Created January 1, 2016 22:36
A couple of Haskell/SQL examples.
-- Both of these functions do the same thing: return some that, if given a DB connection, will return a list of records.
-- No type-checking, but obvious equivalence to SQL.
getPerson :: UUID -> SqlPersistM [Entity Person]
getPerson uuid = rawSql
rawSql "SELECT ?? FROM person WHERE person_id = ?" [uuid]
-- More DSL-ish, but more compile-time guarantees.
getPerson2 :: UUID -> SqlPersistM [Entity Person]
getPerson2 uuid =
(defn stateful-view []
(let [!form (reagent/atom {:name nil})]
(fn [ui-channel view-arg-1 view-arg-2]
[:form
[:input {:defaultValue (-> !form deref :name)
:onChange #(swap! !form assoc :name (.. % target value))}]])))
(defn regular-view
[ui-channel app]
[:div
@krisajenkins
krisajenkins / gist:5165b16e059f01bc44d1
Created April 20, 2015 10:40
JavaScript regexes are stateful!
var youtubeRegexp = /https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube(?:-nocookie)?\.com\S*[^\w\s-])([\w-]{11})(?=[^\w-]|$)(?![?=&+%\w.-]*(?:['][^<>]*>|<\/a>))[?=&+%\w.-]*/gi;
console.log(youtubeRegexp.test("https://www.youtube.com/watch?v=o4nCcgWFEwU"));
console.log(youtubeRegexp.test("https://www.youtube.com/watch?v=o4nCcgWFEwU"));
console.log(youtubeRegexp.test("https://www.youtube.com/watch?v=o4nCcgWFEwU"));
console.log(youtubeRegexp.test("https://www.youtube.com/watch?v=o4nCcgWFEwU"));
console.log(youtubeRegexp.test("https://www.youtube.com/watch?v=o4nCcgWFEwU"));
console.log(youtubeRegexp.test("https://www.youtube.com/watch?v=o4nCcgWFEwU"));
// Prints true, false, true, false...
@krisajenkins
krisajenkins / haskell-completion.el
Last active November 14, 2016 01:50
GHCi REPL-style completions for company-mode
(require 'cl-lib)
(require 'thingatpt)
(defun haskell-process-completions-at-point ()
"A company-mode-compatible complete-at-point function."
(-when-let (process (haskell-process))
(-when-let (symbol (symbol-at-point))
(destructuring-bind (start . end) (bounds-of-thing-at-point 'symbol)
(let ((completions (haskell-process-get-repl-completions (haskell-process)
(symbol-name symbol))))
@krisajenkins
krisajenkins / core.clj
Created December 4, 2014 13:42
Quick Schema Benchmark
(ns schemaspeed.core
(require [schema.core :as s]))
(def S {:name s/Str
:age s/Int
:things [s/Int]})
(def xs
(doall (repeat 100000
{:name "somename"