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 / 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
import time
import notify2
from abc import ABCMeta
from jenkinsapi.jenkins import Jenkins
class JenkinsPoller():
__metaclass__ = ABCMeta
@samueljackson92
samueljackson92 / arduino_code.ino
Created September 18, 2014 10:38
Arduino serial communication
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
const int sensorPin = A0;
const int messageBufferSize = 17;
char messageBuffer[17];
void read_serial()
{
char inputChar = -1;
@samueljackson92
samueljackson92 / R_scatter
Last active August 29, 2015 14:16
Scatterplot example in R
args <- commandArgs(trailingOnly = TRUE)
file_name <- args[1]
library('ggplot2')
data_df <- read.csv(file_name, header=TRUE)
plot <- ggplot(data_df, aes(x=X0, y=X1)) + geom_point(aes(color=class))
# Remove ticks marks from plot
plot + scale_y_discrete(breaks=NULL) + scale_x_discrete(breaks=NULL)
"""Showing the cool stuff which functools does"""
import functools
def print_shit(f):
"""Because Sam, you need to learn why decorators are sexy.
Plus, functool.wraps() is a _very_ important tool, yo
"""
@functools.wraps(f)
def inner(*args, **kwargs):
@samueljackson92
samueljackson92 / git-revert-merges
Last active August 29, 2015 14:27
Bash git script to revert n pull requests from a git repo. The command will squash each of the reverts into a single commit to keep the history cleaner. A commit message must also be supplied as an argument.
#!/bin/bash
usage="$(basename "$0") [-h] <n> <commit-message> -- revert back n pull requests
where:
-h show this help text"
while getopts ':h:' option; do
case "$option" in
h) echo "$usage"
exit
@samueljackson92
samueljackson92 / grades.csv
Created September 20, 2015 15:50
Module results for my course so far
Module Name Grade
CS10110 Introduction To Computer Hardware, Operating Systems And Unix Tools 87.0
CS10410 The Mathematics Driving License For Computer Science 95.0
CS12130 Concepts In Programming 87.0
PH19510 Chaos, Communications And Consciousness 90.0
CS12420 Software Development 91.0
CS15020 Web Development Tools 94.0
CS15210 An Introduction To Communications And Telematics 66.0
CS18010 Professional And Personal Development 71.0
CS20410 The Advanced Mathematics Driving License For Computer Science 70.0
@samueljackson92
samueljackson92 / concatdir.pl
Created November 12, 2012 17:43
Perl script to concat directories full of text files.
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use File::Find::Rule;
#Perl script for combining sub directories of text files
GetOptions('recursive' => \my $isRecursive,
@samueljackson92
samueljackson92 / sierpinskicarpet.pl
Created November 12, 2012 17:39
Generating a sierpinski carpet with a perl script
#!/usr/bin/perl
use strict;
use warnings;
my @carpet;
my $total;
carpet(2);
foreach my $row(@carpet){