Skip to content

Instantly share code, notes, and snippets.

View lachholden's full-sized avatar

Lachlan Holden lachholden

View GitHub Profile
@akkornel
akkornel / id_token_demo.py
Created July 13, 2021 04:11
A Python 3.6+ script showing how to get an OpenID Connect Token from Google Auth, and comparing the one you get with your own OAuth2 client ID against the one you get with the Google Cloud SDK OAuth2 client ID
#!/usr/bin/env python3
# vim: ts=4 sw=4 et
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: MIT
# This was written by A. Karl Kornel <akkornel@stanford.edu>
# It is © The Board of Trustees of the Leleand Stanford Junior University
# It is made available under the MIT License
# https://opensource.org/licenses/MIT
@rlabbe
rlabbe / real_time_plotting.py
Last active March 14, 2023 13:09
Plot with matplotlib with real time updates without plt.pause
# draw the figure so the animations will work
import matplotlib.pyplot as plt
fig = plt.gcf()
fig.show()
fig.canvas.draw()
while True:
# compute something
plt.plot([1, 2, 3, 4, 5], [2, 1, 2, 1, 2]) # plot something
@nickelpro
nickelpro / mcvarint.py
Created November 5, 2013 02:20
Two python functions that implement the new Minecraft varint type (32-bit signed integers packed into Google protobuf varints). Packs varints into a byte string, unpacks varints from a buffer that has a read(bytes) method. Supports negative numbers even though they aren't used in the current protocol.
import struct
def pack_varint(val):
total = b''
if val < 0:
val = (1<<32)+val
while val>=0x80:
bits = val&0x7F
val >>= 7
total += struct.pack('B', (0x80|bits))
@ib-lundgren
ib-lundgren / github_flask_oauth2.py
Created September 10, 2013 10:53
Example of how to use Flask with requests-oauthlib to fetch a GitHub user profile using an OAuth 2 token.
from requests_oauthlib import OAuth2Session
from flask import Flask, request, redirect, session, url_for
from flask.json import jsonify
import os
app = Flask(__name__)
# This information is obtained upon registration of a new GitHub
client_id = "<your client key>"