Skip to content

Instantly share code, notes, and snippets.

View nornagon's full-sized avatar

Jeremy Rose nornagon

View GitHub Profile
@nornagon
nornagon / index.js
Created November 30, 2022 05:57
canvas boilerplate
document.head.appendChild(document.createElement('style')).textContent = `
body { margin: 0; overflow: hidden; }
canvas { width: 100%; height: 100%; }
`;
const canvas = document.body.appendChild(document.createElement('canvas'));
(window.onresize = () => {
const {width, height} = canvas.getBoundingClientRect()
canvas.width = width * devicePixelRatio
canvas.height = height * devicePixelRatio
frame()
@nornagon
nornagon / gist:b22e4c5af4b53705286b139cbffcbf19
Created October 11, 2022 21:43
dyld dependency tree walker
#!/usr/bin/env node
import macho from 'macho'
import * as path from 'path'
import * as fs from 'fs'
const rootExe = path.resolve(process.argv[2])
function resolve(exe, rpath, lib) {
return path.resolve(lib.replace(/@rpath/, rpath).replace(/@loader_path/, path.dirname(exe)).replace(/@executable_path/, path.dirname(rootExe)))
@nornagon
nornagon / index.js
Created June 17, 2021 17:26
test electron crash reporter
const { app, crashReporter } = require('electron')
console.log('crashDumps:', app.getPath('crashDumps'))
crashReporter.start({ uploadToServer: false })
app.whenReady().then(() => {
process.crash()
})
@nornagon
nornagon / microtracery-example.html
Created January 24, 2021 01:36
Example of microtracery usage
<body>
<script>
// Micro-size tracery implementation by @nornagon: https://twitter.com/nornagon/status/1322718632481153025
function tracery(data, s='#origin#') {return s.replace(/#([^#]+?)#/g, (_,m) => (_=data[m]??[`((${m}))`],tracery(data, _[(Math.random()*_.length)|0])))}
// Example usage
const text = tracery({
origin: ["#a#", "#b#"],
a: ["a1", "a2"],
b: ["b1", "b2"],
import('./test.mjs') // async import needed to allow for webpack download+compile
// How many unique tiles are required to represent all possible road
// connections on a grid, given that rotations are allowed?
//
// e.g. for a square grid, the tiles look like this:
//
// +---+ +-|-+ +-|-+ +-|-+ +-|-+ +-|-+
// | | | | | | | | | | | | | | | | |
// | | | o | | +-- | | | | +-- --+--
// | | | | | | | | | | | | | | |
// +---+ +---+ +---+ +-|-+ +-|-+ +-|-+
@nornagon
nornagon / github-check-colors.user.js
Created June 18, 2019 18:35
Make GitHub Checks UI readable
// ==UserScript==
// @name GitHub Check Colors
// @version 1
// @include https://github.com/*
// @grant none
// ==/UserScript==
for (const li of document.querySelectorAll('[data-channel^="check_runs:"] .container-md li')) {
if (/Failed/.test(li.textContent)) {
li.style.color = 'red'
@nornagon
nornagon / find-deps.js
Last active December 20, 2018 19:11
List transitive dynamic library dependencies on macOS
#!/usr/bin/env node
const child_process = require('child_process')
const printTree = require('print-tree')
const depsOf = (lib) => {
const res = child_process.spawnSync('otool', ['-L', lib])
if (res.status !== 0) {
throw new Error(`Failed to run otool on ${lib}:\n${res.stderr}`)
}
return res.stdout.toString()
@nornagon
nornagon / reverse-ssh.md
Created December 18, 2018 17:57
SSHing into a machine that can't open listening ports

How to get SSH access to a machine that can't open listening ports

This will work on any machine that can freely connect to outside ports, but can't listen for incoming connections.

In particular, Azure DevOps CI agents have no "Rebuild with SSH" option (like CircleCI does), so this technique can be handy for debugging CI issues.

Requirements

  1. You must be able to run arbitrary commands on the remote host, ideally including installing an SSH server.
  2. You need a machine on the internet that's able to open a listening port. I used my Linode. You could use an AWS free tier t2.micro, or open a port to your local machine. Anything works as long as it runs SSH and can receive packets from the target machine. We'll call this machine the 'bounce server'.
@nornagon
nornagon / index.html
Created December 4, 2018 00:59
Electron Fiddle Gist
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<!-- All of the Node.js APIs are available in this renderer process. -->
We are using Node.js <script>document.write(process.versions.node)</script>,