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 / 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 / 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 ''
@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
@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 / 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 / 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 / .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 / cookie.coffee
Last active August 29, 2015 14:08
Simple cookie interface
@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 / 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
}