Skip to content

Instantly share code, notes, and snippets.

@brandonros
brandonros / stm32f407g-disc1-dfu-mode.md
Last active January 14, 2026 19:14
STM32F407G-DISC1/STM32F4DISCOVERY DFU mode
  1. Take every jumper off except JP1. Take both jumpers off CN3. Take the jumpers JP2 and JP3 off from the bottom of the board.
  2. Put a jumper between BOOT0 and VDD.
  3. Connect with a wire PA9 to 5V.
  4. Connect the device using the micro USB port, not the mini-USB port.
  5. sudo dfu-util -d 0483:df11 -a 0 -s 0x08000000 -D build/Example_Project.bin
  6. Unplug the device.
  7. Disconnect the BOOT0 jumper.
  8. Plug the device in.
@brandonros
brandonros / gist:4aa6ae51d0f925671d034446947df555
Last active January 7, 2026 19:53
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
apiVersion: v1
kind: Namespace
metadata:
name: docker-dev
---
apiVersion: v1
kind: Pod
metadata:
name: docker-compose-pod
namespace: docker-dev
@brandonros
brandonros / blueGreenDeployment.js
Created December 17, 2018 01:42
node.js + nginx + PM2 rolling release/blue green deployments (zero downtime)
const Promise = require('bluebird');
const fs = require('fs');
const execa = require('execa');
class BlueGreenDeployment {
constructor({appName, blueProxyPassPattern, greenProxyPassPattern, nginxConfigFile}) {
this.appName = appName;
this.blueProxyPassPattern = blueProxyPassPattern;
this.greenProxyPassPattern = greenProxyPassPattern;
this.nginxConfigFile = nginxConfigFile;
@brandonros
brandonros / gist:f276b75099d363d8c74e00ec55892e91
Created February 21, 2019 06:05
Vanilla JavaScript equivalent of jQuery $('body').on('click', 'selector', ...)
const bindEvent = (eventNames, selector, handler) => {
eventNames.split(' ').forEach((eventName) => {
document.addEventListener(eventName, function (event) {
if (event.target.matches(selector + ', ' + selector + ' *')) {
handler.apply(event.target.closest(selector), arguments)
}
}, false)
})
}

USB Preparation

SOURCE_IMAGE="debian-12-nocloud-amd64.qcow2"
TARGET_SIZE_GB=120
OUTPUT_RAW="${SOURCE_IMAGE%.qcow2}.raw"

# install dependencies
sudo apt-get update
sudo apt-get install -y parted
@brandonros
brandonros / retries-and-timeouts.rs
Created November 25, 2022 18:54
Rust async retries + timeout callbacks
use log::warn;
use std::future::Future;
pub async fn timeout_wrapper<Fut, T>(timeout_ms: u64, cb: &impl Fn() -> Fut) -> Result<T, String>
where
Fut: Future<Output = Result<T, String>>,
{
let request_future = cb();
let timeout_future = tokio::time::timeout(tokio::time::Duration::from_millis(timeout_ms), request_future).await;
if timeout_future.is_err() {
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
@brandonros
brandonros / preact-htm-example.html
Last active August 9, 2024 04:32
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 / bmw-esys-series-codes.java
Last active April 1, 2024 13:10
Extracted BMW F series ESYS commands (DME/ECU/Tune/Code)
// Random code sequences I found throughout a flashing tool
D = new hs("RCS_EraseCoding", "31 01 0F 01", 3, false);
e = new ha("DSC_DS", "10 01");
f = new ha("DSC_ES", "10 03");
g = new ha("DSC_PS", "10 02");
h = new ha("DSC_DEVS", "10 4F");
i = new ha("DSC_CS", "10 41");
j = new ku("RCS_SEMD", "31 01 0F 0C 00");
k = new ku("RCS_SEMF", "31 01 0F 0C 03");