Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Daniel van Flymen dvf

🏠
Working from home
Block or report user

Report or block dvf

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dvf
dvf / asyncio.md
Last active Jul 12, 2019
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
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 May 8, 2019
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 Feb 22, 2018
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 Feb 22, 2018
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 Sep 24, 2017
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 Sep 24, 2017
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 Sep 23, 2017
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
@dvf
dvf / blockchain.py
Last active Jun 29, 2019
Step 8: The Mining Endpoint
View blockchain.py
import hashlib
import json
from time import time
from uuid import uuid4
from flask import Flask, jsonify, request
...
@dvf
dvf / blockchain.py
Created Sep 23, 2017
Step 2.1: Creating a Transaction
View blockchain.py
class Blockchain(object):
...
def new_transaction(self, sender, recipient, amount):
"""
Creates a new transaction to go into the next mined Block
:param sender: <str> Address of the Sender
:param recipient: <str> Address of the Recipient
:param amount: <int> Amount
You can’t perform that action at this time.