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 / Example.hs
Last active August 29, 2015 14:03
Haskell Substitution Problem
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Control.Lens
import Data.Map (Map)
type SessionID = String
data Player = Player {
(ns demo
(:require-macros [schema.macros :as sm])
(:require [schema.core :as s]))
(defn twice
[x]
(* x 2))
@krisajenkins
krisajenkins / code.clj
Last active August 29, 2015 14:05
How to annotate?
(ann lookup-by
(All [a b]
[b (IFn [a -> b]) (Option (Seq a)) -> (Option a)]))
(defn lookup-by
"Convenience filter. Returns the first item in coll where (= value (lookup-fn item))"
[value lookup-fn coll]
(first (filter (fn _ [x]
(= value (lookup-fn x)))
coll)))
(require 'cl-lib)
(defun haskell-process-completions-at-point ()
"A company-mode-compatible complete-at-point function."
(interactive)
(destructuring-bind (start . end) (bounds-of-thing-at-point 'symbol)
(let ((completions (haskell-process-get-repl-completions (haskell-process)
(symbol-name (symbol-at-point)))))
(list start end completions))))
@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"
@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 / 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...
(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 / 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 =
module Main (..) where
intersectingMagnitude : Line -> Position -> Angle -> List Length
intersectingMagnitude ( ( sx, sy ), ( sa, sm ) ) ( rx, ry ) ra =
let
sdx =
cos (degrees sa)
rdx =