Skip to content

Instantly share code, notes, and snippets.

View 2minchul's full-sized avatar
😀

Colin (MinChul Lee) 2minchul

😀
View GitHub Profile
@2minchul
2minchul / pub.py
Created October 30, 2019 14:48
ZeroMQ pubsub with pyzmq asyncio
import asyncio
import datetime
import zmq
import zmq.asyncio
context = zmq.asyncio.Context()
async def run_server(host, port):
@2minchul
2minchul / proxy.py
Created October 29, 2019 07:48
Python HTTPS proxy server with asyncio streams
import asyncio
import re
from asyncio.streams import StreamReader, StreamWriter
from contextlib import closing
from typing import Tuple, Optional
import async_timeout
StreamPair = Tuple[StreamReader, StreamWriter]
import cv2 # pip install opencv-python
def find_contained_image(image_path, target_path, min_accuracy=0.8):
img = cv2.imread(image_path, 0)
template = cv2.imread(target_path, 0)
w, h = template.shape[::-1]
res = cv2.matchTemplate(img, template, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
top_left = max_loc
# https://www.acmicpc.net/problem/16283
def solution(a, b, n, w):
no_result = '-1'
if a == b:
if a + b == w and n == 2:
return '1 1'
else:
return no_result
@2minchul
2minchul / make_models.py
Created June 4, 2019 08:28
sqlacodegen을 python으로 실행하여 models.py 만들기
from sqlalchemy.engine import create_engine
from sqlalchemy.schema import MetaData
from sqlacodegen.codegen import CodeGenerator
url = 'mysql+pymysql://user:password@localhost/dbname'
engine = create_engine(url)
metadata = MetaData(engine)
metadata.reflect(engine)
@2minchul
2minchul / firewallcmd-drop-client.sh
Last active May 27, 2019 02:34 — forked from lesstif/firewallcmd-drop-client.sh
firewall 에서 ip를 차단하기 위한 script
#!/bin/bash
ZONE="service"
function usage {
echo "USAGE: $0 param"
echo ""
echo "$0 -i block-ip1,block-ip2"
echo "$0 -f block-ip-file"
exit 1
}
@2minchul
2minchul / main.go
Created April 16, 2019 05:55
golang http client using specific network adapter
package main
import (
"context"
"fmt"
"io/ioutil"
"net"
"net/http"
)
# coding=utf-8
import re
import requests
from bs4 import BeautifulSoup, Tag
weather_pattern = re.compile(
r'''(?P<name>[^<>]+?) # name group
\s*?:\s*? # split by ':'
(?P<value> # value group
def decrypt(row, size):
mask = 1 << (size - 1)
while mask:
yield '#' if (row & mask) else ' '
mask = mask >> 1
def solution(n, arr1, arr2):
answer = []
for row in (a|b for a, b in zip(arr1, arr2)):
answer.append(''.join(decrypt(row, n)))
from collections import Counter, defaultdict
def solution(genres, plays):
song_limit = 2
answer = []
songs = defaultdict(dict)
_genre_counter_dict = defaultdict(int)