Skip to content

Instantly share code, notes, and snippets.

View TheRayTracer's full-sized avatar

Simon Flannery TheRayTracer

  • Melbourne, Australia
View GitHub Profile
@TheRayTracer
TheRayTracer / main.cmd
Created May 9, 2012 13:13
A simple C++ implementation of the Levenshtein distance algorithm to measure the amount of difference between two strings.
main.exe kitten sitting
@TheRayTracer
TheRayTracer / main.sql
Created May 10, 2012 13:37
Example SQL setup using triggers to provide logging and auditing services. This file was prepared for SQL Lite, and the syntax would differ slightly for SQL Server and MySQL.
-- Work-a-round for SQL lite's lack of ENUM support.
CREATE TABLE enum(id INTEGER NOT NULL PRIMARY KEY, action VARCHAR(255) NOT NULL);
INSERT INTO enum VALUES (0, "INSERT");
INSERT INTO enum VALUES (1, "UPDATE");
INSERT INTO enum VALUES (2, "DELETE");
PRAGMA foreign_keys = ON;
-- Create a table to audit.
CREATE TABLE inventory(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name VARCHAR(255) NOT NULL, description VARCHAR(255), cost INTEGER NOT NULL, quantity INTEGER NOT NULL);
@TheRayTracer
TheRayTracer / main.cpp
Last active October 6, 2015 20:48
Example code to find the nth node from the end of a linked list using only one pass.
#include <iostream>
#include <assert.h>
namespace std { };
using namespace std;
struct node
{
node* next;
size_t data;
@TheRayTracer
TheRayTracer / main.cpp
Created December 5, 2012 09:16
An example of a greedy algorithm to implement a non-optimal scheduling solution.
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
namespace std { }
using namespace std;
@TheRayTracer
TheRayTracer / main.cpp
Created December 7, 2012 09:04
A quick implementation of Prim's algorithm to find the MST of a (connected) input graph.
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cassert>
namespace std { }
using namespace std;
struct edge
@TheRayTracer
TheRayTracer / main.cpp
Created December 16, 2012 05:55
A simple implementation of Kruskal's algorithm to determine a Minimum Spanning Tree. Also added an optional parameter to extend the base algorithm to supported a k number of clusters.
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
namespace std { }
using namespace std;
@TheRayTracer
TheRayTracer / main.cpp
Last active May 8, 2020 09:22
An example implementation to solve the knapsack problem. This includes a 2D and 1D array solution.
#include <iostream>
#include <fstream>
#include <vector>
#include <cassert>
namespace std { }
using namespace std;
struct item
{
@TheRayTracer
TheRayTracer / main.cpp
Last active December 11, 2015 01:19
A working implementation of the Bellman - Ford algorithm in C++. It will also detect and bail out if a negative cycle is detected.
#include <iostream>
#include <fstream>
#include <vector>
#include <cassert>
#include <limits>
#include <iomanip>
namespace std { }
using namespace std;
@TheRayTracer
TheRayTracer / main.cpp
Created August 2, 2013 01:27
A small random number generator.
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#define SAMPLE_SIZE 36000
namespace std { }
using namespace std;
@TheRayTracer
TheRayTracer / main.cpp
Created April 1, 2014 04:56
A simple implementation of a Bloom Filter using two hash functions. A Bloom Filter is used to test whether an element is a member of a set. False positive matches are possible, but false negatives are not; i.e. a query returns either "possibly in set" or "definitely not in set". This sample shows an example of a false positive.
#include <iostream>
#include <bitset>
#include <vector>
#include <cassert>
namespace std { }
using namespace std;
typedef size_t (*pHashFunc)(const char*);