Skip to content

Instantly share code, notes, and snippets.

@ajmas
ajmas / IPv6Utils.js
Last active March 30, 2016 19:09
Some IPv6 utility functions I put together, improvements appreciated
var ipv4Regex = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
function expandIPv6(ipv6ColonNotation) {
var pad = "0000"
var count = (ipv6ColonNotation.match(/:/g)|| []).length;
if (count == 0 || count > 7) {
// too few or too many colons
return "err";
}
@ajmas
ajmas / polar2cartesian.java
Last active January 20, 2016 23:18
Takes a panoramic image that is in a 'fisheye' view and unwraps it. See http://terra-azure.org/?loc=articles/programming/java/polar2cartesian for an explanation
package ajmas74.experimental.graphics2d;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferInt;
import java.awt.image.DirectColorModel;
import java.awt.image.PixelGrabber;
import java.awt.image.Raster;
@ajmas
ajmas / healthcheck.sh
Last active January 6, 2016 02:56
Script to do both IPv4 and IPv6 host health checks, also supporting hosts that only have one address class
#!/bin/ksh
hostname="$1"
url_protocol="https://"
url_path="/cbace7c0fbe7ffad8af83f61a550dcef/xxxxx_nvwwcsKpsN1qajmbto1_500.jpg"
## TODO support CNAMES properly - it throws things off
###
### IPv4 Health Check
@ajmas
ajmas / snapSVG rainbow gradient.js
Created December 24, 2015 05:20
Drawing a rainbow gradient with snapSVG
snap = Snap('#mySVG');
gradient = snap.gradient('l(0, 0, 1, 0)red-orange-yellow-green-blue-indigo-violet');
snap.rect(0,0,200,200).attr({
fill: gradient
});
@ajmas
ajmas / SI Order of Magnitude.js
Last active December 3, 2015 21:53
Javascript code to an SI 'order of magnitude' prefix to a displayed value. For example, given 1000 and 'Hz', you will get 1kHz. For decimal number less than 1, big.js is needed to avoid errors. Note, I looked at using a mathematical approach to get the index, but it worked out to be about the same speed, so I opted for readability
//ref: https://en.wikipedia.org/wiki/Metric_prefix
function valueToMagnitude(value, unit, fixedPlaces) {
var unitExponents = [
[0,''],
[3,'k'],
[6,'M'],
[9,'G'],
[12,'T'],
[15,'P'],