Skip to content

Instantly share code, notes, and snippets.

View sagebind's full-sized avatar
💭
Limited availability for Open Source

Stephen M. Coakley sagebind

💭
Limited availability for Open Source
View GitHub Profile
@sagebind
sagebind / Accessors.php
Created May 20, 2013 16:54
PHP trait that gives classes property accessor functionality.
<?php
use LogicException;
use BadMethodCallException;
trait Accessors
{
/**
* Gets the value of a property.
*
* @param string $name
@sagebind
sagebind / zombie-war.cpp
Created January 10, 2014 17:32
A simple game in C++ for a class exercise.
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
using namespace std;
int createZombie() {
if (rand() % 67 < 10)
return 11;
@sagebind
sagebind / Delegate.php
Last active August 29, 2015 14:10
Delegate
<?php
/*
* Copyright 2014 Stephen Coakley <me@stephencoakley.com>
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@sagebind
sagebind / MinGW-w64.sublime-build
Last active May 29, 2022 00:23
Sublime Text 3 C++ build system for mingw-w64
{
"cmd": ["g++", "-o", "${file_path}/${file_base_name}.exe", "-static-libgcc", "-static-libstdc++", "*.cpp"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.cpp, source.c++",
"path": "c:/Program Files/mingw-w64/mingw64/bin",
"shell": true,
"variants": [
{
"name": "Run",
@sagebind
sagebind / get-cppunit.sh
Created April 28, 2015 23:12
Install CppUnit on UW-Whitewater's servers
#!/bin/bash
# set up paths and colors
BOLD=`tput bold`
GREEN=`tput setaf 2`
NC=`tput sgr0`
LOCAL_PREFIX=$HOME/.usr
LOCAL_SRC=$LOCAL_PREFIX/src
PROJECT_DIR=`pwd`
CPPUNIT_PATH=$PROJECT_DIR/cppunit
# use local autotools
@sagebind
sagebind / Timer.php
Last active August 29, 2015 14:24
A simple timer class
<?php
/* The MIT License (MIT)
*
* Copyright (c) 2015 Stephen Coakley
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@sagebind
sagebind / Source.php
Created July 4, 2015 21:46
Interface definition for Zephyr event sources
<?php
/*
* Copyright 2015 Stephen Coakley <me@stephencoakley.com>
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@sagebind
sagebind / slack-example.php
Last active November 22, 2016 05:30
Example program using slack-client
<?php
require __DIR__ . "/vendor/autoload.php";
use React\EventLoop;
use Slack\ChannelInterface;
use Slack\RealTimeClient;
$loop = EventLoop\Factory::create();
@sagebind
sagebind / shallow-green.js
Created December 6, 2015 00:01
A.I. bot for Tronament
tronament.aiModule("shallow-green", function() {
var directions = [tronament.NORTH, tronament.EAST, tronament.SOUTH, tronament.WEST];
var iteration = 0;
this.onReady = function() {
// randomly choose a favored direction for the round
directions = shuffle(directions);
this.message("Ready, Freddy!");
}
@sagebind
sagebind / error.rs
Created April 23, 2016 03:52
Interesting error handling in Rust
use std::error;
use std::fmt;
use std::io::Write;
use std::process;
#[macro_export]
macro_rules! throw {
($e:expr) => (return Err($e))
}