Skip to content

Instantly share code, notes, and snippets.

Avatar

Bachsau

View GitHub Profile
@Bachsau
Bachsau / pythonrc.py
Created Jul 19, 2020
~/.pythonrc to make `exit` work without parentheses
View pythonrc.py
# ~/.pythonrc
# -*- coding: utf-8 -*-
# Make `exit` work without parentheses
import sys
if "site" in sys.modules:
Quitter = type(exit)
Quitter.__str__ = Quitter.__repr__
Quitter.__repr__ = Quitter.__call__
del Quitter
@Bachsau
Bachsau / backup-history.sh
Last active Jul 18, 2020
Bash history backup script
View backup-history.sh
#!/bin/bash --login
# Make a backup of the user's Bash history
if [ -z "${HISTFILE}" ]; then
cd "${HOME}"
hfile='.bash_history'
else
cd "${HISTFILE%/*}"
hfile="${HISTFILE##*/}"
fi;
@Bachsau
Bachsau / dwarf_fortress.svg
Last active Mar 1, 2020
Handmade vector icon for Dwarf Fortress
View dwarf_fortress.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Bachsau
Bachsau / virtual_oserror.py
Last active May 27, 2020
A custom exception class that closely resembles Python’s OSError
View virtual_oserror.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# A custom exception class that closely resembles the behavior of
# Python’s built-in OSError, including arguments and automatic
# subclassing. Useful if a fine-grained error handling based on
# error numbers is needed.
class VirtualOSError(Exception):
"""Base exception for all virtual OS related errors.
@Bachsau
Bachsau / configuration_manager.py
Last active Aug 25, 2020
A simple abstraction of Python’s ConfigParser
View configuration_manager.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# A simple abstraction of Python’s ConfigParser.
# It features implicit type conversion and defaults through prior
# registration of settings. It can be used to save and read settings
# without bothering about the specifics of ConfigParser or the INI files
# themselves. It could also serve as a starting point to abstract
# platform-specific saving methods through its general API.
@Bachsau
Bachsau / stop_dangerous_names.php
Last active Aug 27, 2020
Stop PHP’s dangerous name handling
View stop_dangerous_names.php
<?php
// Stop PHP’s dangerous name handling
function undefined_name_error($errno, $errstr, $errfile='', $errline=0, $errcontext=NULL) {
if (stripos($errstr, 'Undefined') !== false) {
error_log("PHP Fatal error: $errstr in $errfile on line $errline");
exit(255);
}
else {
return false;
You can’t perform that action at this time.