Skip to content

Instantly share code, notes, and snippets.

@fliptopbox
fliptopbox / Javascript: Number.toCurrency()
Created June 12, 2013 13:32
Javascript Number.toCurrency() to convert INT 1234567 to CURRENCY £1,2345.67
/*
@fliptopbox
Format a number as a currency.
eg. 12345.67 = £12,345.67
usage examples:
(1234567.899).toCurrency(); // 1,234,567
(1234567.999).toCurrency(0); // 1,234,567
@fliptopbox
fliptopbox / top-level-domain.js
Created October 14, 2013 22:12
Javascript Top Level Domain (TLD) Utility
/*jslint bitwise: true, eqeq: true, sloppy:true, white:true, passfail: false, nomen: false, plusplus: false, undef: true, evil: true */
/*global window, setTimeout, document, console, $, jQuery, self */
/*
An object to return the domain name, taking into account
the various top-level-domains (TLD) and second-level-domains (SLD)
as maintained by mozilla (see: https://wiki.mozilla.org/TLD_List)
this list was last modified on 11 January 2010, at 09:32
USAGE:
@fliptopbox
fliptopbox / string.compress.js
Created October 15, 2013 12:32
JavaScript String compression
/*
@fliptopbox
LZW Compression/Decompression for Strings
Implementation of LZW algorithms from:
http://rosettacode.org/wiki/LZW_compression#JavaScript
Usage:
var a = 'a very very long string to be squashed';
var b = a.compress(); // 'a veryāăąlong striċ to bečquashed'
@fliptopbox
fliptopbox / String.prototypes
Created November 13, 2013 12:33
Some String prototype extensions that are handy
/* Additional Primative Object Extensions */
String.prototype.capitals = function () {
// 'kilRoY waS hErE!' >> 'Kilroy Was Here!'
return (this || '').replace(/([^ ])([^ ]*)/g,
function(a,b,c) { return b.toUpperCase() + c.toLowerCase(); });
};
String.prototype.snake = function () {
// 'kilRoY waS hErE!' >> 'kilRoY_waS_hErE!'
return (this || '').replace(/\s+/g, '_');
};
@fliptopbox
fliptopbox / lorem
Created November 19, 2013 23:46
lorem ipsum test generator
var lorem = (function () {
/* (c) 2013 - Qwack Ltd. -------------------------- */
var i = 0,
l = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmodtempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodoconsequat. Duis aute irure dolor in reprehenderit in voluptate velit essecillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat nonproident, sunt in culpa qui officia deserunt mollit anim id est laborum.'.split(' '),
n = l.length,
r = function (n) { return Math.floor((Math.random()*n)+1); },
u = r(100),
t = '',
a = '',
w = function (q) {
/*
This is a proxy function to minimize console.log
output on production server. It creates non-existant
window.console Object for old browsers, and defers all
log events via the proxy function.
Usage:
(on your dev server)
window.message('kilroy was here...'); // normal output.
(on your production server)
@fliptopbox
fliptopbox / string.wordwrap.js
Last active August 29, 2015 14:16
javascript: wordwrap
/*
String.wordwrap(@length INT [ @spill INT ])
A String prototype to wrap long strings into lines with an ideal length
by recurrsively itterating over the string, to complie an array of lines.
Arguments:
@length: INT (required) - ideal string length of characters per line
@spill: INT (optional) - margin of tolerance, a greedy look ahead
@fliptopbox
fliptopbox / const.less
Last active August 29, 2015 14:22
LESS frequently used functions and mixins
// colours
@paleblue: #a0d3f1;
@half: 47%;
// Functions
.fontmuseo (@size: 14px, @color: #FFFFFF, @weight: 500, @style: normal) {
font-family: 'MuseoSans', Arial, sanserif;
font-size: @size;
color: @color;
font-weight: @weight;
font-style: @style;
@fliptopbox
fliptopbox / browser-update
Created June 18, 2015 09:25
HTML generic browser update message
<style type="text/LESS">
.browser {
&-msg {
position: absolute;
background-color: #333;
color: #fff;
z-index: 999999;
width: 550px;
margin: 15% auto;
display: block;
@fliptopbox
fliptopbox / html-unicode-characters
Created June 22, 2015 15:57
HTML Unicode characters
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<pre>
U+2302 ⌂ HOUSE
U+2303 ⌃ UP ARROWHEAD