Skip to content

Instantly share code, notes, and snippets.

@jeanmonet
jeanmonet / curve_example.py
Created October 22, 2020 18:37 — forked from nlitsme/curve_example.py
example of bitcoin curve calculations in python
"""
Example of how calculations on the secp256k1 curve work.
secp256k1 is the name of the elliptic curve used by bitcoin
see http://bitcoin.stackexchange.com/questions/25382
"""
p = 2**256 - 2**32 - 977
@jeanmonet
jeanmonet / modsqrt.py
Created October 17, 2020 22:30 — forked from nakov/modsqrt.py
mod_sqrt - Python 3 implementation
def modular_sqrt(a, p):
def legendre_symbol(a, p):
""" Compute the Legendre symbol a|p using
Euler's criterion. p is a prime, a is
relatively prime to p (if p divides
a, then a|p = 0)
Returns 1 if a has a square root modulo
p, -1 otherwise.
@jeanmonet
jeanmonet / sync2async_v01.py
Last active September 26, 2020 21:37
Convenience function to call (multiple) asynchronous functions from synchronous code (loop runs in separate thread and returns results to the main thread)
"""Call async functions from sync code.
This module provides the convenience sync2async function.
It runs a bunch of given coroutines (async functions) from sync code in one separate thread,
and returns results to the main thread.
sync2async function:
Argument:
iterable (such as list) of coroutines
@jeanmonet
jeanmonet / asyncio_plus_greenlet.py
Created September 26, 2020 19:20 — forked from zzzeek/asyncio_plus_greenlet.py
An asyncio program that runs rows into a Postgresql database, using blocking style code to actually run the database commands
"""This program is exactly the same as that of
https://gist.github.com/zzzeek/33943060f7a08cf9e82bf8df1f0f75de ,
with the exception that the add_and_select_data function is written in
synchronous style.
UPDATED!! now includes refinements by @snaury and @Caselit . SIMPLER
AND FASTER!!
@jeanmonet
jeanmonet / hosts
Created May 9, 2020 19:45 — forked from consti/hosts
/etc/hosts to block shock sites etc.
# This hosts file is brought to you by Dan Pollock and can be found at
# http://someonewhocares.org/hosts/
# You are free to copy and distribute this file for non-commercial uses,
# as long the original URL and attribution is included.
#<localhost>
127.0.0.1 localhost
127.0.0.1 localhost.localdomain
255.255.255.255 broadcasthost
::1 localhost
@jeanmonet
jeanmonet / test_zmq.py
Created April 26, 2020 20:10 — forked from SlamJam/test_zmq.py
ZMQ REQ-REP poll example
import sys
import time
import zmq
context = zmq.Context()
def run_service(addr):
socket = context.socket(zmq.REP)
socket.bind(addr)
@jeanmonet
jeanmonet / router.py
Created April 26, 2020 18:48 — forked from anopheles/router.py
Router Dealer example with bidirectional communication
# encoding: utf-8
import zmq
from collections import defaultdict
context = zmq.Context()
client = context.socket(zmq.ROUTER)
client.bind("tcp://*:5556")
poll = zmq.Poller()
@jeanmonet
jeanmonet / router.py
Created April 26, 2020 18:48 — forked from anopheles/router.py
Router Dealer example with bidirectional communication
# encoding: utf-8
import zmq
from collections import defaultdict
context = zmq.Context()
client = context.socket(zmq.ROUTER)
client.bind("tcp://*:5556")
poll = zmq.Poller()
@jeanmonet
jeanmonet / europython-2018.md
Created April 20, 2020 21:58 — forked from rupert/europython-2018.md
EuroPython 2018
@jeanmonet
jeanmonet / aproducer.py
Created April 19, 2020 15:45 — forked from dabeaz/aproducer.py
"Build Your Own Async" Workshop - PyCon India - October 14, 2019 - https://www.youtube.com/watch?v=Y4Gt3Xjd7G8
# aproducer.py
#
# Async Producer-consumer problem.
# Challenge: How to implement the same functionality, but no threads.
import time
from collections import deque
import heapq
class Scheduler: