Skip to content

Instantly share code, notes, and snippets.

View TooTallNate's full-sized avatar

Nathan Rajlich TooTallNate

View GitHub Profile
@TooTallNate
TooTallNate / header.ts
Last active December 30, 2024 07:09
Get the NCA header decryption key in nx.js
// These source values are seen in other open source repos:
// - https://github.com/blawar/tinleaf/blob/3363538600e47e1862d64d265dab1a031b32d037/include/util/crypto.hpp#L41-L42
// - https://github.com/ITotalJustice/sphaira/blob/0370e47f7fac0e426675624f363fe50f3b442048/sphaira/source/owo.cpp#L339-L346
const headerKekSource = new Uint8Array([
0x1f, 0x12, 0x91, 0x3a, 0x4a, 0xcb, 0xf0, 0x0d, 0x4c, 0xde, 0x3a, 0xf6,
0xd5, 0x23, 0x88, 0x2a,
]);
const headerKeySource = new Uint8Array([
0x5a, 0x3e, 0xd8, 0x4f, 0xde, 0xc0, 0xd8, 0x26, 0x31, 0xf7, 0xe2, 0x5d,
0x19, 0x7b, 0xf5, 0xd0, 0x1c, 0x9b, 0x7b, 0xfa, 0xf6, 0x28, 0x18, 0x3d,
@TooTallNate
TooTallNate / vc-files.sh
Last active September 5, 2022 21:54
Uploads a single file as a Now deployment
#!/bin/bash
set -euo pipefail
input="$1"
shift
files_dir="$HOME/files"
mkdir -p "$files_dir"
# Delete old files
rm -f "$files_dir"/*
@TooTallNate
TooTallNate / convert_to_hevc.sh
Last active March 24, 2020 03:32
Transcodes input video file to use the h265/HEVC codec
#!/bin/bash
# Transcodes input video file to use the h265/HEVC codec.
# Outputs the same filename but with x264/h264/xvid/etc. replaced with HEVC.
sed=sed
if type gsed >/dev/null 2>&1; then
sed=gsed
fi
get_streams() {
@TooTallNate
TooTallNate / on-macos.txt
Created February 11, 2020 19:43
Does anyone know why this script takes >2s to receive the `error` event on Windows? On MacOS it's essentially instant…
$ time node slow-windows-error.js
Error: connect ECONNREFUSED 127.0.0.1:4
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1134:16) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 4
}
add() {
expr "$1" + "$2"
}
@TooTallNate
TooTallNate / test.sh
Created August 15, 2018 17:46
Running `shakedown` HTTP unit tests through `import`
#!/usr/bin/env bash
eval "`curl -sfLS import.pw`"
import "import.pw/robwhitby/shakedown" # load the framework
shakedown GET /foo # make a GET request
status 404 # assert on http status code
content_type 'text/html' # assert Content-Type header contains string
contains 'Not found' # assert body contains string
matches 'No.*' # assert body matches regex
@TooTallNate
TooTallNate / test.sh
Created August 14, 2018 20:19
Running `shunit2` shell script tests through `import`
#!/bin/sh
testEquality() {
assertEquals 1 2
}
# Load shUnit2.
eval "`curl -sfLS import.pw`"
import "import.pw/kward/shunit2"
@TooTallNate
TooTallNate / Dockerfile
Created July 17, 2018 22:08
Node.js + Dockerfile
# This is the "base image" which contains Alpine Linux and Node.js v10.x.x preinstalled
FROM mhart/alpine-node:10
# Use the `NPM_TOKEN` build arg to create the `~/.npmrc` file
ARG NPM_TOKEN
RUN echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
# Set the working direcrory to `/usr/src`
WORKDIR /usr/src
@TooTallNate
TooTallNate / add.sh
Created June 23, 2018 17:22
Basic "add" function for bash, for demonstration purposes
add() {
echo "$(( $1 + $2 ))"
}
@TooTallNate
TooTallNate / jsfunc.sh
Created June 20, 2018 05:37
Write JavaScript functions - use as bash functions
#!/bin/bash
jsfunc() {
local code="$(cat)"
local fn="$(cat <<EOFF
$1() {
node <(cat <<EOF
require('stream').Readable.prototype.then = function (...args) { return new Promise((res, rej) => { const bufs = []; this.on('error', rej).on('data', buf => bufs.push(buf)).on('end', () => res(Buffer.concat(bufs))); }).then(...args) };
(async () => {
${code}
})().then(val => typeof val !== 'undefined' && console.log(typeof val === 'string' ? val : JSON.stringify(val, null, 2))).catch(err => console.error(err.stack) || process.exit(1));