Skip to content

Instantly share code, notes, and snippets.

View skion's full-sized avatar

Pieter Ennes skion

View GitHub Profile
@skion
skion / google-access-token.py
Created March 14, 2023 11:52
Obtain an access token for a Google Service Account.
"""
Given a credentials file for a Google Service Account, obtain a short-lived
access token to access Google APIs. Such an access token can be used, for instance,
by a customer to upload external files to a Google Cloud Storage Bucket over HTTP.
To install required dependencies on Debian-based systems:
apt-get install python3-jwt python3-requests
or on other systems:
"""
A simple Flask error handler that turns exceptions into problem detail responses.
"""
from flask import Flask, current_app, jsonify
from werkzeug.exceptions import HTTPException, InternalServerError
def exception_to_problem_detail(exc: Exception):
"""
Turn an exception into a problem detail response.
@skion
skion / hunter.py
Created January 19, 2018 00:06
A Hunter.io client optimised for interactive usage, written in Python 3.
import collections.abc
import urllib.parse
from typing import Dict, List
from requests_cache import CachedSession
class DictView(collections.abc.Mapping):
"""
Provides a viw into another dictionary.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Convert a PEM encoded X509 certificate into a JWK RSA public key.
"""
import base64
import json
from cryptography import x509
from cryptography.hazmat.primitives import serialization
@skion
skion / ipsec-ios.md
Last active October 7, 2018 10:35
Racoon config that works with MacOS 10.11, iOS 8, Android 6.0
  • Add VPN Configuration
  • IPSEC
  • Server: your-ip
  • Account: shell user
  • Password: shell password
  • Use certificate: Off
  • Group name: Blank
  • Secret: your-strong-secret
Verifying that +skion is my openname (Bitcoin username). https://onename.io/skion
### Keybase proof
I hereby claim:
* I am skion on github.
* I am skion (https://keybase.io/skion) on keybase.
* I have a public key whose fingerprint is 2210 17C1 62D0 1494 7B63 9600 D3D2 1406 5962 D58F
To claim this, I am signing this object:
@skion
skion / pil_arc.py
Created February 27, 2014 21:28
Rough PIL draw.arc() replacement that supports a line width.
def arc(draw, bbox, start, end, fill, width=1, segments=100):
"""
Hack that looks similar to PIL's draw.arc(), but can specify a line width.
"""
# radians
start *= math.pi / 180
end *= math.pi / 180
# angle step
da = (end - start) / segments