Skip to content

Instantly share code, notes, and snippets.

View ramirez7's full-sized avatar
💗
Grey hairs are visible / I'm kinda of miserable, too

Armando Ramirez ramirez7

💗
Grey hairs are visible / I'm kinda of miserable, too
View GitHub Profile
type Coord = (Int, Int)
type Direction = Coord -> Coord
type Boundary = Coord -> Bool
north :: Direction
north (row, col) = (row - 1, col)
south :: Direction
south (row, col) = (row + 1, col)
data Message = Mark Word8 | Load Word64 Word64 | Undo | Reset | Legal Bool | Suggest Bool
newButtonPressEvent :: Int -> m -> Chan m -> IO ()
newButtonPressEvent pinNumber msg ch = -- forkIO blah blah blah
-- Push msg into ch whenever a press occurs on pinNumber (rising edge, basically)
-- Usually used partially applied :: Int -> m -> (Chan m -> IO ())
newButtonHoldEvent :: Int -> (Bool -> m) -> Chan m -> IO ()
newButtonHoldEvent pinNumber msg ch = -- forkIO, recursive loop with lastPressed
-- Push msg into ch whenever a hold or release occurs on pinNumber (rising edge = hold, falling edge = releaseS)
data Edge = Rising | Falling
newGpioEdgeEventHandler :: Int -> (Edge -> Maybe m) -> Chan m -> IO ()
-- The above function is a more general case of pressing or holding a button
-- Holding sends messages on the Rising and Falling edges of a GPIO pin's input
-- Pressing only sends messages on a Rising edge
-- If you want to not send a message on an edge, just have your
-- input function return Nothing
-- Otherwise, return Just m
fizzCases = [(3, "Fizz"), (5, "Buzz"), (7, "Baz")]
fizzBuzz :: Int -> String
fizzBuzz n = case (foldl fizzBuzzify "" fizzCases) of
"" -> show n
s -> s
where
fizzBuzzify acc (i, s) = if ((n `mod` i) == 0) then acc ++ s else acc
#!/usr/bin/expect
#example state:
#-------------------X-------XX------XO--------------------------- O
if { $argc != 2 } {
puts "USAGE: ./go.exp <BOARD> <PLAYER>"
exit 1
}
log_user 0
@ramirez7
ramirez7 / pic24.c
Created May 5, 2014 00:47
The code on our PIC24F microcontroller in BoilerReversi (ECE 477 Senior Design)
#include "p24F08KL302.h"
//_CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2)
//_CONFIG2( FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_XT & FNOSC_PRI)
_FGS(GSS0_OFF & GWRP_OFF)
_FICD(ICS_PGx2)
_FWDT(FWDTEN_OFF)
_FOSC(FCKSM_CSDCMD & OSCIOFNC_ON & POSCMD_XT)
_FOSCSEL(FNOSC_PRI & SOSCSRC_DIG)
// generic helpers
module FizzBuzzC
%default total
-- Dependently typed FizzBuzz, constructively
-- A number is fizzy if it is evenly divisible by 3
data Fizzy : Nat -> Type where
ZeroFizzy : Fizzy 0
Fizz : Fizzy n -> Fizzy (3 + n)
@ramirez7
ramirez7 / hlist.idr
Created September 6, 2015 03:42
HList take
module HList
% default total
data HList : List Type -> Type where
HNil : HList []
(::) : t -> HList ts -> HList (t :: ts)
hcons : t -> HList ts -> HList (t :: ts)
hcons = (::)
-- map is my original implementation
map : (f ~~> g) -> HList ts -> {auto prf : Mapper (f ~~> g) ts ts'} -> HList ts'
map f xs {prf} = map' f xs prf
-- It works for mapping head' over an HList of Lists:
:let xs: HList[List Int, List Bool]; xs = [[2], [True]]
*hlist> :let xs: HList[List Int, List Bool]; xs = [[2], [True]]
*hlist> :let ys2: HList[Maybe Int, Maybe Bool]; ys2=map (MkPoly(\a => head'{a=a})) xs
*hlist> ys2
[Just 2, Just True] : HList [Maybe Int, Maybe Bool]
#include <stdio.h>
#include <stdlib.h>
/*
* TODO
* - Maybe write some macros to facilitate writing the thunks
* - Lazy-cons macro? (can't have lazy-cons as a function due to CbV)
* - Make sure my memory management strategy isn't shit
* - I already know that if you use malloced ptrs in the Generic
* it'll fuck shit up