Skip to content

Instantly share code, notes, and snippets.

@ryannjohnson
ryannjohnson / application.service
Created June 15, 2020 07:17
Put in /etc/systemd/system/
[Unit]
Description=My application %I
After=network.target
[Service]
User=ubuntu
WorkingDirectory=/home/root/projects/project
Environment=PORT=5010
ExecStart=/path/to/executable arg1 arg2
Restart=always
# flock acquires a lock prior to running.
# timeout will kill the command if it's still funning at the end of the duration.
* * * * * flock -n /var/lock/my-task.lock timeout 45 my-task-command
# Suppress output of command so that other crons keeping going
* * * * * my-task-command > /dev/null 2>&1
@ryannjohnson
ryannjohnson / lifx_lights_daemon.py
Created October 12, 2018 06:13
Allows me to control all my lights by powering on/off one of my lights.
#!/usr/bin/env python3
"""
Allows me to turn any LIFX lights in my home on and off and have the
remaining lights follow suit.
Requires python 3.6 or higher.
To run:
$ virtualenv -p python3 env
#!/bin/bash
PREFIX=$1
COMMAND=$2
OUTPUT=$(eval "$COMMAND" 2>&1)
logger -i -t "$PREFIX" -- "$OUTPUT"
# This adds all non-whitespace characters to the index.
#
# Consider this a template into which other arguments can be added. For
# example, `git diff` can take filename args to limit its effects.
git diff -U0 -w --no-color | git apply --cached --ignore-whitespace --unidiff-zero -
@ryannjohnson
ryannjohnson / letsencrypt-acme-challenge.conf
Last active October 10, 2017 15:34
NGINX snippet for the LetsEncrypt acme challenge.
#############################################################################
# Configuration file for Let's Encrypt ACME Challenge location
# This file is already included in listen_xxx.conf files.
# Do NOT include it separately!
#############################################################################
#
# This config enables to access /.well-known/acme-challenge/xxxxxxxxxxx
# on all our sites (HTTP), including all subdomains.
# This is required by ACME Challenge (webroot authentication).
# You can check that this location is working by placing ping.txt here:
@ryannjohnson
ryannjohnson / rsa_signature_api.py
Created July 13, 2017 05:15
For me and @griefdad to synchronize our signing efforts.
import base64
from Crypto.PublicKey import RSA
from flask import Flask, request
from flask.json import jsonify
import json
from OpenSSL import crypto
import os
app = Flask(__name__)