Skip to content

Instantly share code, notes, and snippets.

View samueljackson92's full-sized avatar

Samuel Jackson samueljackson92

  • UKAEA
  • Wallingford, Oxfordshire, UK
View GitHub Profile
@samueljackson92
samueljackson92 / otsu.py
Last active December 24, 2020 04:15
Otsu's method of thresholding. Partially based on the implementation shown at: http://www.labbookpages.co.uk/software/imgProc/otsuThreshold.html
#!/usr/local/bin/python
#######################################################
# Otsu's Method
# Author: Samuel Jackson ([email protected])
# Date: 21/07/2013
# Description: Performs Otsu's method of thresholding
# using the between class variance.
#######################################################
@samueljackson92
samueljackson92 / kmp_search.py
Created July 20, 2013 15:52
Knuth-Morris-Pratt (KMP) substring searhc algorithm implementation in python
#######################################################
# Knuth-Morris-Pratt Algorithm
# Author: Samuel Jackson ([email protected])
# Date: 20/07/2013
#######################################################
# implementation of KMP Search
def kmp_search(s, w):
m = 0 # current search start point
i = 0 # current index in target word
@samueljackson92
samueljackson92 / variance.cpp
Created June 11, 2013 19:57
Accurately compute variance and standard deviation in one pass. Source: http://www.johndcook.com/blog/2013/06/11/computing-skewness-and-kurtosis-in-one-pass/
class RunningStat
{
public:
RunningStat() : m_n(0) {}
void Clear()
{
m_n = 0;
}
@samueljackson92
samueljackson92 / stuff.tex
Created April 22, 2013 12:45
ACM Proceeding template
\documentclass{acm_proc_article-sp}
\usepackage{graphicx}
\usepackage{epstopdf}
\begin{document}
\title{A Comparison of Scheduling Algorithms}
\numberofauthors{1}
\author{
\alignauthor
@samueljackson92
samueljackson92 / priority.java
Last active December 15, 2015 14:28
Weight priority selection.
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
new Main().calcSlot(7);
}
public int calcSlot(int priority) {
//list of jobs
@samueljackson92
samueljackson92 / delta.cpp
Created March 21, 2013 17:53
C/C++ code for calculating delta time. Output in seconds.
timeval t1, t2;
double elapsedTime;
//start timer
gettimeofday(&t1, NULL);
//do stuff...
//stop timer
gettimeofday(&t2, NULL);
@samueljackson92
samueljackson92 / JSONExample.js
Created March 12, 2013 14:36
JSON object notion example for Connor
var ar = {
"Hello": {
score: 12,
run: function()
{
return "hi";
}
}
};
@samueljackson92
samueljackson92 / image.tex
Created February 19, 2013 23:17
LaTeX code for importing, formatting, centring, captioning and labelling an image. Will force images to follow after each other and stay in the same section. Compliments of @cgddrd
% Include the required packages.
\usepackage{float}
\usepackage{graphicx}
% insert a single centred image into a LaTeX document.
\begin{figure}[H]
\centering
\includegraphics[width=0.7\textwidth]{<path-to-file>}
\caption{<image-caption>}
\label{fig:<image label>}
@samueljackson92
samueljackson92 / fuzzy.py
Created February 11, 2013 16:25
Fuzzy set logic tipping system python code.
#!/usr/bin/env python
#####################################################
#Fuzzy logic implementation of simple tipping system
#Author: Samuel Jackson ([email protected])
#Date: 10/2/13
#####################################################
#################################
# Functions for calculating #
@samueljackson92
samueljackson92 / simple_graph.py
Created February 4, 2013 17:46
A python script that defines a simple graph data structure.
################################################
# Simple Graph
# Author: Samuel Jackson
# Created: 28/1/13
################################################
class Node:
def __init__(self, data):
self.adjacents = []
self.set_data(data)