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 / 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;
@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)
# 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 / 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();
@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 / storage.js
Last active May 5, 2020 15:56
Import & Export localStorage between domains
function exportLocalStorage () {
var output = {};
for (var key in localStorage) {
if (!localStorage.hasOwnProperty(key)) {
continue;
}
output[key] = localStorage[key];
}
return JSON.stringify(output).replace(/'/g, '\\\'').replace(/"/g, '\\"');
}
@stayradiated
stayradiated / lines.sh
Created February 3, 2016 03:06
Find number of lines of code in a folder recursively (excluding tests)
find . -iname '*.js' -not -path "*/__tests__/*" -exec wc -l {} \; | ag -o \\d+ | paste -sd+ - | bc
var successPromise = new Promise(function (resolve, reject) {
setTimeout(resolve, 1000);
});
successPromise.then(function () { console.log('this should succeed') });
var failingPromise = new Promise(function (resolve, reject) {
setTimeout(reject, 1000);
});
@stayradiated
stayradiated / img2vid
Last active January 11, 2024 15:33
Concatenate Videos and Images using ffmpeg
#!/usr/bin/env bash
#
# img2vid
# =======
#
# Convert an image into three second video
#
# Usage: ./img2vid photo.jpg video.mp4
#
@stayradiated
stayradiated / data.csv
Created March 12, 2017 22:51
D3 Dot Graph
snap audience
0 100
1 95
2 82
3 78
4 61
5 59
6 42
7 30
8 29