Skip to content

Instantly share code, notes, and snippets.

@randombenj
randombenj / physics-rocket-principles.py
Last active August 29, 2015 13:58
The rocket impulse problem: the rocket changes its mass to accelerate
# G acceleration of earth (m/s^2)
G_EARTH = 9.81
# How many times the iteration is repeated (s)
DELAY = 0.001
# Start mass of Rocket (kg)
START_MASS = 775000
# End mass of the Rocket (all fuel burnt) (kg)
END_MASS = 265143
# Velocity of the gas (relative to the rocket) (m/s)
V_REL = 3248
@randombenj
randombenj / .bashrc
Created August 11, 2015 13:30
Bash PS1
export PS1='`if [ $? = 0 ]; then echo "\[\e[32m\] ✔ "; else echo "\[\e[31m\] ✘ "; fi`\[\e[00;37m\]\u\[\e[01;37m\]\[\e[01;30m\]@\[\e[00;37m\]\h\[\e[01;37m\]:`[[ $(git status 2> /dev/null | head -n2 | tail -n1) != "# Changes to be committed:" ]] && echo "\[\e[31m\]" || echo "\[\e[33m\]"``[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] || echo "\[\e[32m\]"`$(__git_ps1 "(%s)\[\e[00m\]")\[\e[01;34m\]\w\[\e[00m\]\$ '
@randombenj
randombenj / reconnectiong-websocket.js
Created November 25, 2015 07:31
This websocket connection automaticaly reconnects when the closing event gets fired.
// gets called when a message is recieved
var onmessage = function (event) {
console.log(event);
};
// reconnecting websocket
var socket;
(function start(address){
// creating a WebSocket and set eventhandlers
socket = new WebSocket(address);
HDRS = Arduino.h binary.h Client.h HardwareSerial.h IPAddress.h new.h pins_arduino.h Platform.h Printable.h Print.h \
Server.h Stream.h Udp.h USBAPI.h USBCore.h USBDesc.h WCharacter.h wiring_private.h WString.h
OBJS = WInterrupts.o wiring_analog.o wiring.o wiring_digital.o wiring_pulse.o wiring_shift.o CDC.o HardwareSerial.o \
HID.o IPAddress.o main.o new.o Print.o Stream.o Tone.o USBCore.o WMath.o WString.o
#may need to adjust -mmcu if you have an older atmega168
#may also need to adjust F_CPU if your clock isn't set to 16Mhz
CFLAGS = -I./ -std=gnu99 -DF_CPU=16000000UL -Os -mmcu=atmega2560
@randombenj
randombenj / .zshrc
Last active May 8, 2024 07:19
Custom ZSH Prompt
# Path to your oh-my-zsh installation.
export ZSH=~/.oh-my-zsh
plugins=(git asdf zsh-syntax-highlighting zsh-autosuggestions zsh-autocomplete)
# User configuration
if [ -f $ZSH_CUSTOM/path.sh ]; then
source $ZSH_CUSTOM/path.sh
fi
@randombenj
randombenj / mouse-keyboard.sh
Created March 27, 2020 07:15
r.a.t. 7 & apple keyboard setup
[ $(id) -eq 0 ] || echo "error: run this script as root" && exit 1
# -- setup apple function keys (https://askubuntu.com/a/7553)
echo 2 > /sys/module/hid_apple/parameters/fnmode # temp enabled
# permanently enabled
echo options hid_apple fnmode=2 | sudo tee -a /etc/modprobe.d/hid_apple.conf
update-initramfs -u -k all
# -- setup R.A.T. 7 mouse (https://gist.github.com/pubkey/31ef83263bb5451ff904304d161f40e2)
mkdir -p /etc/X11/xorg.conf.d
#!/bin/sh
lxc image rm $( \
lxc image list --format=json | \
jq -r --arg s $( \
date -d "-1 month" +%Y-%m-%d \
) '[map(select(.created_at | . <= $s)) | .[].fingerprint] | join(" ")')
@randombenj
randombenj / debug-assembly-code.md
Last active October 29, 2020 18:19
A short guide on how to debug x86 assembly code (compiled with nasm for example)

-masm=intel

gdb build/divider

show code: disassemble _lable

run code r

@randombenj
randombenj / apt-key.sh
Created February 13, 2021 15:15
fetch apt key without wget
sudo apt-key adv --fetch-keys https://....pub
sudo add-apt-repository "deb https://.../ /"
@randombenj
randombenj / custom.omp.yml
Last active December 18, 2023 11:32
oh my posh config
# yaml-language-server: $schema=https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json
$schema: https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json
blocks:
- alignment: left
segments:
- foreground: '#9E9E9E'
style: plain
template: '╭─ '
type: text