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 / 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]+$/;
{
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'
@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 / localised-date-object.coffee
Created August 7, 2014 12:39
Localised month/weekday name and ordinal functions for the Javascript Date object
# Just add new languages to this object
Date.locale =
'en':
'months': ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
'days': ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
'ordinals': ['th', 'st', 'nd', 'rd']
# Get current locale
Date.prototype.getLocale = ( lang ) ->
@9point6
9point6 / email-normalizer.coffee
Last active August 29, 2015 14:04
Email address normalizer in CoffeeScript
defaultOptions =
'normalizeGmail': true
'lowerCaseLocal': true
'stripTags': true
'stripComments': true
class EmailNormalizer
constructor: ( @email, options = {} ) ->
@options = defaultOptions
for own k, v of options