Skip to content

Instantly share code, notes, and snippets.

View Wollw's full-sized avatar

David E. Shere Wollw

View GitHub Profile
@Wollw
Wollw / ref_example.cpp
Created October 20, 2011 05:43
C++ References Example
#include <iostream>
using namespace std;
void addFiveToNum(int &n);
int main() {
int myNumber1 = 10;
int myNumber2 = 20;
cout << "Before" << endl << "------" << endl;
@Wollw
Wollw / c_object.c
Created November 2, 2011 10:51
A simple (if flawed) implementation of an object in C.
/*
* A simple example of an object in ANSI C.
* It would be better to have initAdder simply call malloc
* and return a pointer to the new object (and be preferable too)
* as this would allow for freeing of objects too but for the sake of
* simplicity I've opted to pass it a pointer instead.
*
* Note that with C++ the "this" variable is pretty much just implicit.
*
*/
@Wollw
Wollw / object_malloc.c
Created November 2, 2011 11:34
A simple implementation of an object in C using malloc an free for creation and destruction.
/*
* A simple example of an object in ANSI C.
* This example uses malloc to create the new object.
*
* Note that with C++ the "this" variable is pretty much just implicit.
*
*/
#include <stdio.h>
#include <stdlib.h>
@Wollw
Wollw / insertat.c
Created February 14, 2012 01:09
insertion function example
#include <stdio.h>
/* This insertAt function takes an index to insert at "i",
* a number to insert into the integer array "num", a pointer
* to the current number of used spaces in the array "numUsed",
* and a pointer to the array "a".
*
* This assumes that the array is big enough to insert a new element
* for the sake of simplifying the example so it doesn't check against
#include <stdio.h>
int main() {
char s1[256],s2[256],s3[256];
int i;
sscanf("MPTRAY=FIRST [3 ENUMERATED READONLY]",
" %s [%d %s %s]",
s1, &i, s2, s3);
#include <iostream>
using namespace std;
void change_array(int a[], int i, int n) {
a[i] = n;
}
int main() {
int a[] = {1,2,3,4,5,6};
change_array(a, 3, 789);
@Wollw
Wollw / wavelet.c
Created March 1, 2012 04:54
Wavelet Tree
/*
* An implementation of the Wavelet Tree data structure.
* It is similar to a binary search tree using bits.
*
* More info here:
* http://siganakis.com/challenge-design-a-data-structure-thats-small
* http://www.alexbowe.com/wavelet-trees
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
int points[100000][2];
int i, j, k;
int q;
int count[4];
inline void mirror() {
i--;
/*
* This is a parser intended for Common Log Format access logs.
* It splits on whitespace unless it is part of a field delimited by
* square brackets or double quotes.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "parser.h"
@Wollw
Wollw / x11.go
Created March 19, 2012 18:20
Simple X11 Window in Go
package main;
import (
"exp/gui"
"exp/gui/x11"
"image"
)
func main() {
w,_ := x11.NewWindow()