Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / ts-pattern-match.ts
Last active September 8, 2020 06:35
Typescript Pattern Matching
/**
* @fileoverview
* Typescript Pattern Matching
* @description
* From [@fillopeter's Medium post](https://medium.com/@fillopeter/pattern-matching-with-typescript-done-right-94049ddd671c),
* _“Pattern matching” with Typescript done right_
*/
class Square {
type = "Square" as const
@disco0
disco0 / Nominal.ts
Last active September 27, 2020 22:36
Typescript nominal typing scratch
/**
* Inspired by [Drew Colthorp's blog post, Flavoring: Flexible Nominal Typing for TypeScript](https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing)
*/
/**
* Last form of an attempt to define a generic constrained to `unique symbol` for
* the property symbol (`NominalIdentifierSymbol` in this case).
*
* 'NominalIdentifierSymbol' is declared but its value is never read.(6133)
* VVVVVVVVVVVVVVVVVVVVVV
@disco0
disco0 / TemplateStringReduce.ts
Last active September 21, 2020 07:40
typescript-template-string-reduce
///<reference lib="es2019.array"/>
//#region Util
const Identity = <V>(value: V): V => value;
type Identity = typeof Identity;
const asString = (value: any): string => String(value);
type ToString = (value: any) => string;
@disco0
disco0 / GroupedRegExpResult.ts
Last active September 22, 2020 05:25
typescript-regexp-groups
/**
* Casting regexp match/exec results will allow for autocompletion of the keys supplied in union
* to `Groups` generic parameter:
* ``` ts
* const execResult = /(?<test>capture)/.exec('test') as GroupedRegExpExecArray<'test'>;
* execResult.groups. // <TAB> => test?: string
*
* const matchResult = 'test'.match(/(?<test>capture)/) as GroupedRegExpMatchArray<'test'|'capture'>;
* matchResult.groups. // <TAB> => (property) capture?: string
* // (property) test?: string
@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 / ifArray.ts
Last active September 16, 2020 03:43
typescript-ifArray-conditional-return
type AnyArray = any[];
type NotArray = Exclude<any, AnyArray>;
//#region ifArray
//#region Definition
function ifArray<T, F, O extends Array<any> = Array<any>>(obj: O, isTrue: T, isFalse: F): T;
function ifArray<T, F, O extends Exclude<any, any[]>>(obj: O, isTrue: T, isFalse: F): F;
function ifArray<T, F, O>(obj: O, isTrue: T, isFalse: F): T | F
@disco0
disco0 / playground.json
Last active September 20, 2020 11:19
Styled console.log using HTML (jsfiddle.net/yg6hk/5/)
{
"scripts": [],
"showConsole": true,
"scriptType": "text/javascript",
"layout": "splitLeft"
}
@disco0
disco0 / index.ts
Last active September 27, 2020 09:17
Array#join Override
//#region Types
// Just here to validate that the new signature is identical to the es5 type declaration
type Array$join$primordial_Signature = (separator?: string) => string
declare interface Array<T>
{
separator?: string;
join: Array$join$primordial_Signature;