View common_string_components.py
from itertools import zip_longest
def common_string_components(strings, separator=None):
def split_string(string):
if type(string) == str:
# if separator is '', split by character
if separator == '':
string = list(string)
else:
View import_rows_with_auto_increment_id.sql
LOCK TABLES test WRITE;
SET @next_id = (
SELECT AUTO_INCREMENT
FROM information_schema.TABLES
WHERE TABLE_SCHEMA=DATABASE() AND
TABLE_NAME='test'
);
INSERT INTO test
(id1, id2, id3)
VALUES
View created_updated_mysql.sql
// from MySQL 5.6.5+
CREATE TABLE test (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id)
);
// beware of the timezone you're storing the datetime at
View nix_php_package.md

Nix PHP Package

Shell.nix:

{
  pkgs ? import ./pkgs.nix,
  phpPath ? "php56"
}:
  with pkgs;
View mysql.sh
#!/usr/bin/env bash
# for when you want to start mysql in a current working directory
# unlike postgresql, many of the mysql commands do not use environment variables
# which requires you to use the aliases for shell commands
# just remember that aliases are not inherited by subprocesses
# externally set environment variables
# any variable that is unset will be defaulted
# if the variable is set and an empty string, it will be used literally
View postgresql.sh
#!/usr/bin/env bash
# for when you want to start postgresql in a current working directory
# externally set environment variables
# any variable that is unset will be defaulted
# if the variable is set and an empty string, it will be used literally
export PGDATABASE=postgres
export PGUSER=postgres
export PGPASSWORD=
View docker_x_gui.md

Run X GUI Applications in Docker

docker run -it --rm \
  --env='DISPLAY=:0' \
  --volume="$HOME/.Xauthority:/root/.Xauthority:ro" \
  --net=host \
  container
View script_directory.py
import os.path as path
from inspect import getsourcefile
path_to_this_script = path.abspath(getsourcefile(lambda: 0))
path_to_containing_dir = path.dirname(path_to_this_script)
View keras_multiprocessing_exit.py
# when using keras multiprocessing, it's process architecture is not robust to
# posix termination signals
# keras also doesn't expose the multiprocessing pool back to the user
# this means we need to use a signal handler that switches between the parent
# and child worker processes
# when doing this, we are taking control of the shutdown/cleanup procedures
# this means we need to use os._exit() instead of sys.exit()
# os._exit() will exit immediately without running any cleanup procedures
import os