Skip to content

Instantly share code, notes, and snippets.

View remexre's full-sized avatar

Nathan Ringo remexre

View GitHub Profile
@remexre
remexre / hwk_01_tests.ml
Last active January 25, 2017 21:40
CSCI2014 Spring 2017 Homework 1 Unit Tests
(*****************************************************************************)
(******************************** UNIT TESTS *******************************)
(*****************************************************************************)
#use "hwk_01.ml"
(* even or odd *)
let () =
assert (even 4);
assert (not (even 5))
(* Odd is not required *)
@remexre
remexre / passmenu
Last active February 4, 2017 04:11
#!/usr/bin/env bash
shopt -s nullglob globstar
typeit=0
if [[ $1 == "--type" ]]; then
typeit=1
shift
fi
@remexre
remexre / monads.md
Created October 26, 2016 23:57
Hello!

Monad Tutorial?

Making a Monad

We're going to make a monad called Result. First, define it as a type. This definition makes it essentially an enum which is generic over two types. It can either be Success containing a value of the first type, or Error containing a value of the second type.

data Result a e
;; With infix arithmetic macro:
(defn f-real (cr ci zr zi)
~{ zr * zr - ir * ir + cr})
(defn f-imag (cr ci zr zi)
~{ 2 * zr * zi + ci })
(defn complex-abs (a b)
(sqrt ~{a * a + b * b}))
(defn m-loop (cr ci zr zi i)
(if ~{i = 0}
~{(complex-abs zr zi) < 2}
;; C-like
(defn int foo (int x str y)
...)
;; Rust-like
(defn foo:int (x:int y:str)
...)
;; CLOS-like
(defn (foo int) ((x int) (y str))
;; POSIX-based API. Really long and yuck.
(defn capitalize-file (path)
; Read the input.
(def in-fd (open path))
(def in-str (read in-fd))
(close in-fd)
; Process the input.
(def out-str (toupper in-str))
; Write the output.
(def out-fd (open path 'w))
(defn times-two (x)
(* x 2))
(defn div-by-three (x)
(= (% x 3) 0))
;; With threading macro:
(->>
(range 100)
(filter div-by-three)
(map times-two)
extern crate ocl;
extern crate raw_cpuid;
extern crate serde;
extern crate serde_json;
include!(concat!(env!("OUT_DIR"), "/serde_types.rs"));
fn main() {
let cpu_vendor_name = format!("{}", raw_cpuid::CpuId::new().get_vendor_info().unwrap());
let plats = ocl::Platform::list();
extern crate ocl;
use ocl::*;
macro_rules! test {
($obj: expr, $func: ident) => {
println!(concat!("\t", stringify!($obj), ".", stringify!($func), "(): {:?}"),
$obj.$func().chars().last() == Some('\0'));
};
($prefix: expr, $obj: expr, $func: ident) => {
@remexre
remexre / .gitconfig
Last active September 9, 2016 19:24
Dotfiles
[alias]
lg = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
[push]
default = simple
[user]
email = remexre@gmail.com
name = Nathaniel Ringo
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f