Skip to content

Instantly share code, notes, and snippets.

View samdbmg's full-sized avatar

Sam Mesterton-Gibbons samdbmg

View GitHub Profile
@samdbmg
samdbmg / proxy_with_oauth.py
Last active June 20, 2024 08:28
Proxy a remote API secured using an OAuth2 client credentials grant, exposing it locally without auth
# Taken partly from https://stackoverflow.com/a/36601467
from datetime import datetime, timedelta
import os
from authlib.integrations.httpx_client import AsyncOAuth2Client
from sanic import Sanic
from sanic.log import logger
from sanic.response import raw
# This should be the full token endpoint URL,
@samdbmg
samdbmg / git-ssh-wrapper
Created April 23, 2017 10:07
Codenvy GIT_SSH script to get private key
#!/bin/bash
set -e
if [ $1 = "-p" ]
then
host=$(echo "$3" | sed -e 's/git@//')
else
host=$(echo "$1" | sed -e 's/git@//')
fi
@samdbmg
samdbmg / start-syncthing.sh
Created February 28, 2017 15:09
Script to run syncthing in a screen session, with a proxy set
#!/bin/bash
if [ "$1" == "run" ];
then
while true
do
all_proxy=socks5://socks-gw:1080 /usr/bin/syncthing -no-browser -logfile=/tmp/syncthing.log
sleep 1
done
fi
@samdbmg
samdbmg / .startterminal.sh
Created August 31, 2016 15:11
Run the Cygwin gnome-terminal from a Windows shortcut (and start the keyring daemon)
#!/bin/bash
# Place this somewhere sensible - your Cygwin home directory should suffice
export DISPLAY=:0.0
#if [ -n "$DESKTOP_SESSION" ];then
eval $(gnome-keyring-daemon --start)
export SSH_AUTH_SOCK
export GNOME_KEYRING_CONTROL
#fi
@samdbmg
samdbmg / camera-disk-rsync.sh
Created August 22, 2016 16:06
Rsync a folder to two drives at the same time
#!/bin/bash
if [ $# -lt 4 ];
then
echo "Usage: camera-disk-rsync.sh DESTINATIONFOLDER MOUNT1 MOUNT2 SOURCEFILE\r\n"
echo "Where MOUNT1 and MOUNT2 are the mountpoints of the two drives"
exit
fi
foldername=$1
@samdbmg
samdbmg / configure-cameras.sh
Created August 18, 2016 10:49
Configure multiple GoPro Hero4's over wifi (for 360 balls etc)
#!/bin/bash
# Requires goproctl from https://github.com/joshvillbrandt/goprohero
# Expects ssid and password as arguments
# Settings from https://github.com/KonradIT/goprowifihack/blob/master/HERO4/WifiCommands.md
function set_camera {
if [ -e /tmp/gperr ];
then
rm /tmp/gperr
fi
@samdbmg
samdbmg / ConvertMailToTask.vb
Created June 6, 2016 08:49
VBA script for an Outlook rule to pick up mail with "Task: " in the subject line, and create an Outlook task from it
Sub ConvertMailToTask(Item As Outlook.MailItem)
Dim objTask As Outlook.TaskItem
Set objTask = Application.CreateItem(olTaskItem)
Dim taskSplit As New RegExp
taskSplit.Pattern = "^task[:]?\s*"
taskSplit.Global = True
taskSplit.MultiLine = True
taskSplit.IgnoreCase = True
@samdbmg
samdbmg / pwm_setup.c
Created January 26, 2015 13:58
Enable PWM timer output on STM32F4 using peripheral library (not STM Cube)
/* Board support headers */
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_tim.h"
#include "stm32f4xx_rcc.h"
#define TIMER_BASE_FREQUENCY 72000000
#define PWM_FREQUENCY 40000
#define PWM_TICKS TIMER_BASE_FREQUENCY/PWM_FREQUENCY
@samdbmg
samdbmg / TemplateTool.py
Created June 11, 2014 00:54
A simple HTML templating system - wraps a template file (such as a menu) around a named div containing content.
import os
import sys
from bs4 import BeautifulSoup
"""Bogotemplater template engine
Wraps a specified element in every HTML file in target directory with a template file
"""