Skip to content

Instantly share code, notes, and snippets.

@disco0
disco0 / proxy-and-decorator.ts
Created October 15, 2020 01:59 — forked from mmichlin66/proxy-and-decorator.ts
Virtualizing TypeScript Properties with Proxy and Decorator - listing 4
export function virtual( target: any, name: string)
{
// symbol to keep the proxy handler value
let sym = Symbol( name + "_proxy_handler");
Object.defineProperty( target, name, {
enumerable: true,
get()
{
@disco0
disco0 / virtualizing-numbers.ts
Created October 15, 2020 01:59 — forked from mmichlin66/virtualizing-numbers.ts
Virtualizing TypeScript Properties with Proxy and Decorator - listing 5
class Base
{
@virtual a = 1;
b = this.a;
}
class Derived extends Base
{
a = 2;
}
@disco0
disco0 / primitive-types-proxy-and-decorator.ts
Created October 15, 2020 01:59 — forked from mmichlin66/primitive-types-proxy-and-decorator.ts
Virtualizing TypeScript Properties with Proxy and Decorator - listing 6
// @virtual decorator function
function virtual( target: any, name: string)
{
// symbol to keep the proxy handler value
let sym = Symbol( name + "_proxy_handler");
Object.defineProperty( target, name, {
enumerable: true,
get()
@disco0
disco0 / 1.md
Created October 15, 2020 01:44 — forked from getify/1.md
BetterPromise: a strawman experiment in subclassing Promise and "fixing" a bunch of its awkward/bad parts

Some things that are "better" with this BetterPromise implementation:

  • BetterPromise # then(..) accepts a BetterPromise (or Promise) instance passed directly, instead of requiring a function to return it, so that the promise is linked into the chain.

    var p = BetterPromise.resolve(42);
    
    var q = Promise.resolve(10);
    
    p.then(console.log).then(q).then(console.log);
@disco0
disco0 / readme.md
Created October 9, 2020 04:04 — forked from EthanRutherford/readme.md
Regex but better

RegexButBetter

changes:

  • whitespace is no longer meaningful, and can therefore be used for formatting
    • this means whitespace must be escaped, using existing constructs like \n, \t, and a new escape for singleSpace \ (exact recipe open for discussion)
  • (capture) group constructs are totally rearranged, to allow for easier non-capturing grouping and reduction of "symbol soup" of current regex patterns
    • non-capturing group is assigned the bare ( so that the easiest-to-type grouping construct does not capture, and pollute the capture result array
      Motivation: using (?: just to be able to | a few options looks nasty
    • lookahead and lookbehind are modified to remove inconsistencies that exist for legacy, backward-compatibility reasons
  • (>= = positive lookahead
@disco0
disco0 / asyncwhile.js
Created October 4, 2020 08:08 — forked from tyler-johnson/asyncwhile.js
Asynchronous while loop for ES6 Promises.
function asyncWhile(condition, action, ctx) {
var whilst = function(data) {
return condition.call(ctx, data) ?
Promise.resolve(action.call(ctx, data)).then(whilst) :
data;
}
return whilst();
}
@disco0
disco0 / index.pug
Last active September 20, 2020 08:57 — forked from zeddash/index.pug
Medium style lazy loading images with react #codepen #react
div#app
@disco0
disco0 / macmini 1,1 to 2,1 EFI firmware update.md
Last active January 29, 2025 06:02 — forked from dreamcat4/macmini 1,1 to 2,1 EFI firmware update
macmini 1,1 to 2,1 EFI firmware update

Mac Mini 1,1 to 2,1 Firmware Upgrade

  • NOTE: This is a markdown adaptation of the original forked gist, additional file in this gist is an adaptation of the original post.

Guide & Discussion Thread:

For the best guide, use search keyword: chmod. It should scroll down to:

@disco0
disco0 / Log-.md
Created July 28, 2020 11:58 — forked from bgrins/Log-.md
Prevent errors on console methods when no console present and expose a global 'log' function.

Javascript log Function

Every time I start a new project, I want to pull in a log function that allows the same functionality as the console.log, including the full functionality of the Console API.

There are a lot of ways to do this, but many are lacking. A common problem with wrapper functions is that the line number that shows up next to the log is the line number of the log function itself, not where log was invoked. There are also times where the arguments get logged in a way that isn't quite the same as the native function.

This is an attempt to once and for all document the function that I pull in to new projects. There are two different options:

  • The full version: Inspired by the plugin in HTML5 Boilerplate. Use this if you are writing an application and want to create a window.log function. Additionally,
@disco0
disco0 / mpv.desktop
Created May 11, 2020 10:38 — forked from zoqaeski/mpv.desktop
MPV single instance controller
[Desktop Entry]
Type=Application
Name=mpv Media Player (Single-instance mode)
GenericName=Multimedia player
Comment=Play movies and songs without starting new instance of multimedia player
Icon=mpv
TryExec=mpvctl
Exec=mpvctl add -- %U
Terminal=false
Categories=AudioVideo;Audio;Video;Player;TV;