View file_downloader.py
"""Download with automatic resume.
2018-06-28 v1.0 by Cees Timmerman
2018-07-09 v1.1 Added If-Unmodified-Since header for consistency."""
import os, shutil, sys, time
import requests # python -m pip install requests
def download_file(url, local_filename=None):
if not local_filename:
local_filename = url.split('/')[-1]
View OOM_killer.py
"""Out Of Memory (OOM) Killer
2018-02-08 v1.0 by Cees Timmerman
2018-04-18 v1.0.1 Fix for Windows.
2018-04-27 v1.0.2 Use process ID in Windows.
2018-05-01 v1.1 Account for HP's RAM tester.
"""
import operator, os, subprocess, time
#import tkinter as tk
#import tkinter.messagebox
import psutil # python -m pip install psutil
View HelloWorld.java
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
public class HelloWorld{
private static HelloWorld instance;
public static void main(String[] args){
instantiateHelloWorldMainClassAndRun();
View SICP_Scheme_sucks.py
""" SICP section 2.2.3, page 160.
We can rearrange the pieces and use them in computing the product of the squares of the odd integers in a sequence:
(define (product-of-squares-of-odd-elements sequence) (accumulate * 1 (map square (filter odd? sequence))))
(product-of-squares-of-odd-elements (list 1 2 3 4 5))
225
2017-09-13 v1.0 Translated & benchmarked by Cees Timmerman
"""
from __future__ import print_function # For Python 2.
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