Skip to content

Instantly share code, notes, and snippets.

View aholmes's full-sized avatar

Aaron Holmes aholmes

View GitHub Profile
@aholmes
aholmes / apc_overloads.php
Created December 23, 2013 19:49
Overload apc_fetch and apc_add as a quick replacement for APC methods on systems that don't support it (like PHP 5.5 on OSX). These methods are not an exact reimplementation of the defined documentation on http://php.net. TTL is ignored, for one.
<?php
// apc crashed on my dev box, so overload the methods if they don't exist
if (!function_exists('apc_fetch')) {
function apc_fetch($key, &$success) {
if (!($filename = apc_get_tmpfile($key, $f))) {
return false;
}
if (!($d = fread($f, filesize($filename)))) {
@aholmes
aholmes / Traverse.php
Last active January 2, 2016 14:49
The OOP version of https://igor.io/2014/01/08/functional-library-traversal.html for ghits and shiggles.
<?php
class Traverse implements ArrayAccess {
protected $container;
function __construct($array) {
$this->container = $array;
}
public function offsetExists($offset) {
return isset($this->container[$offset]);
}
#!/bin/bash
FAILURE=0
do_tasks() {
if [[ $FAILURE -eq 0 ]]; then
echo -e "Running tasks\n"
some_command &
some_command &
some_command &
<?php
class HTTP {
protected _statusCode;
protected function _getStatusCode() {
return $this._statusCode;
}
protected _url;
protected function _getUrl() {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using Newtonsoft.Json;
<?php
class Result {
public $id;
public $foo = 'bar';
function __construct() {
$this->id = rand(0,9999);
}
}
@aholmes
aholmes / bst-timing.php
Created January 22, 2014 22:39
Reimplementation of "The Mysterious Program." https://stripe-ctf.com/
<?php
$words = file('/usr/share/dict/words');
function generateBTree($input) {
$tree = [];
$p = $tree;
foreach($input as &$word) {
$word = trim($word);
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
</head>
var queued = [], scrollTimeout, waitForQueueTimeout;
function queueMore() {
Array.prototype.filter.call(document.querySelectorAll('a.UFILikeLink[title*="Like this"]'), function(a) {
if (queued.indexOf(a) === -1) {
queued.push(a);
}
});
}
#define DURP <stdio.h>
#define DQRP static
#define DIRP int
#define DFRP main()
#define DVRP(X,Y) printf(X,Y)
#define DYRP(X) return X
#define DGRP {
#define DJRP }
#define DORP 0
#define DNRP 1