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
#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
@ramirez7
ramirez7 / cps.ss
Created December 27, 2013 23:42
Visualization of continuation passing style using map as an example.
;; Non-tail recursive map
(define map
(lambda (f ls)
(if (null? ls)
'()
(cons (f (car ls)) (map f (cdr ls))))))
;; > (map add1 '(1 2 3))
;; (2 3 4)
(ns async-tut1.core
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [goog.dom :as dom]
[goog.events :as events]
[cljs.core.async :refer [put! chan <!]]
[cljs.core.async :as async]))
;; ============================================================================
;; HELPERS
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
@ramirez7
ramirez7 / gopurdue.hs
Last active September 21, 2016 03:34
main = let inputs = [InputAction Immediate $ getGpioRisingEdge ()]
initial = cycle "GO PURDUE! "
update _ state = tail state
outputs = [OutputAction Immediate $ print . head]
in topLevel inputs update initial outputs
main = let inputs = [InputAction (Repeat 1000000) $ return ()]
initial = cycle "GO PURDUE! "
update _ state = tail state
outputs = [OutputAction Immediate $ print . head]
#!/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