Skip to content

Instantly share code, notes, and snippets.

Avatar

Eric Dorsey ericdorsey

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

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 Sep 1, 2019
Rhind Papyrus: Multiplication by Doubling and Halving (Mediation & Duplation)
View rhind_papyrus.py
#!/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 Sep 10, 2017
(Linux) List only hidden files, and only the file name
View list-only-hidden.md

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.

View vim_non-empty-line_replace.md

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 Sep 7, 2016
Raspbian Static IP config
View raspbian_static_ip.md
@ericdorsey
ericdorsey / ise_color_change.ps1
Created Aug 20, 2016
PS ISE Color Change + Revert
View ise_color_change.ps1
# 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()
View kill_steam_processes.ps1
<#
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"}
View require_sudo_pi_user.md
$ sudo visudo

Change
pi ALL=(ALL) NOPASSWD: ALL

to

pi ALL=(ALL) PASSWD: ALL

View pretty_etc_passwd.md

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

View python_sigterm_handling.py
# 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)