Skip to content

Instantly share code, notes, and snippets.

@lmlsna
lmlsna / config
Last active October 17, 2017 18:16
Enable a lxc container to use a tuntap device
# Add these lines to the container's config
lxc.cgroup.devices.allow = c 10:200
lxc.hook.start /usr/local/bin/mktun
@lmlsna
lmlsna / python2rc.py
Created November 4, 2017 11:27
Enable tab completion in an interactive python2 shell
'''
This script enables tab competion for functions in the Python2 interactive shell.
It requires the readline and rlcompleter packages (install with pip) and set PYTHONSTARTUP
to this file's location as an enironmental variable in your .bashrc file.
'''
try:
import readline
except ImportError:
pass
@lmlsna
lmlsna / uniq
Created November 18, 2017 00:17
Bash script for a better version of the `uniq` shell command
#!/bin/bash
# uniq - The default version of the uniq command only finds uniques that are adjacent
# and has no flag to find non-adjacent lines... so pretty useless. This is a
# bash script that actually does what you would expect uniq to do.
# for every piped in line:
for w in $(cat); do
# if we haven't already added it before
if [[ "$(grep -o "$w" <<< "$once")" == "" ]]; then
# add it + newline
@lmlsna
lmlsna / ssh-on-first-boot-rpi.sh
Last active November 18, 2017 00:17
script to enable SSH on a fresh Raspbian (Raspberry Pi) install
#!/bin/bash
# Enables SSH on first boot by touching a blank file called `ssh` in the boot directory
# Requies the $disk argument (in the format /dev/sdX) to be set or passed as the fisrt command line flag.
disk="$disk$1"
if [[ -z "$disk" ]]; then
echo "You need to pass the install device (/dev/sdX) with the \$disk arg or as the 1st param"
exit 1
fi
@lmlsna
lmlsna / keybase.md
Created December 2, 2017 05:59
keybase.md

Keybase proof

I hereby claim:

  • I am lmlsna on github.
  • I am mlsna (https://keybase.io/mlsna) on keybase.
  • I have a public key ASAUo_z8mC69AnoQfAqJ1vnKKTSs4kfZjqoWi6iYP2KofQo

To claim this, I am signing this object:

@lmlsna
lmlsna / php.ini
Created January 17, 2018 09:08
PHP7 Error reporting values
error_reporting = E_ALL
display_errors = On
display_startup_errors = On
log_errors = On
track_errors = On
html_errors = On
error_prepend_string = "<span style='color: #ff0000'>"
error_append_string = "</span>"
@lmlsna
lmlsna / str_to_int.sh
Created February 1, 2018 01:35
Convert string to int in bash.
#!/bin/bash
# This is a simple bash function to change strings (of arbitrary length) into integers (of arbitrary maximums).
# I use this to convert my "user@hostname" to a number between 1-255 and use that as a persistent color for the
# termnal prompt to remind me what box/user I am on.
#
# It just hashes whatever string you give it, converts the hex to a decimal and then mods around whatever your max int is.
# Usage: str_to_int [string_to_convert] [max_int_size]
# Example: str_to_int "user@hostname" 255
#
@lmlsna
lmlsna / install-bootstrap.sh
Created February 15, 2018 08:51
Shell script to bootstrap Bootstrap 4
#!/bin/bash
# Shell script to bootstrap Bootstrap...
# JS Extra files w/ integrity hashes
JQ_URL="https://code.jquery.com/jquery-3.2.1.slim.min.js"
JQ_SHA384="KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
POP_URL="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
POP_SHA384="ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
@lmlsna
lmlsna / json2yaml.py
Created February 7, 2019 04:17
Convert JSON to YAML
#!/usr/bin/env python3
#
# Accepts a JSON file path as an optional argument, otherwise reads stdin
import os
import simplejson
import sys
import yaml
# If valid path to json file is passed
@lmlsna
lmlsna / list-ubuntu-apps.sh
Created February 23, 2019 02:38
Get a list of what is being shown in the Ubuntu Desktop's applications menu
#!/bin/bash
grep -Li 'nodisplay=true' /usr/share/applications/*.desktop