Skip to content

Instantly share code, notes, and snippets.

View IceCreamYou's full-sized avatar

Isaac Sukin IceCreamYou

View GitHub Profile
@IceCreamYou
IceCreamYou / promise-pool.js
Created January 28, 2019 23:43
A simple way to run promises with limited concurrency.
/**
* 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 July 17, 2018 05:31
Given an array of values, finds sequences of nulls.
/**
* 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 03:02
A reasonably robust, relatively comprehensible CSV / DSV parser, <1 KB minified, for when you don't want to import a giant library. MIT Licensed.
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 September 9, 2017 09:33
Implements simple character-count-based word wrapping with regular expressions in JavaScript
/**
* 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 September 5, 2016 08:01
Extends MainLoop.js to support multiple loops.
/*
* 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 June 30, 2016 07:38
A circular buffer with timed expiry, useful for tracking real-time activities like mouse/touch positions for gesture detection.
/**
* 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

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 March 6, 2024 01:00
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.
.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 March 5, 2024 11:18
Blurs Google Calendar event names to make it easier to share screenshots of your availability.

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:

var style = document.getElementById('--style') || document.createElement('style'), // <style> element holding blur/hide rules
    spans = document.querySelectorAll('[data-eventchip] span'); // This worked as of May 3, 2023 but it may change.

// Add the styles
style.id = '--style';
@IceCreamYou
IceCreamYou / chrome-dom-i18n.js
Created November 22, 2015 08:06
Drop-in i18n (internationalization / translation) for HTML / DOM in Chrome extensions / apps.
/**
* 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).