Skip to content

Instantly share code, notes, and snippets.

View stayradiated's full-sized avatar
🏃‍♂️
Running fast!

George Czabania stayradiated

🏃‍♂️
Running fast!
View GitHub Profile
@stayradiated
stayradiated / roman.js
Last active August 29, 2015 14:16
Convert numbers to roman numerals
var MIN = 1;
var MAX = 3999;
var CHARS = 'IVXLCDM ';
function toRomanNumeral (input) {
if (input > MAX || input < MIN) {
throw new Error('Cannot convert number');
}
var offset = CHARS.length - 3;
@stayradiated
stayradiated / central.js
Created December 11, 2014 21:11
Debugging noble and bleno
var noble = require('noble');
noble.on('stateChange', function (state) {
console.log('state:', state);
if (state === 'poweredOn') {
console.log('scanning...');
noble.startScanning();
} else {
noble.stopScanning();
# Super simple templating engine
tmpl = (template, namespace) ->
fn = (existing, fieldName) ->
content = namespace[fieldName]
content ?= existing
return content
template.replace(/\{\{([a-z0-9_]*)\}\}/ig, fn)
@stayradiated
stayradiated / dom.coffee
Last active June 27, 2022 10:00
Using native methods instead of jQuery
class $
constructor: (query) ->
return document.querySelector(query)
@find: (parent, query) ->
parent.querySelector(query)
@findAll: (parent, query) ->
parent.querySelectorAll(query)
@stayradiated
stayradiated / toLittleEndian.js
Created February 26, 2013 07:06
Create little endians in JavaScript.
function dec2hex (dec) {
hex = dec.toString(16);
if (hex.length < 2) {
hex = "0" + hex;
}
return hex;
}
function toLittleEndian (number, dontPad) {
var power = Math.floor((Math.log(number) / Math.LN2) / 8) * 8;