Skip to content

Instantly share code, notes, and snippets.

Avatar

Isaac Sukin IceCreamYou

View GitHub Profile
@IceCreamYou
IceCreamYou / promise-pool.js
Created Jan 28, 2019
A simple way to run promises with limited concurrency.
View promise-pool.js
/**
* Creates and immediately starts running a new PromisePool.
*
* Note the pool currently has a fixed size, but dynamic sizing could be added. Also fns for size, isRunning. Does not track return values.
*
* @param producer
* A function that does some work concurrently. If the function returns a
* Promise, the producer will be called again when the Promise resolves and
* the new work will be added to the stack. If the function returns nothing,
* the pool will drain and stop.
@IceCreamYou
IceCreamYou / find-array-null-runs.js
Created Jul 17, 2018
Given an array of values, finds sequences of nulls.
View find-array-null-runs.js
/**
* Given an array of values, finds sequences of nulls.
*
* @param data The array of values within which to search.
*
* @returns
* An array of objects with `start` and `end` properties. These hold indices
* of non-null values on either side of one or more null values. No object is
* returned for leading or trailing nulls.
*/
@IceCreamYou
IceCreamYou / parse-csv.ts
Created May 18, 2018
A reasonably robust, relatively comprehensible CSV / DSV parser, <1 KB minified, for when you don't want to import a giant library. MIT Licensed.
View parse-csv.ts
export type CSVOptions = Partial<{
fieldSeparator: string,
rowSeparator: string,
quote: string,
trimFields: boolean,
sanitizeRowSeparators: boolean,
}>;
/**
* Converts a CSV string to an array of arrays.
@IceCreamYou
IceCreamYou / regex-wordwrap.js
Created Sep 9, 2017
Implements simple character-count-based word wrapping with regular expressions in JavaScript
View regex-wordwrap.js
/**
* Wraps the specified string onto multiple lines by character count.
*
* Words (consecutive non-space characters) are not split up.
* Lines may be shorter than `len` characters as a result.
* Careful: words longer than `len` will be dropped!
*
* @param str The string to wrap.
* @param len The max character count per line.
*
@IceCreamYou
IceCreamYou / mainloop-multiple.js
Created Sep 5, 2016
Extends MainLoop.js to support multiple loops.
View mainloop-multiple.js
/*
* Adds the ability to have multiple main loops to MainLoop.js.
*
* The functionality in this file modifies the MainLoop object.
*/
(function(root) {
// All the active MainLoop instances.
var instances = [],
@IceCreamYou
IceCreamYou / TimedCircularQueue.js
Created Jun 30, 2016
A circular buffer with timed expiry, useful for tracking real-time activities like mouse/touch positions for gesture detection.
View TimedCircularQueue.js
/**
* Creates a new queue that reuses space and expires elements.
*
* This data type is optimized for frequent additions and expirations. One use
* case is keeping track of mouse/touch positions every frame for gesture
* detection (instead of, for example, pushing and shifting elements onto /
* off of an array, which would churn memory).
*
* If you frequently need to do something with the values that requires
* knowing how many values there are, the best approach is usually to walk the
View keybase.md

Keybase proof

I hereby claim:

  • I am IceCreamYou on github.
  • I am isaacdfx (https://keybase.io/isaacdfx) on keybase.
  • I have a public key whose fingerprint is 1FA3 86C5 4E28 39E9 9C3D F15A 9724 467C BEC5 0586

To claim this, I am signing this object:

@IceCreamYou
IceCreamYou / force-scrollbars-visible.css
Last active Aug 5, 2022
Mac OS X hides scrollbars by default. This is annoying for UI design because it means users might not realize that certain areas are scrollable. This public domain Gist forces the scrollbar to always be visible with native behavior in Webkit-based browsers (Chrome and Opera) on Macs.
View force-scrollbars-visible.css
.force-show-scrollbars ::-webkit-scrollbar-track:vertical {
border-left: 1px solid #E7E7E7;
box-shadow: 1px 0 1px 0 #F6F6F6 inset, -1px 0 1px 0 #F6F6F6 inset;
}
.force-show-scrollbars ::-webkit-scrollbar-track:horizontal {
border-top: 1px solid #E7E7E7;
box-shadow: 0 1px 1px 0 #F6F6F6 inset, 0 -1px 1px 0 #F6F6F6 inset;
}
@IceCreamYou
IceCreamYou / Blur Google Calendar.md
Last active Sep 23, 2022
Blurs Google Calendar event names to make it easier to share screenshots of your availability.
View Blur Google Calendar.md

Sometimes for scheduling purposes it would be nice to be able to take a screenshot of your calendar and send it to someone, but you may not want to show that someone the names of every event on your calendar. This code and bookmarklet solves that problem by blurring out event names on your calendar.

Here is the code:

// These class names were recorded on July 28, 2022 and may change.
var style = document.getElementById('--style') || document.createElement('style'), // <style> element holding blur/hide rules
    spans = document.querySelectorAll('[data-eventchip] span');

// Add the styles
@IceCreamYou
IceCreamYou / chrome-dom-i18n.js
Created Nov 22, 2015
Drop-in i18n (internationalization / translation) for HTML / DOM in Chrome extensions / apps.
View chrome-dom-i18n.js
/**
* Translates HTML in Chrome extensions.
*
* This works by replacing the content or attributes of a DOM element with a
* translated string identified by the element's "data-i18n" attribute. For
* example, `<p data-i18n="p_contents,title=p_title" title="hello">world</p>`
* will be translated to `<p title="__MSG_p_title__">__MSG_p_contents__</p>`
* (assuming `p_title` and `p_contents` are defined keys in a messages.json
* file in the extension as described at
* https://developer.chrome.com/extensions/i18n).