Skip to content

Instantly share code, notes, and snippets.

View evanrinehart's full-sized avatar

Evan Rinehart evanrinehart

View GitHub Profile
function just(x){ return {just: x}; }
var nothing = {nothing: null};
function maybe(d, f, m){
if('nothing' in m){
return d;
}
else if('just' in m){
return f(m.just);
}
else{
@evanrinehart
evanrinehart / gist:a41180e897d42a1c6993
Created October 15, 2014 15:53
download a csv export of a google sheet
(ns atomic-playground.sheets
(:import [com.google.api.client.http GenericUrl]
[com.google.api.services.drive.model File]
[com.google.api.client.googleapis.auth.oauth2 GoogleCredential GoogleCredential$Builder]
[com.google.api.client.http HttpTransport]
[com.google.api.services.drive Drive Drive$Builder]
[com.google.api.services.drive DriveScopes]
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
import Test.QuickCheck
import Control.Monad
{-
This defines a "continuous space" I and a continuous function from I to itself.
You can interpret this space as a really low resolution continuous line segment
It consists of 5 "open subspaces":
// code is for 16MHz adafruit trinket (atmel ATtiny85)
int red = 0;
int green = 1;
int blue = 2;
void setup() {
// put your setup code here, to run once:
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
module Foo where
import Data.Attoparsec.ByteString
import Data.Attoparsec.ByteString.Char8
import Data.Attoparsec.Combinator
import Control.Applicative
import Data.Time
import Data.ByteString
import qualified Data.ByteString as BS
import Control.Monad
withShader :: ShType -> Src -> (GLuint -> IO (Either String a)) -> IO (Either String a)
withShader ty src action = mask $ \restore -> do
eithv <- loadShader ty src
case eithv of
Left err -> return (Left err)
Right v -> restore (action v) `finally` deleteShader v
d/dt enemies = keep <> new <> gone where
keep = mapWithKey (Ok . enemyAI) enemies
new = on buttonA newK (Create newEnemy)
gone = on buttonB target (Delete (enemies ! target))
on but k act = unDelta (\d -> if d < 0 then singleton k act else mempty) (d/dt but)
ks = keys enemies
newK = maximum ks + 1
d/dt x = v
d/dt v = a
a = -x
Let's say you have these equations:
a = -x
d/dt v = a
d/dt x = v
x and v are state variables and their initial values are a free choice.
Let's say x = 1 and v = 0 are the chosen starting state.
According to Wolfram Alpha, the solution to these equations and these initial values is:
x(t) = cos(t)
/* The cord switch is attached to CORD_IN, and we're using internal pullups.
so normally the value reads HIGH. when cord is pulled and connects to ground, reads LOW. */
/* In so many words, we're using the debounce protocol
described at university of utah "debouncing.pdf" section "software debouncers" */
/* return 1 if cord pull is detected, else 0 */
/* If 1 is returned, it will only be returned once (until cord is released and cycled). */
#define DEBOUNCE_TIME 100
int debounceState = HIGH;
int debounceTimer = DEBOUNCE_TIME;
int checkCordIn() {