Skip to content

Instantly share code, notes, and snippets.

View leonadler's full-sized avatar

Leon Adler leonadler

View GitHub Profile
@leonadler
leonadler / ANSI.md
Created November 30, 2023 18:14 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@leonadler
leonadler / useIsInStrictMode.test.tsx
Last active November 15, 2023 04:40
Detect React StrictMode
import { useIsInStrictMode } from './useIsInStrictMode';
test('detect strict mode', async () => {
function TestComponent() {
const [isInStrictMode, CheckStrictMode] = useIsInStrictMode();
return (
<p>
<CheckStrictMode />
{`Strict mode: ${isInStrictMode ? 'on' : 'off'}`}
@leonadler
leonadler / overlayColors.js
Last active June 9, 2022 17:02
Helper to test how the browser blends overlayed semi-transparent colors
/**
* Helper to test how alpha-transparent colors are layered in the browser.
*
* @example
* blendColors('255 0 0 / 20%', '60 60 40 / 30%', '128 96 44 / 60%')
* // -> {r: 128, g: 84, b: 40, a: 0.7764705882352941}
*/
function overlayColors(...colors) {
let canvas;
if (typeof OffscreenCanvas === 'function') {
@leonadler
leonadler / useMemoizedCallback.tsx
Last active October 20, 2021 09:02 — forked from Alx-l/index.tsx
React useMemoizedCallback hook
import * as React from "react";
// see: https://stackoverflow.com/questions/55045566/react-hooks-usecallback-causes-child-to-re-render/55047178
/**
* Useful when you when to pass a function that depends on a piece of state,
* as a prop, without triggering a re-render everytime.
*
* @example
*
@leonadler
leonadler / hasEnabledAdblock.js
Last active March 1, 2021 12:42
Detect if an ad blocker is enabled for the current page
function checkAdblockerEnabled() {
const div = document.createElement('div');
div.className = 'ad_container';
const style = document.createElement('style');
style.innerText = `.ad_container { width:500px; }`;
document.head.appendChild(style);
document.body.appendChild(div);
const hasAdblock = div.offsetWidth < 500;
document.head.removeChild(style);
document.body.removeChild(div);
@leonadler
leonadler / svg2ico.sh
Created December 1, 2020 14:49 — forked from azam/svg2ico.sh
Convert SVG to ICO using ImageMagick, with transparent background and multi-size icons
convert -density 256x256 -background transparent favicon.svg -define icon:auto-resize -colors 256 favicon.ico
@leonadler
leonadler / no-samsung-tv-ads.md
Last active March 6, 2020 14:48 — forked from peteryates/guide.md
How to stop adverts appearing on your Samsung TV

I'm getting adverts in my TV's UI, help!

Samsung's otherwise excellent 2016 range of UHD TVs received an update that added advertisements to the UI. This has been complained about at great length on Samsung's forums and repeatedly, Samsung have refused to add an option to remove them.

The ads interrupt the clean UI of the TV and are invasive. Here's an example of how they look:

one two

This guide was originally posted on Samsung's TV forums but unfortunately, that site is a super-slow and barely accessible unusable mess.

@leonadler
leonadler / unindent.ts
Last active January 15, 2020 19:33
Tagged template unindent helper
export function unindent(template: TemplateStringsArray, ...args: any[]): string {
let numSpaces = 999;
for (const part of template) {
for (const indentation of part.match(/\n +/g) || []) {
numSpaces = Math.min(numSpaces, indentation.length - 1);
}
}
const spaces = new RegExp('\n' + ' '.repeat(numSpaces < 999 ? numSpaces : 0), 'g');
return template
@leonadler
leonadler / enzyme_render_diffs.md
Created April 24, 2019 17:30 — forked from fokusferit/enzyme_render_diffs.md
Difference between Shallow, Mount and render of Enzyme

Shallow

Real unit test (isolation, no children render)

Simple shallow

Calls:

  • constructor
  • render
@leonadler
leonadler / cursor.css
Created April 12, 2019 16:11 — forked from dsdsdsdsdsds/cursor.css
CSS: Cross Browser hires/retina cursor image
.cursor {
cursor: url("cursor.png") 0 0, pointer; /* Legacy */
cursor: url("cursor.svg") 0 0, pointer; /* FF */
cursor: -webkit-image-set(url("cursor.png") 1x, url("cursor@2x.png") 2x) 0 0, pointer; /* Webkit */
}