Skip to content

Instantly share code, notes, and snippets.

View dvf's full-sized avatar

Daniel van Flymen dvf

View GitHub Profile
dvf /
Last active January 25, 2023 07:46
Example of recursively walking a folder using Django Storages API
from pathlib import Path
from import default_storage
def walk_folder(storage, base="/", error_handler=None):
Recursively walks a folder, using Django's File Storage.
:param storage: <Storage>
:param base: <str> The base folder
dvf /
Last active July 9, 2024 14:10
Enable High Quality mode on your headphones (Updated for macOS Catalina)

If you're using a high-end bluetooth headset on your Macbook Pro it's likely your mac is using an audio codec which favors battery efficiency over high quality. This results in a drastic degradation of sound, the SBC codec is the likely culprit, read more about it here.

Find out what codec you're using

  1. Play a song on your headphones
  2. Option (⌥) click the Bluetooth button at the top of your screen Inspect the Bluetooth Coded
  3. If you're using AAC or aptX, you can stop here—those are the highest quality codecs.

Change your codec to AAC or aptX

dvf /
Last active March 7, 2023 09:32
How on earth does Asyncio work

What are coroutines?

Coroutines are functions that can be paused. We define them using the async syntax:

async def say_something(what):

But coroutines can't be run directly:

dvf / MD5.js
Created May 19, 2019 20:20
MD5 Algorithm for Google Sheets
function MD5 (input) {
var digest = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, input);
var output = "";
for (i = 0; i < digest.length; i++) {
var h = digest[i];
if (h < 0) { h += 256; }
if (h.toString(16).length == 1) { output += '0'; }
output += h.toString(16);
return output;
dvf /
Last active December 6, 2022 13:20
Running Python locally without driving yourself insane

This is my highly opinionated way of developing with Python locally. Use it, don't use it. But you probably know that it's a PITA to manage different projects with different dependencies targeting different Python versions, and there are different ways of installing Python too:

  • Using the interpreters preinstalled in the OS 😵
  • Using brew (or apt etc.) 😅
  • Using the binaries from 😫
  • Using pyenv 😎
dvf /
Last active February 22, 2018 21:10
Creating a simple Blockchain in Python
class Blockchain(object):
def __init__(self):
self.current_transactions = []
self.chain = []
def new_block(self):
# Creates a new Block in the Blockchain
def new_transaction(self):
dvf /
Last active May 22, 2020 14:10
Step 12: New Endpoints for Consensus
@app.route('/nodes/register', methods=['POST'])
def register_nodes():
values = request.get_json()
nodes = values.get('nodes')
if nodes is None:
return "Error: Please supply a valid list of nodes", 400
for node in nodes:
dvf /
Last active May 22, 2020 14:11
Step 11: Implementing Consensus Algorithm
import requests
class Blockchain(object)
def valid_chain(self, chain):
Determine if a given blockchain is valid
dvf /
Last active March 31, 2021 18:16
Step 10: Registering Nodes
from urllib.parse import urlparse
class Blockchain(object):
def __init__(self):
self.nodes = set()
dvf /
Created September 23, 2017 20:31
Step 9: Consensus (Retrieve Chain)
@app.route('/chain', methods=['GET'])
def full_chain():
response = {
'chain': blockchain.chain,
'length': len(blockchain.chain),
return jsonify(response), 200