Skip to content

Instantly share code, notes, and snippets.

View Aaronphy's full-sized avatar
🏀
Focusing

Aaronphy Aaronphy

🏀
Focusing
View GitHub Profile
@OrionReed
OrionReed / dom3d.js
Last active May 7, 2024 17:10
3D DOM viewer, copy-paste this into your console to visualise the DOM topographically.
// 3D Dom viewer, copy-paste this into your console to visualise the DOM as a stack of solid blocks.
// You can also minify and save it as a bookmarklet (https://www.freecodecamp.org/news/what-are-bookmarklets/)
(() => {
const SHOW_SIDES = false; // color sides of DOM nodes?
const COLOR_SURFACE = true; // color tops of DOM nodes?
const COLOR_RANDOM = false; // randomise color?
const COLOR_HUE = 190; // hue in HSL (https://hslpicker.com)
const MAX_ROTATION = 180; // set to 360 to rotate all the way round
const THICKNESS = 20; // thickness of layers
const DISTANCE = 10000; // ¯\\_(ツ)_/¯
@iwill
iwill / semverCompare.js
Last active January 19, 2024 12:42
JavaScript - Comparison of Semantic Versioning
/**
* Semantic Versioning Comparing
* #see https://semver.org/
* #see https://stackoverflow.com/a/65687141/456536
* #see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options
*/
function semverCompare(a, b) {
if (a.startsWith(b + "-")) return -1
if (b.startsWith(a + "-")) return 1
return a.localeCompare(b, undefined, { numeric: true, sensitivity: "case", caseFirst: "upper" })
@wheelo
wheelo / useAppSelector.ts
Created March 24, 2022 10:20 — forked from justblender/useAppSelector.ts
Custom Redux.useSelector() hook for React Native apps
import { useEffect, useReducer, useRef } from 'react';
import { useNavigation } from '@react-navigation/native';
import { useSelector } from 'react-redux';
const undefinedRef = Symbol();
const refEquality = (a: Object, b: Object) => a === b;
export function useAppSelector<Selected = unknown>(
@akai
akai / vscode.settings.json
Created November 22, 2021 06:14
vscode.settings
{
"editor.fontSize": 16,
"editor.fontFamily": "'Fira Code'",
"editor.tabSize": 2,
"editor.fontLigatures": true,
"editor.rulers": [
80,
100
],
"editor.accessibilitySupport": "off",
@JSerZANP
JSerZANP / ContentView.swift
Created March 4, 2021 14:01
communication between native(swiftUI) and wkwebview
import SwiftUI
import WebKit
struct WebView: UIViewRepresentable {
class Coordinator: NSObject, WKNavigationDelegate, WKScriptMessageHandler {
var webView: WKWebView?
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
self.webView = webView
}
@sindresorhus
sindresorhus / esm-package.md
Last active May 7, 2024 08:55
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@tavinus
tavinus / puppeteerDebianHeadless.md
Created September 11, 2020 09:14
Minimal Puppeteer NodeJS Debian 10 Buster

System

Debian 10 Buster headless

Chromium dependencies

Shared Libraries needed

$ sudo apt install libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libgbm1 libasound2 libpangocairo-1.0-0 libxss1 libgtk-3-0

Install nvm

Local user

@souporserious
souporserious / window-zoom.js
Created October 15, 2019 22:00
Checks if window has been zoomed.
// modified from https://stackoverflow.com/a/52008131/1461204
const zoomEvent = new Event('zoom')
let currentRatio = window.devicePixelRatio
function checkZooming() {
if (currentRatio !== window.devicePixelRatio) {
window.dispatchEvent(zoomEvent)
}
}
@ls-joris-desmedt
ls-joris-desmedt / echo-websocket.tsx
Created May 15, 2019 14:21
Websockets + React Context
import React, { ReactNode, useContext, useEffect, useState } from 'react';
import { Websocket } from './websocket';
export type EchoWebSocketContextType = [
(event: any, filter?: string) => void,
(event: any) => void
];
export const EchoWebSocketContext = React.createContext<EchoWebSocketContextType>([
() => {},
() => {},
@cvan
cvan / help.js
Last active October 23, 2023 04:10
[Node.js] get Operating-System Platform (Windows, macOS, Linux) and Architecture (x32, x64, etc.) (without any third-party npm dependencies)
const os = require('os');
// See docs: https://nodejs.org/api/os.html
const usage = {};
usage[`require('os').type()`] = {
value: os.type(),
otherValues: [
'Linux', 'Darwin', 'Windows_NT'
],