Skip to content

Instantly share code, notes, and snippets.

View twright's full-sized avatar

Thomas Wright twright

View GitHub Profile
@twright
twright / icar.c
Created June 3, 2012 21:38
What assembly does the ICAR example actually compile to?
int main(int argc, char const *argv[])
{
/* Declare variables */
int i;
int a[10];
int b[10] = {1,2,3,4,5,6,7,8,9,10};
int c[10] = {11,12,13,14,15,16,17,18,19,20};
/* The actual loop */
for (i = 9; i >= 0; --i) {
@twright
twright / turing_machine.pl
Created April 7, 2012 03:06
Perl6 turing machine
use v6;
my @tape = map { 0 }, 0..10;
my $state = 1;
#my @rules = (1,0,2,1,'r', 1,1,2,1,'l', 2,0,1,1,'l', 2,1,'h',1,'r');
my @rules = (1,0,2,1,'r', 1,1,'h',1,'r', 2,0,2,1,'l', 2,1,3,0,'r',
3,0,3,1,'l', 3,1,1,1,'l');
my $position = +@tape div 2;
my $halt = 0;
@twright
twright / math.p6
Created March 10, 2012 21:59
A perl6 mathematical expression parser
use v6;
grammar Math::Grammar {
token NonZeroDigit { <[1..9]> }
token Digit { <[0..9]> }
token Sign { <[+\-]> }
token OptionalSign { <Sign>? }
token Integer { <NonZeroDigit><Digit>* }
token Float { <Integer> \. <Digit>+ }
proto token Atom { <...> }
@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}
@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 / 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 / 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.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 / 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;
program Quiz;
{$mode objfpc}
uses sysutils, crt;
const
SEQ_LEN = 5;
NUM_FORMULAE = 4;
GUESSES = 2;