Skip to content

Instantly share code, notes, and snippets.

@uhop
uhop / formatNumber.js
Created June 6, 2009 02:15
Fixing Spymaster's formatNumber()
// How to format big numbers using commas to separate 1000s and abbreviations
// Example: 12345678900 => 12.34B
var numPattern = /^(\d{0,2})(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{3})?$/;
function putCommasIn(s){
return s.match(numPattern).slice(1).join(",").replace(/^\,{1,}/, "").replace(/\,{1,}$/, "");
}
function trimZeroes(s){
return s.replace(/\.?0+$/, "");
@uhop
uhop / gist:3351030
Created August 14, 2012 17:29 — forked from idan/gist:3135754
A Sample Post

Hello there! This is a sample post for gist.io, a super-lightweight writing soapbox for hackers.

Now look up. Further. Above the post title. See that grey text with the gist ID?

Now back to me. That grey text is a link! Open that sucker in a new tab to see the source for this post. Also, I'm on a horse.

This is a major heading

If you peek at it with a web inspector, you'll see that it is a second-level heading. You can use first level headings, but they'll look just like the second level ones, and the gods of the HTML5 outlining algorithm will frown upon you.

@uhop
uhop / minified.js
Last active December 15, 2015 18:19
UMD header
/* UMD.define */ (typeof define=="function"&&define||function(d,f,m){m={module:module,require:require};module.exports=f.apply(null,d.map(function(n){return m[n]||require(n)}))})
(["module", "../main"], function(module, unit){
// module's code
});
/* UMD.require */ (typeof define=="function"&&require||function(d,f,m){m={module:module,require:require};f.apply(null,d.map(function(n){return m[n]||require(n)}))})
(["module", "../main"], function(module, unit){
// module's code
});
Verifying that +elazutkin is my blockchain ID. https://onename.com/elazutkin
* + table {
border-style:solid;
border-width:1px;
border-color:#e7e3e7;
}
* + table th, * + table td {
border-style:dashed;
border-width:1px;
border-color:#e7e3e7;
background: linear-gradient(45deg, #222 12%, transparent 0, transparent 88%, #222 0),
linear-gradient(135deg, transparent 37%, #111 0, #444 32%, #111 63%, transparent 0),
linear-gradient(45deg, transparent 37%, #222 0, #222 63%, transparent 0) #000;
background-size: 15px 15px;
@uhop
uhop / dnd.js
Last active March 14, 2017 20:07
The minimalistic DnD code.
(function () {
'use strict';
window.dnd = window.dnd || {};
function Move (container, options, node, e) {
this.container = container;
this.options = options;
this.node = node;
@uhop
uhop / Component.js
Created June 12, 2017 22:14
React to Web Components bridge
class Component extends HTMLElement {
constructor () {
super();
this.addEventListener('click', this.changeBackground.bind(this));
this.addEventListener('transitionend', this.revertBackground.bind(this));
}
static get observedAttributes () {
return ['text'];
}
@uhop
uhop / rich.html
Created May 14, 2018 19:11
Rich text editor sketch
<!doctype html>
<html>
<head>
<title>Rich text editor demo</title>
<script src="./rich.js" defer></script>
<style>
#editor[contentEditable=true] {
padding: 0.5em;
margin: 1em;
}
@uhop
uhop / stream-merge.js
Last active July 26, 2018 23:49
Merge two corresponding streams by keys
'use strict';
const {Readable} = require('stream');
const merge = (s1, s2) => {
s1.pause();
s2.pause();
let item1 = null,
item2 = null,