Skip to content

Instantly share code, notes, and snippets.

View 9point6's full-sized avatar
🤔
Who actually reads this?

John Sanderson 9point6

🤔
Who actually reads this?
View GitHub Profile
@9point6
9point6 / ssh-retry.sh
Last active April 22, 2023 08:44
Keep retrying SSH connection until success (Useful for waiting for VMs to boot)
#!/usr/bin/env bash
# Check we've got command line arguments
if [ -z "$*" ] ; then
echo "Need to specify ssh options"
exit 1
fi
# Start trying and retrying
((count = 100))
@9point6
9point6 / ipsort.coffee
Last active September 3, 2021 13:34
JavaScript & CoffeeScript function for sorting IP addresses
ipSort = ( ipAddressArray ) ->
ipAddressArray.sort ( a, b ) ->
a = a.split '.'
b = b.split '.'
for i of a
if ( a[i] = parseInt a[i] ) < ( b[i] = parseInt b[i] )
return -1
else if a[i] > b[i]
return 1
return 0
@9point6
9point6 / gc-parser.js
Last active October 27, 2016 10:10
(A quick and dirty) Node V8 GC trace parser.
'use strict';
const Promise = require('bluebird');
const _ = require('lodash');
const path = require('path');
const fs = Promise.promisifyAll(require('fs'));
const DEBUG = true;
const FILENAME = './gc';
const RUBBISH_THRESHOLD = 5;
const ALPHA_REGEX = /^[a-zA-Z\s]+$/;
@9point6
9point6 / formatnum.coffee
Created October 16, 2013 09:28
Formats a number with commas, and can shorten large numbers when surpassing a million. Implemented on number prototype,
Number.prototype.formatNum = ( decimal = true, millionify = 1 ) ->
if @ > 999999 && millionify
"#{( Math.round( @ / 100000 ) / 10 ).formatNum decimal, millionify - 1}m"
else
[n,d] = "#{@}".split '.'
reg = /(\d+)(\d{3})/
while reg.test n
n = n.replace reg, '$1,$2'
n + if d? and decimal then ( if not decimal then ".#{d.substr( 0 , decimal )}" else ".#{d}" ) else ''
{
init: function(elevators, floors) {
function getLeastBusyElevator(elevators) {
return elevators.reduce(function (currentLeast, thisElevator) {
if (thisElevator.destinationQueue.length < currentLeast.destinationQueue.length &&
thisElevator.loadFactor() < 0.75
) {
return thisElevator;
} else {
return currentLeast;
@9point6
9point6 / event-debugger.js
Last active August 29, 2015 14:16
Event Debugging Shim - allows limiting and skipping of event listeners as well as inspection of attached listeners
(function () {
// Limit the number of events to be attached
var limits = {
'keydown': 100
};
// Skip this number of events
var skips = {
'keydown': 1
}
@9point6
9point6 / befunge.coffee
Created January 7, 2015 14:21
Basic CoffeeScript Befunge Interpreter
numberize = (fn) -> (a, b) -> fn Number(a), Number(b)
changeDirection = (pos, direction) ->
if direction is '?' then direction = '^v<>'[parseInt Math.random() * 4]
[pos.dx, pos.dy] = {'^': [0,-1], 'v': [0,1], '<': [-1,0], '>': [1,0]}[direction]
pos
operations =
'+': numberize (a, b) -> a + b
'-': numberize (a, b) -> b - a
'*': numberize (a, b) -> a * b
@9point6
9point6 / cookie.coffee
Last active August 29, 2015 14:08
Simple cookie interface
@9point6
9point6 / .bashrc
Created October 29, 2014 11:34
Bash RC
updateWindowTitle()
{
echo -ne "\033];Home - ${HOSTNAME}:${PWD/$HOME/~}\007";
};
[[ -s ~/.nvm/nvm.sh ]] && . ~/.nvm/nvm.sh
# Aliases
alias cd="pushd"
alias bd="popd"
@9point6
9point6 / Microsoft.PowerShell_profile.ps1
Last active August 29, 2015 14:08
PowerShell Profile
if (([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$bckgrnd = "DarkRed"
$shellchar = "#"
} else {
$bckgrnd = "DarkBlue"
$shellchar = "$"
}
$Host.UI.RawUI.BackgroundColor = $bckgrnd
$Host.UI.RawUI.ForegroundColor = 'White'