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 / mushrooms_explore_a.png
Last active October 6, 2022 20:30
Using R to explore the UCI mushroom dataset reveals excellent KNN prediction results.
mushrooms_explore_a.png
@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*);
@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 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 / SSD1331.py
Last active March 12, 2020 13:18
The below Python source files control an OLED display (size 96 x 64, 65K colours) using a SSD1331 chipset and the SPI interface. The source code initialises the chipset and includes hardware accelerated functions for drawing primitive shapes and a non-hardware accelerated full ASCII set. Examples include a basic Space Invaders game, and a clock.
import struct
import spidev
import sys
import time
import random
import RPi.GPIO as gpio
ascii = [
[ 0x55, 0x00, 0x55, 0x00, 0x55 ],
[ 0x55, 0x00, 0x55, 0x00, 0x55 ],
@TheRayTracer
TheRayTracer / activity1.png
Last active December 11, 2019 03:40
Basic example of a 555 timer flashing led circuit from first principles. Source is from a 5V USB adaptor.
activity1.png
@TheRayTracer
TheRayTracer / SSD1306.py
Last active August 4, 2019 00:03
The below Python source controls an OLED display (size 128 x 64) using a SSD1306 chipset and the SPI interface. The source code initialises the chipset setting the 2 orange pages at the top of the display, and includes functions for drawing primitive shapes and a full ASCII set.
import struct
import spidev
import sys
import time
import random
import RPi.GPIO as gpio
ascii = [
[ 0x55, 0x00, 0x55, 0x00, 0x55 ],
[ 0x55, 0x00, 0x55, 0x00, 0x55 ],
@TheRayTracer
TheRayTracer / SSD1351.py
Last active August 3, 2019 23:59
The below Python source files implement an OLED display driver for the SSD1351 chipset using the SPI interface. The source code provides an interactive example – the classic Snake game that minimise screen redraw and makes use of the Curses library.
import struct
import spidev
import sys
import time
import random
import RPi.GPIO as gpio
ascii = [
[ 0x55, 0x00, 0x55, 0x00, 0x55 ],
[ 0x55, 0x00, 0x55, 0x00, 0x55 ],
@TheRayTracer
TheRayTracer / lm75a.sh
Created November 8, 2015 11:20
This entry contributes a simple Bash script to query and control a LM75 Digital Temperature Sensor via I2C. The second Bash script is a utility to interact with a real-time clock (RTC). The third entry is a Python script for a mini web server to retrieve the temperature in either Celsius (default) or Fahrenheit. These were a few very fun weekend…
#!/bin/bash
readonly lm75=0x48 # Slave address with A0, A1, and A2 set to 0v (ground).
while [ $# -gt 0 ]
do
if [ "$1" == "-debug" ]
then
debug=true
fi