Skip to content

Instantly share code, notes, and snippets.

@miracle2k
miracle2k / web3py_aio.py
Created April 28, 2021 13:52
Using web3py with asyncio
"""
Inspired by this approach:
- https://twitter.com/zzzeek/status/1279069782533386247
- https://gist.github.com/zzzeek/2a8d94b03e46b8676a063a32f78140f1
- https://gist.github.com/zzzeek/33943060f7a08cf9e82bf8df1f0f75de, https://gist.github.com/zzzeek/4e89ce6226826e7a8df13e1b573ad354#file-asyncio_plus_greenlet-py-L28
Essentially we use greenlets to make the IO layer async and the top layer uses async/await, but everything in
between can be regular sync code.
@enixdark
enixdark / main.py
Created December 17, 2019 05:03 — forked from klikstermkd/main.py
Gracefully kill Python process
from time import sleep
import signal
import sys
def on_stop_handler(signum, frame):
print 'Exiting application...'
sys.exit(0)
## PREHEAD
----------
nonce (4 bytes)
|
| timestamp (8 bytes)
| |
| | padding (20 bytes) prevBlock (32 bytes) treeRoot(32 bytes) commitHash(32 bytes)
⚀⚀⚀⚀ ⚀⚀⚀⚀⚀⚀⚀⚀ ⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀ ⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀ ⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀ ⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀⚀
@asyd
asyd / models.py
Created May 14, 2018 16:21
Flask SQLAlchemy multiple column unique constraint
class ComponentCommit(db.Model):
__tablename__ = 'component_version'
__table_args__ = (
db.UniqueConstraint('component_id', 'commit_id', name='unique_component_commit'),
)
id = db.Column(db.Integer, primary_key=True)
component_id = db.Column(db.Integer, db.ForeignKey("component.id"))
commit_id = db.Column(db.String)
branch = db.Column(db.String)
dependencies = db.Column(db.Text)
@vanpelt
vanpelt / upsert.py
Created March 20, 2018 06:33
Flask SqlAlchemy MySQL ON DUPLICATE KEY UPDATE returning auto increment id UPSERT HOTNESS
from app import db
from sqlalchemy import func
from sqlalchemy.dialects.mysql import insert
def upsert(model, insert_dict):
"""model can be a db.Model or a table(), insert_dict should contain a primary or unique key."""
inserted = insert(model).values(**insert_dict)
upserted = inserted.on_duplicate_key_update(
id=func.LAST_INSERT_ID(model.id), **{k: inserted.inserted[k]
for k, v in insert_dict.items()})
@andreafspeziale
andreafspeziale / Operating Ropsten Ethereum testnet.md
Last active March 30, 2022 03:24
Operating Ropsten Ethereum testnet network with Geth and Mist on OSX

Operating Ropsten Ethereum testnet

from a newbie to newbies

Intro

I believe that a development environment is one of the access key in learning new technologies. I didn't find on the internet a simple and common path to make the Ropsten network, the Ethereum public testnet, work.

So I'm writing down a couple of command lines and links that can be useful to achieve it.

Resources and requirements

@ChristopherJohnston
ChristopherJohnston / block.py
Created December 21, 2017 01:07
Example Blockchain hash calculations using Python
from hashlib import sha256
import time
import struct
import binascii
import datetime
VERSION = 1
def hexify(value, type):
return binascii.hexlify(struct.Struct(type).pack(value))
@YihaoPeng
YihaoPeng / Stratum挖矿协议.md
Last active July 26, 2023 14:07
Stratum挖矿协议

Stratum挖矿协议: 该协议是由SlushPool制定的,请参阅其官方文档:https://slushpool.com/help/manual/stratum-protocol

以下所有报文均使用\n做为行结束符。


矿机订阅:

{"id": 1, "method": "mining.subscribe", "params": []}
@fotock
fotock / nginx.conf
Last active May 2, 2024 02:43 — forked from plentz/nginx.conf
Nginx SSL 安全配置最佳实践.
# 生成 dhparam.pem 文件, 在命令行执行任一方法:
# 方法1: 很慢
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
# 方法2: 较快
# 与方法1无明显区别. 2048位也足够用, 4096更强
openssl dhparam -dsaparam -out /etc/nginx/ssl/dhparam.pem 4096
@nilsmagnus
nilsmagnus / kafka_consumer.go
Created February 15, 2017 08:04
Example of go consuming from kafka, using the shopify/sarama library
package main
import (
"fmt"
"github.com/Shopify/sarama"
"os"
"os/signal"
"strings"
)