Skip to content

Instantly share code, notes, and snippets.

View anthonybishopric's full-sized avatar
🚴

Anthony Bishopric anthonybishopric

🚴
View GitHub Profile
@anthonybishopric
anthonybishopric / gist:3915637
Created October 19, 2012 00:50
Inline C in PHP
<?php
// This is largely stolen from test.php in the Inline_C repo (https://github.com/pear/Inline_C/blob/master/test.php)
require_once("C.php");
$function1 = <<<EOF
PHP_FUNCTION(times)
{
long i,j;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &i,&j) == FAILURE) {
@anthonybishopric
anthonybishopric / extensions.md
Last active April 12, 2016 00:48
Interesting PHP Extensions. These aren't necessarily good to use right off the shelf, but serve as inspiration for things that could be built.
@anthonybishopric
anthonybishopric / parse-junit
Created October 18, 2013 17:55
Simple script to print errors in a junit-formatted xml file.
#! /usr/bin/env ruby
require "xmlsimple"
require "colored"
def parse_test_cases(test_cases)
test_cases.each do |test_case|
errs = test_case["failure"] || test_case["error"]
if errs
puts ("-->" + test_case["name"]).red
@anthonybishopric
anthonybishopric / Destructy.php
Last active December 19, 2015 20:08
Guess what $counter is!
<?php
function timer(callable $fn, $name, $freq=50000)
{
$start = microtime(true);
$start_mem = memory_get_usage(true);
$things = [];
for ($i = 0; $i < $freq; $i++)
{
$things[] = $fn();
@anthonybishopric
anthonybishopric / gist:5674518
Created May 29, 2013 23:02
Steven Cipolla's branch switching script
#!/bin/bash
OIFS=$IFS
IFS=$'\n'
count=10
if [ -n "$1" ]; then
count=$1
fi
@anthonybishopric
anthonybishopric / pat
Created December 20, 2012 17:58
cat with syntax highlighting
#! /usr/bin/env bash
# pip install -r Pygments
pygmentize -f terminal256 $1 2>/dev/null
if [ $? -ne 0 ]
then
cat $1
fi
@anthonybishopric
anthonybishopric / segmenter_helper.rb
Created June 17, 2011 02:15
A view helper to go along with SlyShy's TactfulTokenizer
module SegmenterHelper
def sentences(num_sentences, text)
@tactful_tokenizer ||= TactfulTokenizer::Model.new
result = @tactful_tokenizer.tokenize_text text
output = ""
0.upto([num_sentences, result.length].min - 1) do |i|
output << "#{result[i]} "
end
@anthonybishopric
anthonybishopric / gist:1000979
Created May 31, 2011 18:01
How to make Anthony happy
class You < Person
include Transportation
state_machine :wednesday_night, :initial => :no_plans do
before_transition :no_plans => :making_anthony_happy, :do => :come_to_dukegen_pitch_at_rocketspace!
end
def come_to_dukegen_pitch_at_rocketspace!
@anthonybishopric
anthonybishopric / rails3jsroutes.erb
Created May 28, 2011 19:43
Rails 3 routes in Javascript
<script type="text/javascript">
var __RouteCurry = function(route){
return function(options){
var routeMod = route;
if (typeof options == "string" || typeof options == "number"){
routeMod = routeMod.replace(/:[a-zA-Z0-9\_]+/,options);
}
else{
for(key in options){
routeMod = routeMod.replace(":"+key, options[key]);
#!/usr/bin/env ruby
require 'optparse'
options = {source: File.expand_path("~/.profile-remote"), target: "~/.profile"}
OptionParser.new do |opts|
opts.banner = "Copy a .profile script to a machine for sshing to it.\nUsage: shush [options] host"
opts.on("-s", "--source SOURCE", "The source profile file. Default is ~/.profile-remote") do |s|
options[:source] = File.expand_path(s)