Skip to content

Instantly share code, notes, and snippets.

@lmyyao
lmyyao / zap.py
Created July 21, 2020 03:09
zeromq zap curse auth
import zmq
from zmq.utils import z85
server_public, server_secret = zmq.curve_keypair()
context = zmq.Context()
server = context.socket(zmq.PAIR)
server.set(zmq.CURVE_SECRETKEY, z85.decode(server_secret))
server.set(zmq.CURVE_PUBLICKEY, z85.decode(server_public))
server.set(zmq.CURVE_SERVER, True)
server.bind("tcp://127.0.0.1:5556")
@lmyyao
lmyyao / psi.py
Created July 9, 2020 07:50
private set intersection
'''
https://github.com/OpenMined/PyPSI
'''
import gmpy2
import secrets
import hashlib
from Crypto.PublicKey import RSA
class PSI(object):
def __init__(self, rsa_size=1024):
from Crypto import Random
from Crypto.Cipher import AES
from Crypto.Cipher import Salsa20
from Crypto.Cipher import ChaCha20
from Crypto.Cipher import ARC4
from Crypto.Cipher import PKCS1_OAEP
from Crypto.Util import Padding
from Crypto.PublicKey import RSA
import imaplib
import time
import email
import logging
import logging.config
logging_config = dict(
version=1,
formatters={'f': {
'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
}},
import logging
import logging.config
import os
logging_config = dict(
version=1,
disable_existing_loggers=False,
formatters={'f': {
'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
import logging
import logging.config
logging_config = dict(
version=1,
formatters={'f': {
'format': '%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
}},
handlers={'h': {
'class': 'logging.StreamHandler',
'formatter': 'f',
@lmyyao
lmyyao / watchdog.go
Last active March 20, 2020 11:20
golang file watchdog
package main
import (
"log"
"strings"
"github.com/fsnotify/fsnotify"
)
type Event fsnotify.Op
@lmyyao
lmyyao / binaryfile.py
Created March 2, 2020 11:49
python write c struct to file
from ctypes import *
import time
import datetime
class Record(Structure):
_fields_ = [
("time", c_double),
("count", c_double)
]
@lmyyao
lmyyao / server.py
Created September 7, 2018 05:16
A simple threadpool using python
import socket
import threading
import queue
HOST = '0.0.0.0'
PORT = 50000
class Worker(threading.Thread):
def __init__(self, queue, **kwargs):
@lmyyao
lmyyao / formidentify.py
Last active June 4, 2018 07:30
page form identify
# -*- coding: utf-8 -*-
from __future__ import print_function
import lxml.html
from collections import OrderedDict
import re
def after_first_check(func):