Skip to content

Instantly share code, notes, and snippets.

View inexorabletash's full-sized avatar

Joshua Bell inexorabletash

View GitHub Profile
@inexorabletash
inexorabletash / bracket.js
Created March 19, 2014 19:02
Resource Disposal: Haskell's Bracket pattern in JS
// http://cautionsingularityahead.blogspot.com/2012/07/resource-using-in-javascript.html
// Say you have a heavy-weight resource that you can explicitly finalize - either through
// some API or just by dropping a reference when you're done even if you want to hold onto
// the wrapper:
function Resource(a) {
var res = "a resource of " + a;
this.get = function() {
return res;
# Custom prompt
function prompt {
write-host -NoNewLine -ForegroundColor Red $pwd
# Current git branch name
$branch = git rev-parse --abbrev-ref HEAD
if ($branch) {
write-host -NoNewLine -ForegroundColor Green (' [' + $branch + ']')
}
@inexorabletash
inexorabletash / @ Indexed DB Promises.md
Last active September 25, 2015 15:51
Indexed DB + Promises #3

STATUS: Obsolete - see this updated proposal instead.

Extend IDBDatabase with:

interface IDBDatabase {
  IDBExplicitTransaction explicitTransaction(scope, mode);
};
@inexorabletash
inexorabletash / @ Indexed DB Transactionless API.md
Last active September 23, 2016 16:03
Transactionless IDB API

Transactionless Indexed DB

Status: Initial thought experiment. Feedback welcome.

There are times when Indexed DB's transaction-centric API is too heavyweight:

@inexorabletash
inexorabletash / idb_key_list.js
Last active November 22, 2019 00:48
How to iterate over a list of keys using a cursor, using IndexedDB.
// Copyright 2019 Google LLC.
// SPDX-License-Identifier: Apache-2.0
var name = 'db' + Date.now();
var openReq = indexedDB.open(name, 1);
openReq.onupgradeneeded = function() {
var db = openReq.result;
var store = db.createObjectStore('store');
for (var i = 0; i < 100; i += 10)
store.put("record-" + i, i);
@inexorabletash
inexorabletash / aliens_map.txt
Last active June 1, 2020 03:06
Aliens: The Computer Game (Activision) - Map
║ ═ ╔ ╗ ╚ ╝ ╠ ╣ ╦ ╩ ╬ -- normal
│ ─ ┌ ┐ └ ┘ ├ ┤ ┬ ┴ ┼ -- infested
Save the Marines:
╔═╦╦═╦╦═╗╔═╦╦═╗
╠╗╠╬═╝╚╦╩╣╔╝╚╗╚╗
║║║╚╗╔╦╝╔╬╝╔═╬═╝
╚╝╚═╩╝╚═╣╚═╣╔╩╦╗
║╔╗║╚╦╝║
@inexorabletash
inexorabletash / @ Intl.Segmenter polyfill.md
Last active January 5, 2021 17:53
Intl.Segmenter polyfill

Following proposal by @littledan

THIS NO LONGER MATCHES THE PROPOSED API AND SHOULD NOT BE USED

Just proof-of-concept. Do not use in production.

Caveats:

@inexorabletash
inexorabletash / @ Indexed DB - N-Dimensional Select V2.md
Last active July 18, 2022 11:03
@ Indexed DB - N-Dimensional Selection V2

Indexed DB - N-Dimensional Selection (V2)

This is a redo of the solution over in Indexed DB - N-Dimensional Selection but with a revised "API". The sample here takes a query in the form of an array of IDBKeyRange instances (or null), e.g.

select(index, [IDBKeyRange.bound(5, 7), null, IDBKeyRange.lowerBound(15000)], callback, complete);
@inexorabletash
inexorabletash / @ OBSOLETE IndexedDB Promises.md
Last active January 19, 2024 05:50
IndexedDB with Promises Hackery