Skip to content

Instantly share code, notes, and snippets.

@joemaller
joemaller / array_sortByKey.php
Created January 22, 2013 03:06
This works, but not well enough. Needs better handling of undefined values and arranging things in fixed lengths. For example, if there three items and only one has a sort key, but it's sort key asks to be in the second place, then the item specifying spot two should get spot two and all the undefined items should maintain order around it. Funda…
public function array_sortByKey($arr, $key)
{
$sort_on_key = function ($a, $b) use ($key) {
$a[$key] = (isset($a[$key])) ?: null;
$b[$key] = (isset($b[$key])) ?: null;
return strnatcmp($a[$key], $b[$key]);
};
usort($arr, $sort_on_key);
return $arr;
}
@joemaller
joemaller / Bash color Git branch.sh
Last active December 25, 2015 16:12
A bash function for coloring the current git branch. Red for dirty, yellow if all files are staged and clean is green. This uses the color functions from https://gist.github.com/4503986
# https://gist.github.com/joemaller/4527475
#
# A simple bash function for coloring the current git branch.
# - Red: Tree is dirty
# - Yellow: All modified files are staged
# - Green: Tree is clean
#
# This uses the color functions from https://gist.github.com/4503986
function git_branch() {
@joemaller
joemaller / Vagrantfile
Last active December 30, 2015 22:18
Troubleshooting Vagrant 1.4 NFS problems. Testing on a Mac with VirtualBox 4.3.4. VMs work correclty on first `up`, then fail on reload with this error: "No guest IP was given to the Vagrant core NFS helper. This is an internal error that should be reported as a bug." Precise32 box fails on first reload (precise64 also fails on reload). Lucid32 …
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
@joemaller
joemaller / gist:33fea86a9b313d2359cd
Last active February 5, 2016 16:05
IPTables command to block attempted logins to our office server, mostly out of China. These commands don't attempt to isolate single IPs, they just ban the entire subnet.
iptables -I FORWARD -s 89.248.167.139 -j DROP
iptables -I FORWARD -s 112.33.0.0/16 -j DROP
iptables -I FORWARD -s 113.194.0.0/16 -j DROP
iptables -I FORWARD -s 113.195.0.0/16 -j DROP
iptables -I FORWARD -s 115.230.0.0/16 -j DROP
iptables -I FORWARD -s 115.231.0.0/16 -j DROP
iptables -I FORWARD -s 115.239.0.0/16 -j DROP
iptables -I FORWARD -s 117.21.0.0/16 -j DROP
iptables -I FORWARD -s 117.25.0.0/16 -j DROP
iptables -I FORWARD -s 218.25.0.0/16 -j DROP
@joemaller
joemaller / hamster-dance.sh
Created April 1, 2016 19:01
prank shell script, plays hamster dance YouTube loud. Sadly can't deal with headphones
#!/usr/bin/env bash
osascript -e "set Volume 10"
open "https://www.youtube.com/watch?v=6WpMlwVwydo"
osascript -e 'if application "Google Chrome" is running then' -e'tell app "System Events" to set visible of process "Google Chrome" to false' -e 'end'
osascript -e 'if application "Safari" is running then' -e'tell app "System Events" to set visible of process "Safari" to false' -e 'end'
@joemaller
joemaller / .block
Last active August 7, 2016 19:38 — forked from mbostock/.block
Build Your Own Graph!
license: gpl-3.0
@joemaller
joemaller / lsusb
Created September 12, 2016 13:15
Raspbian video debugging
pi@raspberrypi:~ $ lsusb
Bus 001 Device 012: ID 05ac:0220 Apple, Inc. Aluminum Keyboard (ANSI)
Bus 001 Device 011: ID 05ac:1006 Apple, Inc. Hub in Aluminum Keyboard
Bus 001 Device 007: ID 2109:2811
Bus 001 Device 014: ID 05e1:0408 Syntek Semiconductor Co., Ltd STK1160 Video Capture Device
Bus 001 Device 006: ID 2109:2811
Bus 001 Device 005: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS]
Bus 001 Device 004: ID 046d:c526 Logitech, Inc. Nano Receiver
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
The following groups are read: mysqld server mysqld-5.5
var githubPriceForUsers = function (users) {
return Math.max(0, users - 5) * 9 + 25;
};
var githubUsersForCost = function (price) {
var f = Math.ceil(Math.max(0, price - 25)/9);
return [`${f + 5} users`, `$${b(f + 5)}`];
}
@joemaller
joemaller / gulpfile.js
Last active January 5, 2017 20:42
Example gulpfile showing how to serve Browsersync from an arbitrary subpath. Download the zip, `npm install` and `gulp watch`
var gulp = require('gulp');
var browsersync = require('browser-sync').create();
gulp.task('watch', function() {
browsersync.init({
files: './*.html',
startPath: '/some/multi/level/path',
server: {
baseDir: '-',
routes: {