Skip to content

Instantly share code, notes, and snippets.

View stayradiated's full-sized avatar
🪚
Rough

George Czabania stayradiated

🪚
Rough
View GitHub Profile
@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 / 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;
# 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 / 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 / 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

😀 :grinning:

😃 :smiley:

😄 :smile:

😁 :grin:

😆 :laughing:

function! Dab()
let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
if line_end - line_start > 0
" collapse
normal va{J
else
" expand
normal va{
s/[{,]/\0
interface BinaryTreeNodeJSON<Value> {
value: Value,
left?: BinaryTreeNodeJSON<Value>,
right?: BinaryTreeNodeJSON<Value>,
}
class BinaryTreeNode<Value> {
static from<Value> (json: BinaryTreeNodeJSON<Value>): BinaryTreeNode<Value> {
const { value, left, right } = json
const leftNode = left != null ? BinaryTreeNode.from(left) : undefined