Skip to content

Instantly share code, notes, and snippets.

View samueljackson92's full-sized avatar

Samuel Jackson samueljackson92

  • STFC
  • Wallingford, Oxfordshire, UK
View GitHub Profile
@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 / 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 (samueljackson@outlook.com)
# 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 / 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 (samueljackson@outlook.com)
# Date: 21/07/2013
# Description: Performs Otsu's method of thresholding
# using the between class variance.
#######################################################
@samueljackson92
samueljackson92 / quirk.js
Created July 28, 2013 08:25
JS formatting quirk
function foo() {
return {
bar : "Hello World!"
}
}
function foo2()
{
return
{
@samueljackson92
samueljackson92 / sieve.py
Created August 4, 2013 14:15
Sieve Of Eratosthenes
#!/usr/bin/env python
################################################
# Sieve Of Eratosthenes
# Implementation the sieve of eratosthenes for
# finding all prime numbers up to a given limit
# Author: Samuel Jackson (slj11@aber.ac.uk)
# Date: 4/8/13
################################################
@samueljackson92
samueljackson92 / config.json
Created November 23, 2013 09:02
Secret Santa program. Takes a list of names and emails and some details to connect to an SMTP server and pairs each person with another person and sends out emails to each participant informing them who they are secret Santa for.
{
"email": "example@gmail.com",
"password": "yourpasswordhere",
"server": "smtp.gmail.com",
"port": 587
}
5.1,3.5,1.4,0.2,Iris-setosa
4.9,3.0,1.4,0.2,Iris-setosa
4.7,3.2,1.3,0.2,Iris-setosa
4.6,3.1,1.5,0.2,Iris-setosa
5.0,3.6,1.4,0.2,Iris-setosa
5.4,3.9,1.7,0.4,Iris-setosa
4.6,3.4,1.4,0.3,Iris-setosa
5.0,3.4,1.5,0.2,Iris-setosa
4.4,2.9,1.4,0.2,Iris-setosa
4.9,3.1,1.5,0.1,Iris-setosa
@samueljackson92
samueljackson92 / timed.py
Created January 6, 2014 14:02
Simple decorator to wrap a function and print out some basic profiling information.
def timed(f):
import cProfile, pstats, StringIO
def wrap(*args):
#start profiling
pr = cProfile.Profile()
pr.enable()
#execute function
ret = f(*args)
@samueljackson92
samueljackson92 / sequence_compress.py
Created March 28, 2014 10:49
Script to compress linear sequences of numbers as a strings with repeating sections taking the form: start:width:stop
import numpy as np
def findSequence(x, delta_x, start=0):
string = ""
if len(x) == 1: return str(x[0]) + ','
if len(x) == 2: return str(x[0]) + ',' + str(x[1]) + ','
while (start<delta_x.size-1):
end = start+1
@samueljackson92
samueljackson92 / const.cpp
Created April 29, 2014 08:38
Constants in C++
const int* p; // the thing pointed to is const, you can change the value of p
int const *q; // same as p
int * const r; // the pointer is const, but the thing pointed to can change value
int const * const s; // the pointer is const and the thing pointed to is const