Skip to content

Instantly share code, notes, and snippets.

View Aaronphy's full-sized avatar
🏀
Focusing

Aaronphy Aaronphy

🏀
Focusing
View GitHub Profile
@joelgriffith
joelgriffith / big-screenshot.js
Created February 23, 2018 00:07
Large Puppeteer Images
const puppeteer = require('puppeteer');
const merge = require('merge-img');
const pageUrl = ''; // REPLACE ME
const pageElement = '#svgcanvas'; // REPLACE ME
(async() => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(pageUrl);
@brrd
brrd / electron-dynamic-include.js
Last active July 5, 2022 07:02
Electron: dynamic include JS and/or CSS from a dependency in renderer process
// Install 'module-name' as a dependency, then:
function init () {
return new Promise ((resolve, reject) => {
const injectScript = (src, callback) => {
const script = document.createElement('script');
document.head.appendChild(script);
script.onload = callback;
script.src = src;
};
@ilokhov
ilokhov / export-sync-bookmarks.js
Last active September 30, 2024 11:44
Node.js script for exporting and synchronising bookmarks from Google Chrome
const fs = require("fs");
const path = require("path");
function newItem(name, url) {
return { name, url };
}
const bookmarkPath = path.join(
process.env.HOME,
"/Library/Application Support/Google/Chrome/Default/Bookmarks"
@robmathers
robmathers / groupBy.js
Created October 25, 2018 23:18
A more readable and annotated version of the Javascript groupBy from Ceasar Bautista (https://stackoverflow.com/a/34890276/1376063)
var groupBy = function(data, key) { // `data` is an array of objects, `key` is the key (or property accessor) to group by
// reduce runs this anonymous function on each element of `data` (the `item` parameter,
// returning the `storage` parameter at the end
return data.reduce(function(storage, item) {
// get the first instance of the key by which we're grouping
var group = item[key];
// set `storage` for this instance of group to the outer scope (if not empty) or initialize it
storage[group] = storage[group] || [];
@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'
],
@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>([
() => {},
() => {},
@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)
}
}
@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

@sindresorhus
sindresorhus / esm-package.md
Last active May 7, 2025 10:36
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.
@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
}