Skip to content

Instantly share code, notes, and snippets.

function getRandomPayload() {
return {
ts: new Date().valueOf(),
date: {
epoc: new Date().valueOf(),
iso: new Date().toISOString(),
local: new Date().toString(),
utc: new Date().toUTCString()
},
float: Math.random(),
@fliptopbox
fliptopbox / research-bookmarklet.js
Created September 18, 2019 21:26
Bookmarklet to present various links to research recources.
(function(){
const body = document.querySelector("body");
const sources = {
"google": "https://www.google.com/search?q=@",
"amazon": "https://www.amazon.co.uk/s?k=@",
"gutenberg": "https://www.gutenberg.org/ebooks/authors/search/?query=@",
"etymology": "https://www.etymonline.com/search?q=@",
"dictionary": "https://www.dictionary.com/browse/@",
"wikipedia": "https://en.wikipedia.org/wiki/@"
@fliptopbox
fliptopbox / module-template-uml.js
Created July 17, 2019 13:57
A boilerplate for the UML module
(function(root, factory, NS="myfunction") { if (typeof define === "function" && define.amd) { define([], factory); } else if (typeof exports === "object") { module.exports = factory(); } else { root[NS] = factory(); } })(this, function()
{
/*
myfunction
Tell the user what your function does.
And perhaps leave them a usage example
NOTE: don't forget to change NS="myfunction"
that appears in the UML decoration,
@fliptopbox
fliptopbox / base64lib.js
Last active July 17, 2019 13:55
Base64 library - lets you encode UTF-16 or UTF-8 (with UMD decorator)
(function(root, factory, NS = "Base64") { if (typeof define === "function" && define.amd) { define([], factory); } else if (typeof exports === "object") { module.exports = factory(); } else { root[NS] = factory(); } })(this, function()
{
/*
Base64 library
Lets you encode with UTF-16 or UTF-8
https://gist.github.com/fliptopbox/dfbb7ce14730ba1533d48329e4d7740a
@fliptopbox
fliptopbox / console-log-indexed-color.js
Last active June 28, 2019 10:26
Creates a window method that returns an Array of arguments to colour code the console.log output. Each log has a timestamp, and time diff of the last log, the log message is uniquely coloured according to the 1st string in the argument list
/*
Console log index by color
Creates a window method that returns an Array of
arguments to colour code the console.log output
Each log has a timestamp, and time diff of the last log,
the log message is uniquely coloured according
to the 1st string in the argument list
Usage:
@fliptopbox
fliptopbox / iso-countries.json
Created February 13, 2019 15:27
ISO list of countries
{
'AF' : 'Afghanistan',
'AX' : 'Aland Islands',
'AL' : 'Albania',
'DZ' : 'Algeria',
'AS' : 'American Samoa',
'AD' : 'Andorra',
'AO' : 'Angola',
'AI' : 'Anguilla',
'AQ' : 'Antarctica',
/*
a bookmarklet that dumps localStorage
and saves the stringified JSON
to your downloads folder.
1. createa new bookmark (page)
2. in the address field type:
javascript: .... (paste below code)
3. Click the new button
*/
@fliptopbox
fliptopbox / incremental-updater.js
Created March 26, 2018 21:20
incremental updater
var ms;
var runtime;
var i;
var total;
var diff;
var incr;
var prev = 0;
function updater (target, rtime, msec) {
if(target) {
@fliptopbox
fliptopbox / space invader
Last active June 29, 2016 23:44
javascript - alien in my console
(function(e,t) {
console.log('%s\nKilroy was here.', t.replace(/\w/g, function(x) {return e[x];}));
}({a:' ',l:'▀',i:'▄',e:'█',n:'\n'}, "aaaliaaailaanaaieleeeleianaeleeeeeeelenaeaellllleaenaaaallallaaan"));
console.log output:
▀▄ ▄▀
▄█▀███▀█▄
█▀███████▀█
█ █▀▀▀▀▀█ █
@fliptopbox
fliptopbox / Array.shuffleAndClip()
Last active August 25, 2015 21:37
Javascript Array.shuffleAndClip()
Array.prototype.shuffleAndClip = function (len) {
var array = this;
if(len && array.length && len > array.length - 1) {
len = null;
}
for(var rnd, value, i = array.length; i;
rnd = Math.floor(Math.random() * i),
value = array[--i],
array[i] = array[rnd],
array[rnd] = value);