Skip to content

Instantly share code, notes, and snippets.

View 13rac1's full-sized avatar
🎱
The S in IoT stands for security

Bradley Erickson 13rac1

🎱
The S in IoT stands for security
View GitHub Profile
@13rac1
13rac1 / ansible-create-user-with-password
Created March 18, 2013 22:18
Create a user in an Ansible playbook with a set, but unknown password so the account is not locked. Makes it possible to log on the account with a public key. This example requires mkpasswd, but that can be replaced with any other password generator.
---
- hosts: all
gather_facts: yes
##
# Create the password then create the user
#
- name: Users | Generate password for new user
shell: makepasswd --chars=20
register: user_password
@13rac1
13rac1 / cpy
Last active December 15, 2015 22:32
Using Python 3 as a screen-logging command-line calculator
#!/usr/bin/env python3
# Save this in your ~/bin as `cpy` and chmod +x
import code
import readline
import rlcompleter
# Directly import all the math functions
from math import *
@13rac1
13rac1 / androidwear
Created January 4, 2016 22:28
Automate pairing Android and Wear emulators with Expect
#!/usr/bin/expect
# Automates pairing Android and Wear emulators.
# Complete process described here: http://stackoverflow.com/questions/25205888/pairing-android-and-wear-emulators
# Run: ./androidwear DEVICEPORT
# Expect timeout, set short.
set timeout 4
# Device port on localhost [REQUIRED]
set deviceport [lindex $argv 0]

Keybase proof

I hereby claim:

  • I am 13rac1 on github.
  • I am bde (https://keybase.io/bde) on keybase.
  • I have a public key whose fingerprint is 4FAF 283F 8E37 3663 B56D 7031 E167 BF6B 827F 24EF

To claim this, I am signing this object:

@13rac1
13rac1 / measure_string.py
Last active June 23, 2024 06:29
Find the display width in pixels of a string given a font, point size and DPI in Python using Freetype
"Find the display width in pixels of a string given a font, point size and DPI."
import freetype
# Uses Freetype Python bindings:http://freetype-py.readthedocs.io/en/latest/
# Based on the FreeType Tutorial examples:
# https://www.freetype.org/freetype2/docs/tutorial/step2.html
# Note: This code uses bitshift by six to divide/multiply by 64 to convert
# between 26.6 pixel format (i.e., 1/64th of pixels) and points.
THE_STRING = "Hello World!"
@13rac1
13rac1 / get-ops-json.sh
Created February 26, 2017 20:09
Generate a Minecraft UUID ops.json with curl and jq given a comma separated list of usernames
#!/bin/sh
# 2017 https://github.com/eosrei/
OPS=${1-notch,jeb}
echo -n "$OPS" \
| jq --raw-input --slurp 'split(",")' - \
| curl -H "Content-type: application/json" \
-d @- \
@13rac1
13rac1 / bug-singleton-global-data-access.md
Last active January 3, 2019 19:08
Singleton global object cannot be changed by multiple threads without a mutex or data access conflicts will occur

I was researching how to use Golang's Template.FuncMap() and found a data access issue in: https://www.calhoun.io/intro-to-templates-p3-functions/

The section in question:

# Making our functions globally useful

Next we need to define our function that uses a closure. This is basically a fancy way of saying we are
going to define a dynamic function that has access to variables that are not necessarily passed into it,
but are available when we define the function. 
@13rac1
13rac1 / 8bit-sine.h
Created August 8, 2019 07:24
8 bit Sine Wave lookup array
# Reproduce with Golang
# for x := 0; x < 256; x++ {
# xInRadians := float64(x) / 255 * 2 * math.Pi
# sinX := uint8(math.Round((math.Sin(xInRadians) + 1) / 2 * 255))
# fmt.Printf("%#02x,", sinX)
# if x%8 == 7 {
# fmt.Print("\n")
# }
# }
# Based on https://gist.github.com/funkfinger/965900 but more precise.
@13rac1
13rac1 / err_unwrap_stack.go
Last active April 29, 2020 03:11
Go 1.13+ Unwrap Error stack to print type and contents to discover which error types are available for use with errors.As()
if err != nil {
for err != nil {
fmt.Printf("%T: %#v\n", err, err)
err = errors.Unwrap(err)
}
}
# Example Output
# *net.OpError: &net.OpError{Op:"read", Net:"tcp", Source:(*net.TCPAddr)(0xc00019df80), Addr:(*net.TCPAddr)(0xc00019dfb0), Err:(*os.SyscallError)(0xc000223b60)}
# *os.SyscallError: &os.SyscallError{Syscall:"read", Err:0x68}
# syscall.Errno: 0x68
@13rac1
13rac1 / git-incremental-rebase.sh
Created October 7, 2023 22:49
Incrementally rebases a feature branch against a target branch commit by commit to reduce the severity and complexity of the rebase merge conflicts
#!/bin/bash
help() {
echo "Usage: $0 <main_branch> <feature_branch>"
echo
echo "Incrementally rebases a feature branch against a target branch commit by commit to reduce"
echo "the severity and complexity of the rebase merge conflicts."
echo
echo "Arguments:"
echo " main_branch The name of the main branch you want to rebase against."