Skip to content

Instantly share code, notes, and snippets.

@brandonros
brandonros / preact-htm-example.html
Last active December 10, 2023 12:35
Preact + Hyperscript Tagged Markup (HTM) example
<!DOCTYPE html>
<html>
<head>
<title>Preact HTM Example</title>
</head>
<body>
<script type="module">
// 1. imports from unpkg.com
import * as Preact from 'https://unpkg.com/preact@10.4.7/dist/preact.module.js'
import htm from 'https://unpkg.com/htm@3.0.4/dist/htm.module.js'
@brandonros
brandonros / volumetric-efficiency-calculator.js
Last active August 3, 2020 02:53
VE (volumetric efficiency) calculator
// from https://atgtraining.com/atg-volumetric-efficiency-calculator/
const calculateVe = ({engineSize, rpm, maf, iat, cylinder, pressuure, mafSelection, iatSelection, pressureSelection}) => {
let val = 0, cid = 0, lb = 0, degc = 0, degf = 0, tempK = 0, v = 0, molorMass = 0.28705, gb_air_vol = 0, gsec = 0;
let gb_theo_air_vol = 0, lMin = 0, estv = 0, load = 0, cylAir = 0, refCylAir = 0, estGross = 0, estRWHP = 0;
cid = engineSize / 0.0163871;
if (mafSelection == 0) { // g/sec
lb = maf * 0.00220462 * 60;
} else { // lb/min
gsec = maf / (0.00220462 * 60);
ssh -N -L 3389:127.0.0.1:3389 user@HOST
./websockify.js 0.0.0.0:6080 127.0.0.1:3389
https://novnc.com/noVNC/vnc.html -> advanced -> websocket
host: 127.0.0.1
port: 6080
encrypt: no
path: websockify
@brandonros
brandonros / gist:4aa6ae51d0f925671d034446947df555
Last active April 10, 2024 08:44
BMW UDS function descriptions
10 01;setDefaultSession
10 02;setProgrammingSession
10 03;setExtendedDiagnosticSession
11 01;hardReset
14 FF FF FF,31 01 0F 06,31 01 40 00 00,31 01 40 00 05,31 01 40 00 01;Clear all DTCs (clear DTC,clear Infospeicher,ZFS ***8211; DM_Lock,clear ZFS ***8211; DM_Clear,ZFS ***8211; DM_Unlock)
14 FF FF FF;Clear DTC
19 02 0C;ReadDTC(0C)
19 0A;ReadSupportedDTC
22 10 0A;readEnergyMode
22 10 0E;readExtendedMode
from ghidra.program.model.data import PointerDataType
def create_pointer(address):
try:
currentProgram.getListing().createData(toAddr(address), PointerDataType())
except:
pass
functionManager = currentProgram.getFunctionManager()
f = askFile("Give me a file to open", "Go baby go!")
#!/bin/sh
# download from https://dl-cdn.alpinelinux.org/alpine/edge/releases/aarch64/netboot/
qemu-system-aarch64 \
-M virt,highmem=off \
-m 512M \
-cpu host \
-accel hvf \
-kernel ~/Downloads/alpine-edge-aarch64/vmlinuz-lts \
-initrd ~/Downloads/alpine-edge-aarch64/initramfs-lts \
-append "console=ttyAMA0 ip=dhcp alpine_repo=http://dl-cdn.alpinelinux.org/alpine/edge/main/" \
#/bin/sh
# download from https://dl-cdn.alpinelinux.org/alpine/edge/releases/x86_64/netboot/
qemu-system-x86_64 \
-m 512 \
-kernel ~/Downloads/alpine-edge-x86_64/vmlinuz-lts \
-initrd ~/Downloads/alpine-edge-x86_64/initramfs-lts \
-append "console=ttyS0 ip=dhcp alpine_repo=http://dl-cdn.alpinelinux.org/alpine/edge/main/" \
-nographic
// 1. starting balance: $10000, add $1000 every 7 days
// 2. first trade: buy $1000 worth of SPY on 2021-01-04 at the open price
// 3. all subsequent trades: buy $1000 worth of SPY every 7 days
// 4. include dividend revinesting
// 5. what is account value as of 2021-12-23 using closing price
const assert = require('assert')
const rows = [
{
@brandonros
brandonros / preact+htm.html
Last active February 18, 2022 04:02
Preact + htm template strings example (no JSX, no transpiling, unpkg imports)
<!doctype html>
<html>
<head>
</head>
<body>
<script type="module">
import * as Preact from 'https://unpkg.com/preact@10.6.6/dist/preact.module.js'
import htm from 'https://unpkg.com/htm@3.1.0/dist/htm.module.js'
const html = htm.bind(Preact.createElement)
import WebSocket from 'ws'
const parseWsPacket = (str) => {
const cleanerRgx = /~h~/g
const splitterRgx = /~m~[0-9]{1,}~m~/g
return str
.replace(cleanerRgx, '')
.split(splitterRgx)
.map((p) => {
if (!p) return false