Skip to content

Instantly share code, notes, and snippets.

View Xophmeister's full-sized avatar

Christopher Harrison Xophmeister

View GitHub Profile
@Xophmeister
Xophmeister / bp.d
Created June 28, 2012 13:28
Branch Prediction Benchmarking in D
import std.stdio, std.random, core.time;
void main() {
int data[32768];
foreach(ref x; data)
x = uniform(0, 256);
data.sort;
@Xophmeister
Xophmeister / msTimer.d
Created June 29, 2012 13:18
Just a silly little timer!
import std.stdio, core.time;
class msTimer {
TickDuration start;
this() { reset(); }
long split() { return (TickDuration.currSystemTick() - start).msecs(); }
void reset() { start = TickDuration.currSystemTick(); }
}
@Xophmeister
Xophmeister / gist:3040407
Created July 3, 2012 15:20
Playing with Primes in Python
import math
import random
class PrimeBuilder:
_p = set()
_maxChecked = 0
def __init__(self, p = {2, 3, 5}):
self._p = p
self._maxChecked = max(p)
@Xophmeister
Xophmeister / gist:3089424
Created July 11, 2012 10:09
Extreme E-Mail Obfuscation
<html>
<head>
<title>Extreme E-Mail Obfuscation</title>
<style>
.something-else {
font-size: 15pt;
}
</style>
<script>
@Xophmeister
Xophmeister / error.php
Created July 24, 2012 21:45
Simple, session-persistent error handling
<?php
class ErrorStack {
private $errorPage;
private $stack;
function __construct($errorPage = 'showErrors.php') {
$this->errorPage = $errorPage;
}
public function add($desc) {
@Xophmeister
Xophmeister / gist:3175460
Created July 25, 2012 10:28
OCI wrapper class for simplified Oracle handling
<?php
require_once "error.php";
class Oracle {
private $connection;
private $connected;
function __construct($connectionString, $username, $password) {
global $err;
@Xophmeister
Xophmeister / gist:3878629
Created October 12, 2012 10:37
Deserialise the query string in JavaScript
if (!window.query) {
(function () {
var match,
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(/\+/g, ' ')); },
query = window.location.search.substring(1);
window.query = {};
while (match = search.exec(query)) {
window.query[decode(match[1])] = decode(match[2]);
@Xophmeister
Xophmeister / negativeSpace.py
Created December 4, 2012 16:13
Linguistic White Noise Generator
import random
import itertools
import bisect
BNC = [
('the', 6187267),
('be', 4239632),
('of', 3093444),
('and', 2687863),
('a', 2186369),
@Xophmeister
Xophmeister / gist:4298357
Created December 15, 2012 19:20
ADO wrapper for VBA
' ADO Abstraction Class for VBA
' Christopher Harrison
' This is meant for simple, read-only access to an ODBC database (e.g., for
' report writing in Excel, etc.). It constructs parameterised queries, with
' optional varchar parameters (ordered, not named) passed as a collection.
' (SELECT statements, at least, are weakly typed (or can be casted), so using
' strings isn't really a concern.)
' Notes:
@Xophmeister
Xophmeister / gist:4442858
Last active December 10, 2015 13:48
JavaScript ordinals
Number.prototype.ordinal = function() {
return this < 0 ? undefined
: this + ['th', 'st', 'nd', 'rd'][this % 10 < 4 ? (this % 10) * (parseInt(this / 10, 10) % 10 == 1 ? 0 : 1) : 0];
}