Skip to content

Instantly share code, notes, and snippets.

View beporter's full-sized avatar

Brian Porter beporter

View GitHub Profile
@beporter
beporter / synergyc_launch.command
Last active December 27, 2015 04:19
Read the first comment.
#!/bin/bash
# Starts the Synergy client via command line on a Mac.
# Set (at least) the SERVER_IP to the IP of your Synergy server computer.
# beporter@users.sourceforge.net, 2013-11-01
SERVER_IP=192.168.x.x
DIR="$( cd -P "$( dirname "$0" )"/.. && pwd )"
LOG_PATH="$DIR/synergy.log"
LOG_LEVEL=WARNING
SYNERGYC=/Applications/Synergy.app/Contents/MacOS/synergyc
@beporter
beporter / select_options.php
Last active August 29, 2015 13:57
Handle PHP associative and indexed array in a single loop
<?php
//--------------------
function brian($i) {
foreach ($i as $value => $name) {
$value = (is_string($value) ? $value : $name);
echo '<option value="' . $value . '">' . $name . '</option>' . PHP_EOL;
}
}
@beporter
beporter / human_filesize.php
Created March 27, 2014 22:50
Convert an integer byte value into a human-readable file size.
<?php
//----------
// Only works with INTEGER values for $bytes.
function human_filesize($bytes, $decimals = 2) {
$sz = 'BKMGTP';
$bytes = (int)$bytes; // This process only works with integer $byte values.
$factor = floor((strlen($bytes) - 1) / 3); // Determine the correct range.
$s = $bytes / pow(1024, $factor); // Knock out the right number of exponents.
$s = sprintf("%.{$decimals}f", $s) + 0; // Clean up decimals, `+0` removes trailing zeroes.
@beporter
beporter / php_empty_iterator_test.txt
Last active August 29, 2015 14:01
Attempting to call PHP's `EmptyIterator->current()`
$ php -r '$i = new EmptyIterator(); echo $i->current();'
PHP Fatal error: Uncaught exception 'BadMethodCallException' with message
'Accessing the value of an EmptyIterator' in Command line code:1
Stack trace:
#0 Command line code(1): EmptyIterator->current()
#1 {main}
thrown in Command line code on line 1
Fatal error: Uncaught exception 'BadMethodCallException' with message
@beporter
beporter / bash_prompt.sh
Created June 2, 2014 14:57
Bash Prompt
. /etc/bashrc # Pull in the update_terminal_cwd() function.
export PROMPT_COMMAND="prompt_cmd; update_terminal_cwd"
function prompt_cmd {
# Must be obtained early before any other commands run and exit!
EXITSTATUS="$?"
# regular colors
local K="\[\033[0;30m\]" # black
local R="\[\033[0;31m\]" # red
@beporter
beporter / README.md
Last active August 29, 2015 14:03
Provides a pre-composer mechanism for setting up a copy of the CakePHP core project in a local directory and then symlinking it into a target Cake project path.

CakePHP Core Setup

These scripts automate the process of obtaining a copy of the CakePHP core at a specific point release, the latest point release for a minor version, or a specific commit. They also provide a way to symlink the Cake core into an existing Cake project, which is handy for keeping all of the core files out of your project repo.

Usage

  • Place add-cakephp-version.sh in a folder of its own.

  • Run ./add-cakephp-version.sh x.y[.z] (where x is a major version number, y is a minor version number and z is an optional point release) to clone the CakePHP official git repository and set up a folder named cake_x.y.z in the same folder as the script.

@beporter
beporter / BasicIterator.php
Created August 6, 2014 16:42
PHP Iterator Tutorial
<?php
class BasicIterator extends FilterIterator {
public function __construct($pathToFile) {
// Call the parent constructor with an SplFileObject (also Traversable) for the given path.
parent::__construct(new SplFileObject($pathToFile, 'r'));
// These set up the inner SplFileObject's properties to process CSV.
$file = $this->getInnerIterator();
$file->setFlags(SplFileObject::READ_CSV);
@beporter
beporter / synergy_history.md
Last active June 20, 2017 12:22
History of the Synergy Project's "Bug #18 - Sticky modifier/meta keys (shift, ctrl, alt)" (now #9)

This is a crude list of stuff the Synergy team has chosen to focus on instead of an extremely old (and still unsolved) bug.

@beporter
beporter / vmnetshop.sh
Last active March 31, 2020 04:46
Shut down VM network bridges on a Mac
#!/usr/bin/env bash
#
# If you're like me and have to switch between VMware Fusion and
# VirtualBox virtual machines on your Mac frequently, then you've
# probably run into one of the associated errors in this gist
# (https://gist.github.com/beporter/2841de37edbcc48a8755), particularly
# if you're using vagrant. This script shuts down or removes the bridge
# interfaces from BOTH providers so that they can start up cleanly again
# without conflicting with each other and without having to reboot your
# Mac.
@beporter
beporter / monitor-500.sh
Last active August 29, 2015 14:08
Monitor a URL for HTTP 500 errors using a crude shell script.
#!/usr/bin/env bash
#
# Takes a URL as an argument. Will test that URL every X seconds for a
# 500 response code. If a 500 is returned, this script will ring the
# terminal's bell and print a message.
#
# Ref: http://beerpla.net/2010/06/10/how-to-display-just-the-http-response-code-in-cli-curl/
#
# Usage: ./monitor-500.sh "http://yoursite.com/your/page.html"
#