Skip to content

Instantly share code, notes, and snippets.

View MLKrisJohnson's full-sized avatar

Kris Johnson MLKrisJohnson

View GitHub Profile
@MLKrisJohnson
MLKrisJohnson / dechex.sh
Last active August 26, 2016 02:22
Bash/zsh functions for converting command-line arguments between decimal and hex
d2x() {
printf "%x\\n" $1
}
x2d() {
echo $((16#$1))
}
#!/bin/sh
# This script is used as an "External Build Tool"
case $1 in
clean)
make clean
;;
*)
make -j6 dcb-all
@MLKrisJohnson
MLKrisJohnson / dateFormatterMonth.swift
Last active November 11, 2016 13:50
Example of using NSDateFormatter to get/parse month names for user's locale/calendar.
import Foundation
let dateFormatter = DateFormatter()
let calendar = dateFormatter.calendar!
dateFormatter.dateFormat = "MMMM"
let now = Date()
let nowAsString = dateFormatter.string(from: now) // "November"
let september = dateFormatter.date(from: "September")!
@MLKrisJohnson
MLKrisJohnson / .gvimrc
Created January 26, 2017 15:24
My .vimrc and .gvimrc
if has('win32') || has('win64')
set guifont=Consolas:h12:cANSI
command! BigFont set guifont=Consolas:h15:cANSI
command! SmallFont set guifont=Consolas:h12:cANSI
command! TinyFont set guifont=Consolas:h9:cANSI
else
set guifont=Source\ Code\ Pro\ Light:h15
command! BigFont set guifont=Source\ Code\ Pro\ Light:h18
command! SmallFont set guifont=Source\ Code\ Pro\ Light:h15
command! TinyFont set guifont=Source\ Code\ Pro\ Light:h10
@MLKrisJohnson
MLKrisJohnson / unz.sh
Created February 2, 2017 19:38
Bash/zsh function to unzip a set of files to a set of directories
# Unzip a set of files to archive-specific directories
# Example: unz *.zip
unz() {
if [ -z "$1" ]; then
echo 'usage: unz FILE...'
else
for file in "$@"; do
/usr/bin/unzip -d "$file.unz" "$file"
done
fi
@MLKrisJohnson
MLKrisJohnson / ioreturndecode.mm
Last active June 21, 2017 15:15
Objective-C++ program to decode an IOReturn/kern_return_t value
// Decodes an IOReturn/kern_return_t value.
// See https://developer.apple.com/library/content/qa/qa1075/_index.html for details
#include <iostream>
#include <iomanip>
#include <mach/error.h>
using std::cout;
using std::cerr;
@MLKrisJohnson
MLKrisJohnson / newhtml.sh
Created August 8, 2017 20:50
Bash script to generate a minimal HTML 5 document
# Write a minimal HTML document to standard output
newhtml() {
cat <<END
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Title</title>
<!-- <link rel="stylesheet" href="style.css"> -->
<!-- <script src="script.js"></script> -->
@MLKrisJohnson
MLKrisJohnson / coderunner_dotnet.sh
Created June 13, 2018 17:08
Compile script for using .NET Core with CodeRunner <https://coderunnerapp.com>
#!/bin/bash
# To use CodeRunner with .NET Core on a Mac, do this:
#
# 1. Buy CodeRunner <https://coderunnerapp.com>
# 2. Download and install .NET Core SDK from <https://www.microsoft.com/net/learn/get-started/macos>
# 3. Launch CodeRunner and open its Preferences
# 4. In the Languages pane:
# - Select the existing "C#" language (which is for Mono), click the
# gear icon at the bottom of the window and choose Duplicate, then
@MLKrisJohnson
MLKrisJohnson / defines_to_cases.awk
Created June 27, 2018 13:08
AWK script for generating switch/case statements to stringify #define'd macro names
#!/usr/bin/env awk -f
# Given a C-like header file, this AWK script will generate a sequence
# of case statements for stringifying macro names.
#
# For example, if the input file looks like this:
#
# #define kIOReturnSuccess KERN_SUCCESS // OK
# #define kIOReturnError iokit_common_err(0x2bc) // general error
# #define kIOReturnNoMemory iokit_common_err(0x2bd) // can't allocate memory
@MLKrisJohnson
MLKrisJohnson / configure_logging.py
Last active September 21, 2022 19:38
Example of configuring the Python logging module with a custom format
import logging
def configure_logging(level=logging.DEBUG):
"""Configure the logging module.
"""
logging.basicConfig(
format="%(asctime)s.%(msecs)03d %(levelname)-7s %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
level=level)