Skip to content

Instantly share code, notes, and snippets.

View jvranish's full-sized avatar

Job Vranish jvranish

  • Grand Rapids, MI
View GitHub Profile
@jvranish
jvranish / stack_traces.c
Last active April 25, 2024 15:51
An example of catching exceptions and printing stack traces in C on Windows, Linux and OS X
/* compile with:
on linux: gcc -g stack_traces.c
on OS X: gcc -g -fno-pie stack_traces.c
on windows: gcc -g stack_traces.c -limagehlp
*/
#include <signal.h>
#include <stdio.h>
#include <assert.h>
@jvranish
jvranish / AST.hs
Created November 25, 2012 16:06
An example alternative AST construction using GADTs
class HasStmt a where
class HasDef a where
class HasExpr a where
data Module = Module [ParsedDef]
data ParsedDef = ParsedDef (Definition ParsedStmt) SourcePos
data ParsedStmt = ParsedStmt (Statement ParsedDef ParsedStmt ParsedExpr) SourcePos
data ParsedExpr = ParsedExpr (Expr ParsedExpr) SourcePos
@jvranish
jvranish / TypeDirected.hs
Created November 17, 2012 14:37
Example code for 1DevDay talk
{-#Language DeriveFunctor
, DeriveFoldable
, DeriveTraversable #-}
import Control.Applicative
import Data.Foldable
import Data.Traversable
import Prelude hiding (sum)
@jvranish
jvranish / dynamic_alloc_reverse.c
Created September 22, 2012 21:07
Dynamic Allocation without malloc in C (with no mutation!)
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
/*
This is our integer linked list type (Null is an empty list)
(it is immutable, note the consts)
*/
typedef struct IntList_s const * const IntList;
@jvranish
jvranish / Gemfile
Created August 12, 2012 01:53
An example explaining how to use bundler to replace externals/submodules
source "http://rubygems.org"
gem "my_awesome_lib", :path => "../my_awesome_lib"
# or to use directly from a git repository:
# gem "my_awesome_lib", :git => "git://path/to/git/repo/my_awesome_lib.git", :branch => "1.0"
# or just use as a gem (perhaps from your very own gem source):
# gem "my_awesome_lib", ">= 1.0.0"
@jvranish
jvranish / DetectDanger.c
Created July 9, 2012 16:13
Example detector function
#include "DetectDanger.h"
bool Detect_Ship_In_Danger(bool * const in_danger,
Position2D const detector1_pos,
Direction2D const detector1_ship_direction_time1,
Direction2D const detector1_ship_direction_time2,
Position2D const detector2_pos,
Direction2D const detector2_ship_direction_time1,
Direction2D const detector2_ship_direction_time2,
Position2D const hazard_pos,
@jvranish
jvranish / valueLevelClasses.hs
Created May 2, 2012 17:28
An experiment with mixing value level typeclasses and implicit parameters
{-# LANGUAGE Rank2Types
, RebindableSyntax
, ImplicitParams
, NoMonomorphismRestriction #-}
import Data.Maybe
import Data.Function
import Data.String
import Prelude (undefined, error, String, (++))
@jvranish
jvranish / arctan.py
Created April 25, 2012 02:00
Example Implementation of arctan(x)
def arctan(n, x):
if x > 1.0:
return math.pi/2.0 - my_preferred_arctan_implementation(n, 1/x)
else:
return my_preferred_arctan_implementation(n, x)
@jvranish
jvranish / WordpressIsEatingMyHaskell.hs
Created February 16, 2012 21:04
WordpressIsEatingMyHaskell
let result = do
account <- getAccount person
lastTransaction <- getLastTransaction account
getAmount lastTransaction
case result of
Nothing -> putStrLn "Oh noes!"
Just a -> putStrLn ("The amount was: " ++ show a)
-- Or really, I'd actually do this:
@jvranish
jvranish / AST.hs
Created December 31, 2011 20:50
Preliminary AST
{-#Language GeneralizedNewtypeDeriving #-}
module Language.TheExperiment.AST where
import Text.Parsec.Pos
import Language.TheExperiment.Type
data Literal = StringLiteral String
| CharLiteral Char
| IntegerLiteral Integer