Skip to content

Instantly share code, notes, and snippets.

View stewartadam's full-sized avatar

Stewart Adam stewartadam

View GitHub Profile
@stewartadam
stewartadam / README-linode-create.md
Last active September 13, 2018 13:25
A quick Python script that uses the Linode API to create, boot and delete Linodes. Supports an interactive mode that sends emails to users with their Linode credentials, great for providing temporary Linodes for a tutorial.

This is a little automation script I wrote to configure, boot and/or destroy Linodes using the Linode API. This script requires the Requires the linode-python module to wrap the API.

I had written this with the intent of providing users with a temporary Linode that would be destroyed after an hour or two, but the functions are pretty generic and could be repurposed. The interactive mode lets users enter their e-mail address, and upon confirmation sends them a message with their Linode's IP & password.

If you'd like to use this script as-is, you'll need to substitute in your Linode API key, SMTP server details and you will also likely have use the avail_foo() commands to grab the current IDs (e.g. for kernel release, distrubution, etc) and change the variables at the start of the script.

@stewartadam
stewartadam / scs-tutorial-linux-basics.sh
Last active April 2, 2019 19:51
Script used for the SCS Linux Basics tutorial at Concordia University (2016) - discussion about Linux basics & setting up Wordpress on a CentOS 7 machine
#!/bin/sh
###
### Example usage of common commands
###
# pwd
# ls # it's empty
# cd /var/log # there are some files
###
@stewartadam
stewartadam / scs-tutorial-linux-shared-hosting-server.sh
Created March 10, 2016 04:48
CentOS 7 shared hosting server setup script based on the SCS Shared Linux Hosting Server Security tutorial at Concordia University (2016) - discussion about security principles in the context of a shared hosting server.
#!/bin/sh
#
# Usage:
# This script will establish a basic shared hosting server running DNS, Web (HTTP), DB (SQL) and e-mail (SMTP/IMAP) services.
#
# This script doesn't include usage information on adding new user accounts and setting up mail inboxes; for that, please see my
# CentOS 5 server setup tutorial: http://www.firewing1.com/howtos/servers/centos5/getting_started
#
# This configuration is very similar to my previously documented CentOS 5 server setup, but has been ported to take advantage
# of the new features in CentOS 7.
@stewartadam
stewartadam / calc.py
Created January 16, 2017 08:28
contour-lines-dataviz
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Calculates the x,y co-ordinates of the contour lines given a 2D grid of land
heights, with the origin in the bottom-left corner.
"""
import math
# cheap scope hack
CONTOURS = {}
@stewartadam
stewartadam / memcached-multi.init
Created April 9, 2017 07:07
memcached-multi, a RHEL6 initscript with support for easily managing multiple memcached services
#! /bin/bash
#
# chkconfig: - 55 45
# description: The memcached daemon is a network memory cache service.
# processname: memcached
### END INIT INFO
# Based on https://gist.github.com/lboynton/3775818
# Usage:
# cp /etc/sysconfig/memcached /etc/sysconfig/memcached-server1
@stewartadam
stewartadam / plex-systemd-nspawn-setup.sh
Last active June 21, 2018 01:47
Installing Plex in a systemd-nspawn container
CONTAINER_NAME="plex"
CONTAINER_ROOT="/var/lib/machines/$CONTAINER_NAME"
BRIDGE_INTERFACE=br0
mkdir "$CONTAINER_ROOT"
sudo dnf --releasever=25 --installroot="$CONTAINER_ROOT" install systemd passwd dnf fedora-release NetworkManager
systemd-nspawn -D "$CONTAINER_ROOT" --network-bridge="$BRIDGE_INTERFACE"
# Install Plex RPM here, then 'exit' or press Ctrl+] 3x to kill container
mkdir -p /etc/systemd/nspawn
@stewartadam
stewartadam / StubController.java
Last active April 4, 2018 17:59
Spring Redirect to Azure AD
@RestController
class StubController {
@RequestMapping("/resource/{id}")
ModelAndView resource(ModelMap model, HttpServletRequest request, @PathVariable String id) {
model.addAttribute("attribute", "forwardWithForwardPrefix");
String client_id = "";
int state = (int )(Math.random() * 1000000 + 1);
String resource = "client_id_guid_of_fhir";
@stewartadam
stewartadam / 00-docker-linuxserver-README.md
Last active October 11, 2022 17:13
systemd configuration for containers on boot with docker-compose (via linuxserver.io, among others)

Overview

This sample is intended for modern Linux systems using systemd (Fedora, Ubuntu, Arch, etc).

Installation

Install the files in this gist, replacing dashes for slashes (e.g. etc-systemd-system-dockercompose.service should be installed to /etc/systemd/system/dockercompose.service) and then run systemctl enable --now dockercompose.service to get things started.

Usage

Any manual docker-compose commands should be run from /srv/appdata/linuxserver so that the values from the .env file are applied properly.

Log files can be viewed by running docker-compose -f --tail=50.

@stewartadam
stewartadam / main.py
Last active March 5, 2024 16:02 — forked from gear11/main.py
Simple Python proxy server based on Flask and Requests with support for GET and POST requests.
"""
A simple proxy server, based on original by gear11:
https://gist.github.com/gear11/8006132
Modified from original to support both GET and POST, status code passthrough, header and form data passthrough.
Usage: http://hostname:port/p/(URL to be proxied, minus protocol)
For example: http://localhost:5000/p/www.google.com
"""
import re
@stewartadam
stewartadam / LICENSE
Last active June 29, 2018 03:07
Default license to apply for all of my Gists that (1) are not forked and (2) do not have a file named LICENSE
MIT License
Copyright (c) 2018 Stewart Adam
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: