Skip to content

Instantly share code, notes, and snippets.

View twright's full-sized avatar

Thomas Wright twright

View GitHub Profile
procedure TPerson.saveDetails (path : string);
var
output : text;
begin
try
assign (output, path);
if (fileexists (path)) then
append (output)
else
begin
// A finate state machine to perform email validation
function isValidEmail (address : string) : boolean;
var
i, j : integer;
invalidChars : string = '()[];:,<> ';
state : integer = 1;
localPartLength : integer = 0;
begin
result := false;
@twright
twright / newtonraphson.pas
Created January 28, 2010 20:01
Numerically solve equations in pascal - also includes a very basic equation parser
program main;
{$mode objfpc}{$H+}
uses
crt, sysutils;
type
wword = object
public
program Quiz;
{$mode objfpc}
uses sysutils, crt;
const
SEQ_LEN = 5;
NUM_FORMULAE = 4;
GUESSES = 2;
@twright
twright / primeFinder.c
Created June 29, 2010 16:59
Simple Eratosthenes sieve for finding prime numbers.
#include <stdio.h>
int main (int argc, char *argv[])
{
const MAX = 1000000;
int i; int j;
short isPrime[MAX];
for (i = 0; i <= MAX; ++i)
isPrime [i] = 1;
@twright
twright / main.cpp
Created October 28, 2010 17:14
Qt4 C++ Example
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
@twright
twright / autodate.pl
Created October 25, 2011 20:31 — forked from Browne/autodate.pl
Open source perl auto-updater for <lastmod> in XML sitemaps.
#!/usr/bin/perl
#######################################################################
#Basic perl script to update <lastmod> in an XML sitemap. #
#Works by seaching for .html files nested in <loc> and then comparing #
#to the file. It then inserts the date in the <lastmod> tag. #
# #
#This code is not subject to copyright and is free to use #
# #
#Eliot Brown 25/10/2011 #
@twright
twright / main.php
Created January 7, 2012 02:14
Easy Comment Uploads Files
<?php
/*
Plugin Name: Easy Comment Uploads
Plugin URI: http://wordpress.org/extend/plugins/easy-comment-uploads/
Description: Allow your users to easily upload images and files with their comments.
Author: Tom Wright
Version: 1.01
Author URI: http://gplus.to/twright/
License: GPLv3
*/
@twright
twright / awesome.py
Created January 30, 2012 21:19
The awesome program of James and Tom
# This is James' and Toms awesome game!
#
# This program creates a ball moving to the right, which bounces
# off a wall. It demonstrates the while loop and if statements.
#
# Import the Visual Python library
from visual import *
from random import randrange
from time import clock
@twright
twright / proof.tex
Created February 21, 2012 20:00
Example LaTeX proof
\[
A = \begin{bmatrix} 1 & 3 \\ 0 & 1 \end{bmatrix},\;
A^2 = \begin{bmatrix} 1 & 6 \\ 0 & 1 \end{bmatrix},\;
A^3 = \begin{bmatrix} 1 & 9 \\ 0 & 1 \end{bmatrix}
\]
\begin{prop}
\(A^n = \begin{bmatrix} 1 & 3n \\ 0 & 1 \end{bmatrix}\)
\begin{proof}