Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Automate Everything

Craig Derington craigderington

🚀
Automate Everything
View GitHub Profile
View results.py
import fastf1 as ff1
from fastf1 import plotting
from fastf1 import utils
from matplotlib import pyplot as plt
from matplotlib.pyplot import figure
import numpy as np
import pandas as pd
# enable the cache
ff1.Cache.enable_cache('cache')
View recursive_dict_get.py
def recursive_dict_get(d, *keys, default_none=False):
"""Recursive dict get. Can take an arbitrary number of keys and returns an empty
dict if any key does not exist. https://stackoverflow.com/a/28225747"""
ret = reduce(lambda c, k: c.get(k, {}), keys, d)
if default_none and ret == {}:
return None
else:
return ret
View signalR.py
from signalr_aio import Connection
from base64 import b64decode
from zlib import decompress, MAX_WBITS
import json
# decode the payload
def process_message(message):
deflated_msg = decompress(b64decode(message), -MAX_WBITS)
return json.loads(deflated_msg.decode())
@craigderington
craigderington / hashed_messaging.py
Created Jun 6, 2021
Digital Signature Verification with Python and hmac
View hashed_messaging.py
import os
import hashlib
import uuid
import hmac
from datetime import datetime, timedelta
my_api_key = os.urandom(64)
def verify(api_key, token, timestamp, signature):
View asyncio.py
import asyncio
class EchoClientProtocol(asyncio.Protocol):
def __init__(self, message, loop):
self.message = message.encode()
def connection_made(self, transport):
self.transport = transport
self.write_data()
View javascripting.js
// coding: utf-8
// example 1
// string length
// given the following string, 'this example string', write the string length to the console
var string = 'this example string';
console.log(string.length);
View async_socket_server.py
import asyncio, socket
async def handle_client(reader, writer):
request = None
while request != 'quit':
request = (await reader.read(255)).decode('utf8')
response = str(eval(request)) + '\n'
writer.write(response.encode('utf8'))
await writer.drain()
writer.close()
View async_echo_server.py
#!/usr/bin/env python3.4
import asyncio
class EchoServer(asyncio.Protocol):
def connection_made(self, transport):
peername = transport.get_extra_info('peername')
print('connection from {}'.format(peername))
self.transport = transport
def data_received(self, data):
View async_echo_client.py
#!/usr/bin/env python3.4
import asyncio
class EchoClient(asyncio.Protocol):
message = 'Client Echo'
def connection_made(self, transport):
transport.write(self.message.encode())
print('data sent: {}'.format(self.message))
View alacritty.yml
# alacritty
env:
TERM: xterm-256color
window:
dimensions:
columns: 120
lines: 48
padding:
x: 10