Skip to content

Instantly share code, notes, and snippets.

View hghmn's full-sized avatar

Nathan Hughes hghmn

View GitHub Profile
@hghmn
hghmn / is-integer-palindrome-maths.js
Last active August 29, 2015 14:24
Given an integer, determine if it is a palindrome using only mathematical operations.
/**
* Given an integer, determine if it is a palindrome using only mathematical operations
* @param {Integer} num - an integer number to be tested for palindromy-ness
*/
function isIntegerPalindrome( num ) {
// all single digits are by definition palindromes
if( num < 10 ) {
return true;
}
@hghmn
hghmn / logger.js
Created September 11, 2015 04:58
simple JavaScript logging utility
/* logger */
// define the styles we'll use for logger
var cssText = [
"position: fixed;",
"height: 80px;",
"bottom: 0px;",
"left: 0;",
"right: 0;",
"margin: 0;",
@hghmn
hghmn / amount-remaining.js
Created September 12, 2015 15:00
Quick amount remaining indicator for the top of a webpage
(function(context){
var body = document.body,
win = window,
html = document.documentElement,
docHeight,
winHeight,
progBar;
// calculate size of document on load or window resize
function calcSize () {
@hghmn
hghmn / DataGen.js
Created May 18, 2016 22:46
Mock Data Generator
function random(min = 0, max = 100) {
let rand = Math.random() * (max - min) + min;
return rand;
}
class DataGen {
constructor(range) {
//
this.from = range.from||0;
this.to = range.to||10;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
pre {
display: inline;
background: #EAF0F0;
@hghmn
hghmn / index.html
Last active August 4, 2016 20:15
Try to load in an image via canvas
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Image Loader Test</title>
<style>
#canvas {
width: 300px;
height: 300px;
@hghmn
hghmn / bitwise-masks.ts
Last active July 30, 2016 01:00
A collection of bitwise masks
/**
* bitwise masks
*/
const full = 255; /* 11111111 */
// es5 doesn't have Array.fill :(
function makeMask(fn) {
for (let i = 0, mask = []; i < 8; i++) {
mask[i] = fn(full, i) & full;
@hghmn
hghmn / mini-storage.js
Created September 9, 2016 13:25
local storage helper
function Storage(key) {
this.key = key;
this.db = this._load(key);
}
Storage.prototype = {
_load: function(key) {
var _existing = localStorage.getItem(key);
return _existing ? JSON.parse(_existing) : {};
},
@hghmn
hghmn / index.html
Created October 14, 2016 13:43
Trying to achieve a limited state machine in html + css only
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<button id="a">3</button>
<button id="b">2</button>