Skip to content

Instantly share code, notes, and snippets.

View JamesTheAwesomeDude's full-sized avatar

James E. A. JamesTheAwesomeDude

View GitHub Profile
@JamesTheAwesomeDude
JamesTheAwesomeDude / RedditAtom.py
Created October 18, 2017 23:33
Clean up Reddit's defective Atom feed. Runs locally or as CGI.
#!/usr/bin/env python3
import cgi
#import cgitb
#cgitb.enable()
import json
import urllib.request
import urllib.parse
from html import unescape
from werkzeug.contrib.atom import AtomFeed
@JamesTheAwesomeDude
JamesTheAwesomeDude / register.sh
Created November 24, 2017 23:19
tl;dr of registering for Let's Encrypt
#!/bin/bash
SAN=("${@}")
SAN=( "${SAN[@]/#/DNS:}" )
openssl req -new\
-outform pem\
-out "${1}.csr"\
-newkey ec\
-pkeyopt ec_paramgen_curve:secp384r1\
-nodes\
-keyout "${1}.key"\
@JamesTheAwesomeDude
JamesTheAwesomeDude / nix-to-multiuser.md
Last active December 26, 2017 16:23
Converting Nix installation to multi-user

Tested on Debian Stretch so far

This is 90% pirated from https://gist.github.com/joepie91/043a51a7b70be5f50f1d but I made it a whole lot more sustainable / less invasive

I think I recorded all the steps in about the right order but ya never know

First, you'll need to install, at the very minimum curl and ca-certificates (I think you can remove them later if you want).

mkdir -v /nix
@JamesTheAwesomeDude
JamesTheAwesomeDude / minimal-xorg-setup.md
Created December 27, 2017 15:10
X.org without display manager on minimal Ubuntu Xenial / Debian Stretch installations

Without a display manager, you may get Cannot open log file "/var/log/Xorg.0.log" when attempting to startx as a regular user.

One solution I have found is this

usermod james -a -G video
chgrp -v video /usr/bin/Xorg
chmod -v 4754 /usr/bin/Xorg
@JamesTheAwesomeDude
JamesTheAwesomeDude / base2.py
Created May 22, 2018 16:27
Quick base2 encode
# from base2 import b2 as int_base2_repr
# int_base2_repr()
b2 = lambda i,p=8:'0b{0:0{1}b}'.format(i, p)
assert b2(6,4) == '0b0110' and b2(127) == '0b01111111'
# WARNING: "overflows" will OVERRIDE the length specifier
# and return a string that may be longer than you were expecting.
# You should double-check the returned string length yourself
# if this is a concern for you.
@JamesTheAwesomeDude
JamesTheAwesomeDude / hamming.py
Last active May 22, 2018 21:09
Hamming ([24,48] so far)
#!/usr/bin/env python
# Copyright 2018 James Edington
# Permission is given to use, modify,
# and redistribute (including modifications)
# in accordance with the MIT license available at
# https://opensource.org/licenses/MIT
# Version 0.0.3, May 22 2018
def __main__():
@JamesTheAwesomeDude
JamesTheAwesomeDude / username_parse.py
Last active May 28, 2018 20:33
Quickly parse [http[s]://][username[:password]@]hostname[:port][/path]
# [http[s]://][username[:password]@]hostname[:port][/path]
# from username_parse import parse as parse_u
# EXAMPLE USAGE:
# username,hostname,password,port,path,protocol = parse_u(argv[1])
# username = parse_u(argv[1])[0]
# ip,password = parse_u(argv[1])[1:3]
# host,port = parse_u(argv[1])[1:4:2]
# Not intended for use without a hostname
#Conceptual Lambda (vestigial,
@JamesTheAwesomeDude
JamesTheAwesomeDude / 10-LVDS-gamma.conf
Last active June 21, 2018 19:26
Fix laptop blue hue on Linux
# /etc/X11/xorg.conf.d/10-LVDS-gamma.conf
# Works on Debian and Ubuntu for at least the last 5 years
Section "Monitor"
Identifier "LVDS"
# Identifier "eDP-1"
Gamma 1.15 0.8 0.78 #tune to taste or accuracy
EndSection
# /etc/X11/xorg.conf.d/40-libinput-tapping.conf
# https://bugzilla.xfce.org/show_bug.cgi?id=14085
Section "InputClass"
Identifier "libinput touchpad catchall"
MatchIsTouchpad "on"
# MatchDevicePath "/dev/input/event*"
# Driver "libinput"
Option "tapping"
EndSection
@JamesTheAwesomeDude
JamesTheAwesomeDude / .htaccess
Last active June 21, 2018 19:32
shell script used as "CGI handler" to use .url files as "hotlinks"
#this does NOT have to be in webroot!
AddType text/x-url url
Action text/x-url /cgi-bin/webroot/relative/path/to/URL.cgi