Skip to content

Instantly share code, notes, and snippets.

View jvranish's full-sized avatar

Job Vranish jvranish

  • Grand Rapids, MI
View GitHub Profile
#ifndef MODULEA_H
#define MODULEA_H
#include "moduleB.h"
typedef struct
{
...
} ModuleAType;
@jvranish
jvranish / FixedListExample.hs
Created October 10, 2011 13:41
Example of some nice properties of fixed lists due to them being applicative functors
import Data.FixedList -- this doesn't come with haskell, do a 'cabal install fixed-list' to install it
-- or get it from here: http://hackage.haskell.org/package/fixed-list-0.1.5
-- more documentation on this library is here: http://hackage.haskell.org/packages/archive/fixed-list/0.1.5/doc/html/Data-FixedList.html
-- These are all built in haskell modules
import Control.Applicative
import Data.Foldable
import Prelude hiding (sum, concat)
@jvranish
jvranish / Parser.hs
Created August 11, 2011 19:15
Try5 Parser
module Language.Try5.Parser where
import Control.Monad
import Control.Monad.Identity
-- import Text.Parsec.Pos
import Text.Parsec.Prim
import Text.Parsec.Expr
import Text.Parsec.Combinator
@jvranish
jvranish / gist:1140475
Created August 11, 2011 19:09
preliminary AC AST definition
data Statement = ExprStmt ParsedExpr
| VarDef String
| ConstDef String ParsedExpr
| Foreign String
| Assign String ParsedExpr
| FuncDef String [ParsedStatement] Bool ParsedStatement
| Scope [ParsedStatement]
| For ParsedStatement ParsedStatement ParsedStatement ParsedStatement
| While ParsedExpr ParsedStatement
| DoWhile ParsedExpr ParsedStatement
@jvranish
jvranish / lift.hs
Created March 29, 2011 19:47
Example of how to automatically lift a haskell function into a function on some AST
import Control.Monad
import Control.Monad.Error
instance Error (RuntimeError a) where
data Expr = Number Int
| SomethingElse
deriving (Show, Eq, Ord)
data Type = Func Type Type
@jvranish
jvranish / div2.hs
Created March 18, 2011 01:49 — forked from sw17ch/div2.hs
Simple natural number type
-- div2.hs
data Nat = Zero | Succ Nat
deriving (Eq, Ord)
instance Show Nat where
show a = show $ fromEnum a
instance Num Nat where
a + Succ b = Succ a + b
@jvranish
jvranish / uniqueGridId.hs
Created February 6, 2011 02:42
Function for computing a unique grid Id from a coordinate (and it's inverse)
import Data.List
-- simple binomial coefficient function
binomial :: (Integral a) => a -> a -> a
binomial _ 0 = 1
binomial 0 _ = 0
binomial n k = (n - k + 1)*binomial n (k - 1) `div` k
fact :: (Num a, Enum a) => a -> a
@jvranish
jvranish / matrix.h
Created January 22, 2011 01:58
Neat template matrix library that I wrote in highschool
template<int r, int c, class T> class Matrix;
template<int d, class T>
class Vector
{
public:
Vector()
{ }
Vector(const T v[])
@jvranish
jvranish / either.cpp
Created January 18, 2011 15:45
Example Either type in C++
#include <stdio.h>
template <class T1, class T2>
class Either
{
bool isLeft;
union
{
T1 left;
T2 right;
@jvranish
jvranish / mergeTopo.py
Created December 4, 2010 21:56
Script to merge a topo map with an overhead map from pynemap
import Image
import math
im = Image.open("minecraft_map_topo.png")
rotatedTopo = im.rotate(-90)
im = Image.open("minecraft_map.png")
rotatedTerrain = im.rotate(-90)
terrainPix = rotatedTerrain.load()