View game-of-life.py
import itertools
# Conway's Really Simple Game of Life based on "Stop Writing Classes" PyCon 2012
def neighbors(point):
x,y = point
yield x + 1, y
yield x - 1, y
yield x, y + 1
yield x, y - 1
View Smooth_72_percent_off.log
ct@MBA45:code$ python test_progress.py
('A', 0.9180472184659397, 0.0, ZeroDivisionError('float division by zero',))
('B', 0.9180472184659397, 0.0, ZeroDivisionError('float division by zero',))
0% @ 0.92s: -1.00s vs -1.00s
1% @ 1.45s: 143.46s vs 143.46s
2% @ 2.31s: 113.04s vs 128.25s
3% @ 2.75s: 88.78s vs 115.09s
4% @ 2.75s: 65.92s vs 102.80s
5% @ 3.29s: 62.56s vs 94.75s
6% @ 3.78s: 59.21s vs 88.83s
View cleancode.sh
# entire file, CLI code, inplace
perl -0777pe "
# whitespace
s/ /\t/g; # Tabs indent at a uniform and viewer-custom size.
s/\t +/\t\t/g; # Do not mix tabs and spaces.
s/ / /g;
s/\r\n/\n/g; # Nor line endings.
s/(catch|for|foreach|function|if|switch|while)\s+\(/\1\(/g; # Compact flow.
s/\}\s+el(if|se)/\}el\1/g;
s/\s+\{/\{/g; # Useless when indenting.
View .profile
# .profile is used by both Bash and Zsh, .bash_profile only by Bash, and .bashrc by Bash but not on MacOS (no colors, for one).
export PATH="$(brew --prefix homebrew/php/php71)/bin:$PATH"
export CLICOLOR=1
export GREP_OPTIONS='--color=auto'
# Zsh doesn't see these in MacOS Sierra
alias g='pcregrep -MHrn --color=auto'
alias d='diff -Bwurx ".*"'
# Inherit prompt user@host:yellow path$
export PROMPT=$'%n@%m:\e[33m%c\e[0m%# ' # Zsh
export PS1='\u@\h:\[\e[33m\]\W\[\e[m\]\$ ' # Bash
View MacOS_sucks.md

Windows shortcut equivalents:

  • PageUp/Down = Fn+Up/Down
  • Home/End = Cmd+Left/Right
  • Delete = Fn+Backspace
  • Alt+Tab = triple swipe down (per app) or triple swipe up (all apps not minimized windows), or install HyperDock (only that doesn't do minimized windows).
  • Ctrl+Alt+Del = Cmd+Alt+Esc (only to kill apps)
  • Cmd+L = Ctrl+Shift+Power (Ctrl+Shift+Eject if possible, and require a password after sleep/screensaver)
  • PrintScreen = Cmd+Shift+3 (also saves to desktop)
  • Ctrl+C/V/X = Cmd+C/V/X
View commit_all.sh
#!/bin/bash
# https://stackoverflow.com/a/7841728/819417
for DIR in `ls`;
do
if [ -d $DIR/.git ];
then
echo "********"
echo "Updating location: " $DIR;
cd $DIR
View simple_git_workflow.md

Master is the (preferably working) development branch in most git branching models. (GitHub Flow, GitLab Flow, etc.; not Git Flow.) If you want to stabilize for a release, create a release branch and only merge bug fixes from master to it. When a branch works in your local environment (e.g. VirtualBox), push it to the remote. Ideally, merge requests should get reviewed and the remote production branch should get tested and deployed after it passes.

View gotchas.sql
-- istest != 1 does not match null, so do this:
update payments set istest = 0 where istest is null;
-- Multiplication requires exact values; use NUMERIC or DECIMAL with length "digits,digits", eg "12,2":
ALTER TABLE payments MODIFY COLUMN payments.amount NUMERIC(12,2);
-- utf8 is not enough for emoji in MySQL; it uses "utf8mb4" for that. Fix your database:
-- https://stackoverflow.com/a/39465494/819417
SELECT concat('ALTER TABLE ', TABLE_NAME, ' CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;')
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'your_db_name'
View mojibake.py
#!/usr/local/bin/python3
# -*- encoding: utf8 -*-
# http://stackoverflow.com/a/39549102/819417
print ( "\nEmoji to mojibake (origin):")
for emojiChar in ['😊','😣','👽','😎']:
print(emojiChar, emojiChar.encode('utf8').decode('cp1252'))
print ( "\nmojibake to Emoji (repair):")
for mojibakeString in ['😊','😣','👽','😎','🙇']: