Skip to content

Instantly share code, notes, and snippets.

View sw17ch's full-sized avatar

John VanEnk sw17ch

View GitHub Profile
@sw17ch
sw17ch / bad_way.c
Created February 15, 2012 04:28
bad_way.c
#include "interface.h"
void initialize(void)
{
puts("Common Initialize\n");
#if defined(PLATFORM_A)
puts("Initialize A\n");
#elif defined(PLATFORM_B)
puts("Initialize B\n");
#include "interface.h"
void initialize(void)
{
puts("Common Initialize\n");
#if defined(PLATFORM_A)
puts("Initialize A\n");
#elif defined(PLATFORM_B)
puts("Initialize B\n");
#ifndef __INTERFACE__
#define __INTERFACE__
void initialize(void);
void do_stuff(void);
void cleanup(void);
#endif /* __INTERFACE__ */
#include <stdio.h>
#include "common.h"
#include "interface.h"
void initialize(void)
{
common_initialize();
puts("Initialize A\n");
}
#include <stdio.h>
#include "common.h"
#include "interface.h"
void initialize(void)
{
common_initialize();
puts("Initialize B\n");
}
@sw17ch
sw17ch / gist:1901197
Created February 24, 2012 14:17 — forked from manlycode/gist:1896012
Can I use a buffer overflow exploit with this code, or is it secure?
int truncate_and_call(fn_ptr *fns, int index, char *user_string)
{
char buf[64];
// Truncate supplied string
strncpy(buf, user_string, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = '\0';
return fns[index](buf);
}
@sw17ch
sw17ch / random_ast.txt
Created February 29, 2012 05:11
Pretty printed randomized abstract syntax tree for Job and my language. Well, AST for the types at least.
Rx2Hlvk (Qy,
nUD,
t9,
zYH9 N
ksyIBG
qdE
lTq,
p -> (-> BIYUk))
J
(Pd9VS B4UHTB
@sw17ch
sw17ch / gist:2017131
Created March 11, 2012 17:04
Arbitrary type signatures are *still* ugly.
PRhIBRoYtbd5wqmJc1,
p2Zaa,
OtV4mBDJAEb19,
rAK_02Df7vsHH,
daQoBMUx9Aj7YDUMJ,
LlezBIRdO2YNa,
uzv,
wj evM
e2gSpGd0J1UTmebP_V
j1NdPRUoE
This example depends on parsec >= 3.0 and the indents package >= 0.3.2.
To install indents, run the following command:
cabal install indents
> module Main where
> import Text.Parsec
> import Text.Parsec.Indent
@sw17ch
sw17ch / simple_parser.hs
Created March 16, 2012 03:08
An example of a simple parser for my blog post about Text.Parsec.Indent.
module Main where
import Text.Parsec
import Text.Parsec.String
input_text :: String
input_text = "foo123:"
main :: IO ()
main = do