Skip to content

Instantly share code, notes, and snippets.

View ericdorsey's full-sized avatar

Eric Dorsey ericdorsey

View GitHub Profile
@ericdorsey
ericdorsey / parse_chess_com_pgn.md
Created February 16, 2020 06:21
Parse a Chess.com PGN w/ Vim Regex

Parse A Chess.com PGN With Vim Regex

Copy only the moves part of a Chess.com PGN, including the game result into Vim:

1. e4 {[%clk 0:02:59.9]} 1... e5 {[%clk 0:02:55.1]} 2. Nf3 {[%clk 0:02:58.7]}
2... Nc6 {[%clk 0:02:53.6]} 3. Bb5 {[%clk 0:02:57.1]} 3... a6 {[%clk 0:02:51.3]}
                ... // SNIP // ...
0:00:04.4]} 49. Kf4 {[%clk 0:00:01.3]} 49... g5+ {[%clk 0:00:03.9]} 50. Kf5
{[%clk 0:00:00.4]} 50... Bd3+ {[%clk 0:00:03.4]} 0-1
@ericdorsey
ericdorsey / rhind_papyrus.py
Created September 1, 2019 19:50
Rhind Papyrus: Multiplication by Doubling and Halving (Mediation & Duplation)
#!/usr/bin/python3
# Multiplication by Doubling and Halving (Mediation & Duplation)
# http://www.mathnstuff.com/math/spoken/here/2class/60/egyptm.htm
def rhind_papyrus(num1, num2):
# Egyptian Reed Papyrus Multiplication
num1_floors = []
num2_doubles = []
@ericdorsey
ericdorsey / list-only-hidden.md
Last active September 10, 2017 17:49
(Linux) List only hidden files, and only the file name

In Linux, list only hidden files, and only the file name (no owner, perms, etc)

$ ls -1d1 .!(|.)

This was useful in the context of creating an exclude list for some rsync jobs, where I only wanted to capture things like .bashrc and .vimrc, but didn't care bout a lot of the other profile config in the backup.

Insert a character only on non-empty lines. Below inserts a > on all non- blank lines:

%s/[^$]/> \0/

@ericdorsey
ericdorsey / raspbian_static_ip.md
Created September 7, 2016 00:27
Raspbian Static IP config
@ericdorsey
ericdorsey / ise_color_change.ps1
Created August 20, 2016 23:41
PS ISE Color Change + Revert
# Mess up the ISE colors
#$console.ForegroundColor = "white"
#$console.BackgroundColor = "DarkBlue"
# Revert colors back
# https://blogs.technet.microsoft.com/heyscriptingguy/2015/11/13/set-powershell-ise-to-default-values/
$psISE.Options.RestoreDefaults()
@ericdorsey
ericdorsey / kill_steam_processes.ps1
Created August 20, 2016 23:40
PS Kill Steam Processes
<#
Steam has an annoying habit of leaving a process hanging when it crashes.
This script finds the process ID and kills it.
#>
# Get the Steam processes
$steam_processes = Get-Process | Where {$_.name -like "Steam"}
@ericdorsey
ericdorsey / require_sudo_pi_user.md
Created August 11, 2016 02:40
Require sudo for pi user
$ sudo visudo

Change
pi ALL=(ALL) NOPASSWD: ALL

to

pi ALL=(ALL) PASSWD: ALL

@ericdorsey
ericdorsey / pretty_etc_passwd.md
Created August 11, 2016 02:24
Pretty /etc/passwd

awk -F ":" '{ print $1 }' /etc/passwd | sort

@ericdorsey
ericdorsey / python_sigterm_handling.py
Created July 6, 2016 02:53
Python SIGTERM handling
# https://docs.python.org/2/library/signal.html#signal.signal
import signal
import sys
import os
def signal_term_handler(signal, frame):
if signal == 15:
print("got SIGTERM")
sys.exit(0)