Skip to content

Instantly share code, notes, and snippets.

View stut's full-sized avatar

Stuart Dallas stut

View GitHub Profile
@stut
stut / stopwords.txt
Created April 6, 2022 14:58
Stopwords
http
https
ftp
ftps
sftp
rt
a
able
about
above
/***********************************************************************
MySQL Session class
This class encapsulates everything needed to store your PHP sessions
in a MySQL database. To use it simply call Session::start() instead
of session_start().
You'll need a table like this in your database. You can change the
name but the fields should remain as they are defined here.
@stut
stut / 1-table.class.php
Last active May 31, 2016 19:16
PHP models
<?php
// Table: An ActiveRecord-style DB abstraction class
// Copyright (c) 2005-2006 Stuart Dallas
// Released into the public domain with absolutely no warranty, explicit, implied or otherwise
// Use at your own risk!!
// If you do use this code please drop an email to code at stut dot net and let me know why ;)
// Patches, comments, suggestions, questions, etc are welcomed
// The MODEL_CACHE_DIR is where the table definitions get cached. This can be anywhere you like, defaults to cache/
@stut
stut / montyhall.c
Last active April 12, 2016 00:44
Test the Monty Hall problem
#include <stdio.h>
#include <stdlib.h>
#define rand3() ((int)(rand() % 3)+1)
void seedrand()
{
unsigned int randval;
FILE *f;
@stut
stut / gist:6438640
Last active November 3, 2020 03:00
100 first names and 100 last names.
<?php
$first_names = array(
'Abigail', 'Alice', 'Amber', 'Amelia', 'Amy', 'Ava', 'Brooke',
'Caitlin', 'Charlotte', 'Chloe', 'Daisy', 'Elizabeth', 'Ella', 'Ellie',
'Emily', 'Emma', 'Erin', 'Eva', 'Evie', 'Freya', 'Grace', 'Hannah',
'Holly', 'Imogen', 'Isabel', 'Isabella', 'Isabelle', 'Isla', 'Jasmine',
'Jessica', 'Katie', 'Keira', 'Leah', 'Lilly', 'Lily', 'Lola', 'Lucy',
'Matilda', 'Megan', 'Mia', 'Millie', 'Molly', 'Olivia', 'Phoebe',
'Poppy', 'Ruby', 'Scarlett', 'Sophia', 'Sophie', 'Summer', 'Adam',
'Alex', 'Alexander', 'Alfie', 'Archie', 'Benjamin', 'Callum',
@stut
stut / ilogger.php
Last active December 17, 2015 10:59
Interface example
<?php
// Logger interface.
interface iLogger
{
public function __construct();
public function write($str);
}
@stut
stut / dice.py
Created April 20, 2012 13:43
Python Dice Roller
# -*- coding: utf-8 -*-
"""
Dice
Part of rollnmove
Copyright © 2011-2012 Stuart Dallas
"""
import random
@stut
stut / incoming_mail.php
Created November 12, 2011 11:20
Twitter email notification processor from TwitApps v1
#!/usr/bin/env php
<?php
// The email address notifications should be sent to
$____email_address = 'contact@twitapps.com';
// This array maps incoming emails to scripts
$____processor_map = array(
// For the ta_follows user there's a separate script for each notification type
'ta_follows' => array(
'is_following' => dirname(__FILE__).'/ta_follows/new_follower.php',
@stut
stut / gist:1124666
Created August 4, 2011 07:42
IsMobile function
<?php
function IsMobile()
{
$retval = false;
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$accept = $_SERVER['HTTP_ACCEPT'];
if (preg_match('/ipod/i', $user_agent)
||