Skip to content

Instantly share code, notes, and snippets.

View dvf's full-sized avatar

Daniel van Flymen dvf

View GitHub Profile
@dvf
dvf / walk_folders.py
Last active January 25, 2023 07:46
Example of recursively walking a folder using Django Storages API
View walk_folders.py
from pathlib import Path
from django.core.files.storage 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
dvf / change-codec.md
Last active February 27, 2024 02:09
Enable High Quality mode on your headphones (Updated for macOS Catalina)
View change-codec.md

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
dvf / asyncio.md
Last active March 7, 2023 09:32
How on earth does Asyncio work
View asyncio.md

What are coroutines?

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

async def say_something(what):
    print(what)

But coroutines can't be run directly:

@dvf
dvf / MD5.js
Created May 19, 2019 20:20
MD5 Algorithm for Google Sheets
View MD5.js
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
dvf / python-setup.md
Last active December 6, 2022 13:20
Running Python locally without driving yourself insane
View python-setup.md

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 www.python.org 😫
  • Using pyenv 😎
@dvf
dvf / blockchain.py
Last active February 22, 2018 21:10
Creating a simple Blockchain in Python
View blockchain.py
class Blockchain(object):
def __init__(self):
self.current_transactions = []
self.chain = []
def new_block(self):
# Creates a new Block in the Blockchain
pass
def new_transaction(self):
@dvf
dvf / blockchain.py
Last active May 22, 2020 14:10
Step 12: New Endpoints for Consensus
View blockchain.py
@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:
blockchain.register_node(node)
@dvf
dvf / blockchain.py
Last active May 22, 2020 14:11
Step 11: Implementing Consensus Algorithm
View blockchain.py
...
import requests
class Blockchain(object)
...
def valid_chain(self, chain):
"""
Determine if a given blockchain is valid
@dvf
dvf / blockchain.py
Last active March 31, 2021 18:16
Step 10: Registering Nodes
View blockchain.py
...
from urllib.parse import urlparse
...
class Blockchain(object):
def __init__(self):
...
self.nodes = set()
...
@dvf
dvf / blockchain.py
Created September 23, 2017 20:31
Step 9: Consensus (Retrieve Chain)
View blockchain.py
@app.route('/chain', methods=['GET'])
def full_chain():
response = {
'chain': blockchain.chain,
'length': len(blockchain.chain),
}
return jsonify(response), 200