Skip to content

Instantly share code, notes, and snippets.

View marcus-crane's full-sized avatar
💭
Online and logged on

Marcus Crane marcus-crane

💭
Online and logged on
View GitHub Profile
@marcus-crane
marcus-crane / routes.go
Created June 16, 2021 01:49
Fiber golang example of showing child routes a la Django Rest Framework (could be improved)
package routes
import (
"sort"
"strings"
"github.com/gofiber/fiber/v2"
)
func Register(app *fiber.App) *fiber.App {
@marcus-crane
marcus-crane / radarr_tag_netflix.py
Created May 27, 2021 09:59
A hacky script for tagging films in Radarr that can be streamed on Netflix
from justwatch import JustWatch
from pyarr import RadarrAPIv3
client = JustWatch(country='NZ') # change to your country code
BASE_URL = 'http://192.168.1.100:7878'
API_KEY = '<api_key_here>'
FILMS_ON_NETFLIX = {}
radarr = RadarrAPIv3(BASE_URL, API_KEY)
@marcus-crane
marcus-crane / delete-firefox-devices.py
Created April 27, 2021 06:16
A python script for bulk deleting old devices
"""
Roughly based off https://gist.github.com/gbaman/b3137e18c739e0cf98539bf4ec4366ad
To grab your access token, log into https://accounts.firefox.com/settings
Open your browser dev tools (Right click -> Inspect Element), go to the Network tab
and refresh the page to populate the network stream.
Click on any one of the POST requests to https://graphql.accounts.firefox.com/graphql
and then under the Request Headers portion (at the bottom of the Headers tab),
copy the value for the Authorization Header. Just the token, not the Bearer text itself.
@marcus-crane
marcus-crane / convert.py
Created March 31, 2021 06:26
A small script used for changing Maildir message creation date to match date within the email itself
from mailbox import MaildirMessage
import time
from datetime import datetime
import os
from glob import glob
files = glob("*")
def update_mod_date(directory):
with open(directory, 'r') as f:
@marcus-crane
marcus-crane / ical2org.awk
Created January 28, 2021 07:49
Slightly modified version of ical2org.awk for my own use with Fastmail calendars
#!/usr/bin/gawk -f
# awk script for converting an iCal formatted file to a sequence of org-mode headings.
# this may not work in general but seems to work for day and timed events from Google's
# calendar, which is really all I need right now...
#
# Modified by Marcus Crane <[email protected]> slightly to have a human readable name
#
# usage:
# wget https://<calendar_url>.ics && \
# gawk -v calendar="My calendar" -f THISFILE < ical.ics > calendar.org
@marcus-crane
marcus-crane / proxy.sh
Created October 28, 2020 20:34
A couple of shell scripts for toggling on and off an enterprise proxy
#!/bin/zsh
proxy_host="<ip>:<port>"
proxy_state="$HOME/.proxy"
proxy_script="$HOME/dotfiles/work/proxy.sh"
if [[ ! -f $HOME/.proxy ]]; then
echo "No proxy state file found."
echo "Now creating with default state of 'on'"
echo "on" > $HOME/.proxy
fi
@marcus-crane
marcus-crane / csv_to_geojson.py
Created October 6, 2018 05:58
A script for converting LINZ's NZ Road Addressing dataset from a CSV into GeoJSON
import csv
import sys
from geojson import LineString, MultiLineString, Feature, GeometryCollection, FeatureCollection, dumps
csv.field_size_limit(sys.maxsize)
def cleanup_coord_string(shape):
if 'MULTILINESTRING' in shape:
shape = shape.replace('MULTILINESTRING', '')
else:
@marcus-crane
marcus-crane / ldap_client.py
Last active May 1, 2019 00:07
An LDAP wrapper for talking to Active Directory
from ldap3 import Server, Connection, ALL, ALL_ATTRIBUTES, NTLM, SYNC
class LDAPClient:
def __init__(self, username, password, base, url):
self.username = username
self.password = password
self.base = base
self.url = url
self.connection = None
@marcus-crane
marcus-crane / pocketlarder.py
Created July 21, 2018 09:58
A quick script for porting Pocket (https://getpocket.com) bookmarkers to Larder (https://larder.io)
import requests
import json
pocket_consumer_key = ""
pocket_access_token = ""
larder_key = ""
def fetch_pocket():
payload = {'consumer_key': pocket_consumer_key, 'access_token': pocket_access_token, 'state': 'unread'}
url = 'https://getpocket.com/v3/get'
@marcus-crane
marcus-crane / postcode.sh
Created June 14, 2018 21:38
Bash postcode checker [WIP]
curl -X GET -G --header "Referer: https://nzpost.co.nz" -d q=1%20Watt%20Street,%20Parnell -d public_api_key=245ae700-0800-4344-82dc-46bce23d09e0 https://address.nzpost.co.nz/api/suggest.json | jq '.addresses[0].FullAddress' | rev | cut -c2-5 | rev