Skip to content

Instantly share code, notes, and snippets.

@oliger
oliger / intlParse.ts
Created June 23, 2023 08:51
Intl Parse Number
// https://observablehq.com/@mbostock/localized-number-parsing
const makeIntlParse = (locale: string) => {
const parts = new Map(new Intl.NumberFormat(locale).formatToParts(12345.6).map((part) => [part.type, part.value]));
const numerals = Array.from(new Intl.NumberFormat(locale, { useGrouping: false }).format(9876543210)).reverse();
const index = new Map(numerals.map((d, i) => [d, i]));
const reGroup = new RegExp(`[${parts.get("group")}]`, "g");
const reDecimal = new RegExp(`[${parts.get("decimal")}]`);
const reNumeral = new RegExp(`[${numerals.join("")}]`, "g");
const EVENT = 'CHANGE';
function Engine() {
this._isInitialized = false;
Hull.init({ /* CREDENTIALS */ }, () => {
this._isInitialized = true;
this.emitChange();
};
const DEPLOYERS = {
sandbox: SanboxDeployer,
iframe: IframeDeployer,
hardcore: HardcoreDeployer
};
function getDeployer(deployment) {
if (DEPLOYERS[deployment.method] == null) {
throw new Error('Deployment method "' + deployment.method + '" does not exist.');
}

scrollIntoViewIfNeeded 4 everyone!!!

This gist provides a simple JavaScript implementation of the non-standard WebKit method scrollIntoViewIfNeeded that can be called on DOM elements.

Usage

Just use the code in index.js in your app or website. You can see usage in the test page test.html.

The parent element will only scroll if the element being called is out of the view. The boolean can force the element to be centered in the scrolling area.

function relativeTime(date) {
var units = {
year: 31557600000,
month: 2629800000,
week: 604800000,
day: 86400000,
hour: 3600000,
minute: 60000,
second: 1000
};
@oliger
oliger / mask_image.css
Created November 20, 2012 09:59
Javascript Image Mask
.ui-mask {
position: relative;
overflow: hidden;
}
.ui-mask img {
position: absolute;
top: 0;
left: 0;
}
@oliger
oliger / memoize.js
Created October 8, 2012 10:35
Simple javascript memoizer
function memoize(fn, hasher) {
hasher = hasher || JSON.stringify;
var memo = {};
return function() {
var key = hasher(arguments);
return (key in memo) ? memo[key] : memo[key] = fn.apply(this, arguments);
};
@oliger
oliger / uri.js
Created September 6, 2012 14:43 — forked from jlong/uri.js
URI Parsing with Javascript
var parseUrl = (function() {
var parser = document.createElement('a');
return function(url) {
parser.href = url;
return {
hash: parser.hash,
host: parser.host,
hostname: parser.hostname,