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 / 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
@TheRayTracer
TheRayTracer / main
Last active August 29, 2015 14:19
Two puzzles solved using Python. 1. The classic "Make 4 litres from only a 3 litre and 5 litre jug without markings except of a total volume" problem. Two methods are illustrated using a simple Jug class. 2. Maximising the profit by buying low and selling high from yesterday's stock prices.
class jug:
def __init__(self, size):
self.size = size
self.volume = 0
self.waste = 0
def empty(self):
self.waste = self.waste + self.volume
self.volume = 0
@TheRayTracer
TheRayTracer / chart.png
Last active August 29, 2015 14:10
A small collection of scripts to simulate and analyse a game of Monopoly.
chart.png
@TheRayTracer
TheRayTracer / cpuid.h
Last active August 29, 2015 14:06
Utility of functions that help to determine specific CPU features, including determining the vendor of the CPU.
#ifndef CPUID_H
#define CPUID_H
#include <memory.h>
#define FAMILY_ID 0x0000F00
#define EXT_FAMILY_ID 0x0F00000
#define PENTIUM4_ID 0x0000F00
@TheRayTracer
TheRayTracer / iris_classification_results.png
Last active August 14, 2017 09:44
This R script demonstrates Machine Learning and classification using the Caret package. First, the Iris set is divided into a training set and a test set. Secondly, the model is trained. Then, predictions are queried and accuracy is calculated. Lastly, RoC curves are plotted for evaluation. Plots are generated for each step.
iris_classification_results.png
@TheRayTracer
TheRayTracer / main.cpp
Created April 30, 2014 10:38
Computes epsilon - the smallest value such that, when added to 1, is still distinguishable from 1.
#include <iostream>
#include <limits>
#include <cassert>
namespace std { }
using namespace std;
/* Computes the smallest value such that, when added to 1, is still distinguishable from 1. */
template<typename T>
int epsilon(T& eps)
@TheRayTracer
TheRayTracer / main.cpp
Last active August 29, 2015 14:00
This code sample parses the results from a machine learning algorithm to produce receiver operating characteristic (ROC) curves. The curve plot points must be manually charted in an external application such as a spreadsheet application.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cassert>
@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.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
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;