Skip to content

Instantly share code, notes, and snippets.

View deliro's full-sized avatar
🦀
Rust in action

deliro

🦀
Rust in action
  • Tochka Bank
  • Russia
View GitHub Profile
class Semaphore {
constructor(max = 1) {
if (max < 1) { max = 1; }
this.max = max;
this.count = 0;
this.queue = [];
}
acquire() {
let promise;
if (this.count < this.max) {
@deliro
deliro / wiki_parser.go
Created March 5, 2021 11:44
Walk through Wikipedia link graph (close to BFS) and find path from the main page to the page contain search term
package main
import (
"crypto/tls"
"fmt"
"io/ioutil"
"log"
"net/http"
"regexp"
"strings"
@deliro
deliro / parse_wiki.py
Last active November 21, 2020 16:33
async parsing of wikipedia with process pool
import asyncio
from concurrent.futures import ProcessPoolExecutor
import aiohttp
from loguru import logger as loguru
from lxml.html import fromstring
pool = ProcessPoolExecutor()
parser_sem = asyncio.Semaphore(pool._max_workers)
import redis
from time import sleep
from random import randint
from redq import RedisDeque
r = redis.StrictRedis()
q = RedisDeque(r, "l")
def consumer():
while True:
import pickle as _pickle
import json
from functools import partial
class pickle:
dumps = partial(_pickle.dumps, protocol=_pickle.HIGHEST_PROTOCOL)
loads = _pickle.loads
@deliro
deliro / Dockerfile
Created October 10, 2018 12:51
node-to-python multi-stage Vue project build
FROM node:9-alpine AS admin-build
WORKDIR /app
COPY manager .
RUN npm install && npm run build
FROM python:3.7-alpine3.7
EXPOSE 5000
WORKDIR /app
@deliro
deliro / Dockerfile
Last active April 17, 2020 12:33
python alpine lxml image example
FROM python:3.7-alpine
EXPOSE 8000
WORKDIR /app
COPY . .
RUN apk add --update --no-cache --virtual .build-deps \
g++ \
python-dev \
libxml2 \
libxml2-dev && \
@deliro
deliro / find_ip.py
Created July 6, 2018 13:15
Find a subnet that contains ip
from heapq import heappush
from functools import total_ordering, reduce
def ip(s):
return reduce(lambda r, c: c + (r << 8), map(int, s.split(".")), 0)
@total_ordering
class Subnet:
def __init__(self, start, end):
self.start = start
#!/usr/bin/env python3
import argparse
import csv
import os
import re
import subprocess
import sys
from collections import OrderedDict, namedtuple
from datetime import datetime, timedelta
@deliro
deliro / bloom.py
Created January 18, 2017 11:24
Bloom filter on pure python
from math import log
from array import array
from struct import unpack
from hashlib import sha512
class Bits:
__slots__ = ('data',)
def __init__(self, cap):