Skip to content

Instantly share code, notes, and snippets.

@thomaswilley
thomaswilley / gist:88b805de9b5e75f26dbcbb94eff4a559
Last active September 20, 2022 02:54
QEMU setup & run ubuntu

the basics (zero to bootable)

# create disk
$ qemu-img create -f qcow2 ~/QEMU/ubuntu-desktop-18.04.qcow2 10G

# setup
$ qemu-system-x86_64 -m 2048 -vga virtio -show-cursor -usb -device usb-tablet -enable-kvm -cdrom ~/QEMU/ubuntu-18.04.2-desktop-amd64.iso -drive file=~/QEMU/ubuntu-desktop-18.04.qcow2,if=virtio -accel hvf -cpu host

# run (unmount CDROM)
$ qemu-system-x86_64 -m 2048 -vga virtio -show-cursor -usb -device usb-tablet -enable-kvm -drive file=~/QEMU/ubuntu-desktop-18.04.qcow2,if=virtio -accel hvf -cpu host
@thomaswilley
thomaswilley / gist:89f72b1f450e4573513cfce526a665af
Created May 11, 2019 20:54
Show results of curl in firefox
alias ffshow='firefox "data:text/html;base64,$(base64 -w 0 <&0)"'
# usage: curl google.com | ffshow
@thomaswilley
thomaswilley / gist:1d6305ac1191ec905dba10547e7c3b45
Created July 28, 2018 23:13
windows screencast w/ffmpeg (& optionally convert to gif)
# record desktop to .mkv which is safely ended via ctrl+c
ffmpeg -y -f gdigrab -i desktop -r 10 -vcodec libx264 -pix_fmt yuv420p output.mkv
# clip some time (in this case 22s) from the start of the video and transcode to .mp4 (a format not safe to end w/ctrl+c)
ffmpeg -ss 00:00:22.0 -i output.mkv output.mp4
# create a palette
ffmpeg -y -i output.mp4 -vf fps=10,scale=768:-1:flags=lanczos,palettegen palette.png
# create the final gif
ffmpeg -i output.mp4 -i palette.png -filter_complex "fps=10,scale=1024:-1:flags=lanczos[x];[x][1:v]paletteuse" output.gif
@thomaswilley
thomaswilley / sonos.sh
Created July 15, 2018 21:05
brute force scanner for sonos devices on a network
#!/bin/bash
# brute force scanner for sonos devices on a network
# (just looks for open port 1400: e.g., http://ip:1400/support/review)
echo Scanning network for Sonos devices...
for i in $(seq 1 255);
do
IP=192.168.1.$i
PORT=1400
nc -n -z -G 1 $IP $PORT 2>&1 | awk '{print $3}'
@thomaswilley
thomaswilley / CompileTensorflowWithCPUOptimization.txt
Last active January 6, 2018 19:59
Build Tensorflow: OS X High Sierra with CPU optimizations for python3.6
# Reference guide from Google: https://www.tensorflow.org/install/install_sources
# assumes python3 and pip3 installed (/usr/local/python3.6), along with homebrew
# python pkgs path: `python3 -m site` (/usr/local/lib/python3.6/site-packages)
# --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-msse4.1 --copt=-msse4.2
# ^ these are some potential CPU optimizations but just allowing the ./configurewizard to do its thing and use -march=native
# also seems to work fine for just CPU optim.
$ brew install bazel # v.0.9.0
$ pip3 install numpy six wheel
$ git clone https://github.com/tensorflow/tensorflow.git
@thomaswilley
thomaswilley / gist:fcf84480a58d71ff7e89c354e5503283
Created July 9, 2016 19:55
One line template engine that pulls from environment variables. In this example environment variable DIR, contained w/in template infile as "$DIR", will all get replaced by results of `pwd` (current working directory) and the resulting populated template stored in outfile.
DIR=`pwd` awk '{ gsub("\\$DIR",ENVIRON["DIR"]); print $0 }' infile > outfile
@thomaswilley
thomaswilley / gist:eb0fa441438f52ccbba5fcb9339e0bab
Last active July 9, 2016 19:52
Quick incantation to see all the processes using ports/internet (add specific port after -i, e.g., -i :443, to limit results to just that port), sudo it to see fuller list, pipe into grep LISTEN plus sudo to see local servers
lsof -i +c 0 | awk '{ print $1 }' | uniq
@thomaswilley
thomaswilley / applehealth.py
Last active May 29, 2024 14:15
Get Apple Health data as Pandas DataFrame
# Get Apple Health data as Pandas DataFrame
# ===
# pre-reqs: python3, lxml, pandas
# to get started:
# export and mail yourself your data following steps within the Health app on iPhone
# download and unzip contents of exported zip file; find path to export.xml and set path_to_exportxml below
import pandas as pd
import xml.etree.ElementTree
import datetime
@thomaswilley
thomaswilley / gist:6311401
Last active December 21, 2015 13:18
remove (purge) all packages and configs installed on a given date in one line (on ubuntu/debian)
grep -w install /var/log/dpkg.log | awk '{ if ($1 == "2013-08-22") { print $4 }}' | while read -r line; do sudo apt-get -y purge $line && sudo apt-get -y autoremove; done
@thomaswilley
thomaswilley / gist:6205384
Last active December 20, 2015 22:29
convert a csv file to an array
def csvfile_to_array(csvfilepath, delimiter=',', ignore_header=False, set_required_num_cols=(True, 4)):
results = []
with open(csvfilepath, 'r') as csvfile:
ctareader = csv.reader(csvfile, delimiter=delimiter)
if ignore_header:
next(ctareader, None)
for row in ctareader:
if set_required_num_cols[0]:
# hackishly doubly check for None and for cols in one pass
if len([v for v in row if v]) == set_required_num_cols[1]: