Skip to content

Instantly share code, notes, and snippets.

View nornagon's full-sized avatar

Jeremy Rose nornagon

View GitHub Profile
@nornagon
nornagon / require.js
Created January 23, 2010 04:45
asynchronous require() for JavaScript. Uses prototype.js.
var require = (function () {
var _required = {};
return (function (url, callback) {
if (typeof url == 'object') {
// we've (hopefully) got an array: time to chain!
if (url.length > 1) {
// load the nth file as soon as everything up to the n-1th one is done.
require(url.slice(0,url.length-1), function () {
require(url[url.length-1], callback);
});
// 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>,
@nornagon
nornagon / index.html
Created November 28, 2018 00:08
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>,
@nornagon
nornagon / index.html
Created November 28, 2018 00:05
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>,
@nornagon
nornagon / index.html
Created November 9, 2018 21:17
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>,
@nornagon
nornagon / index.html
Created October 16, 2018 21:45
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>,