Skip to content

Instantly share code, notes, and snippets.

View nornagon's full-sized avatar

Jeremy Rose nornagon

View GitHub Profile
@nornagon
nornagon / README.md
Last active October 10, 2023 16:44
My disaster of a piece of software for making Medium auto-publish drafts older than 60 minutes

Pile of hacks to work around the fact that Medium's API doesn't give access to drafts. Hijacks Chrome's cookies to pretend to be you.

Usage:

  1. Put disaster.py somewhere.
  2. Edit net.nornagon.writedamnyou.plist so the second string in ProgramArguments points to where you put disaster.py.
  3. Put the net.nornagon.writedamnyou.plist file in ~/Library/LaunchAgents
  4. Run launchctl load ~/Library/LaunchAgents/net.nornagon.writedamnyou.plist

Probably it'll ask you for access to your keychain, since that's needed to decrypt Chrome's cookie store.

@nornagon
nornagon / 1-intro.md
Last active August 3, 2023 12:37
How to make a Minecraft (1.8) mod

How to make a Minecraft mod

Minecraft mods, especially mods which change the client, are by and large written with Forge. If you visit their website, you'll be greeted abruptly by a mysterious message at the top of an SMF forum, with no clear path towards actually... making a mod. I'm documenting here the steps I went through to get started, in the hopes of helping the next person have an easier time of it.

I'll be using Scala for this guide, but it should be fairly easy to adapt these instructions to any JVM language (e.g. clojure or if you're feeling masochistic, Java). I'm also developing on OS X, so some of the commands will be a little different if you're on Linux or Windows. I'm assuming you have some proficiency with your operating system, so I won't go into details about how to adapt those commands to your system.

Background

Minecraft doesn't have an official mod API (despite early [promises](http://notch.t

@nornagon
nornagon / smith_waterman.py
Created July 21, 2017 04:07
Smith-Waterman Python implementation
import numpy as np
def smith_waterman(a: str, b: str, alignment_score: float = 1, gap_cost: float = 1) -> float:
"""
Compute the Smith-Waterman alignment score for two strings.
See https://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm#Algorithm
This implementation has a fixed gap cost (i.e. extending a gap is considered
free). In the terminology of the Wikipedia description, W_k = {c, c, c, ...}.
This implementation also has a fixed alignment score, awarded if the relevant
@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)))
(defn sliding
([^long n] (sliding n 1))
([^long n ^long step]
(fn [rf]
(let [a (java.util.ArrayDeque. n)]
(fn
([] (rf))
([result]
(let [result (if (.isEmpty a)
result
@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 / SVGMicroSyntax.scala
Last active July 1, 2021 20:35
SVG path and transform parsers in Scala, using fastparse
// License: GPLv3
// Email me and I'll grant you a free eternal license to use it however you want! nornagon@nornagon.net
object SVGMicroSyntax {
// https://github.com/lihaoyi/fastparse
import fastparse.all._
object PathData {
sealed trait PathCommand
sealed trait DrawToCommand extends PathCommand
@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