This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import datetime | |
import zmq | |
import zmq.asyncio | |
context = zmq.asyncio.Context() | |
async def run_server(host, port): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"io/ioutil" | |
"net" | |
"net/http" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter, defaultdict | |
def solution(genres, plays): | |
song_limit = 2 | |
answer = [] | |
songs = defaultdict(dict) | |
_genre_counter_dict = defaultdict(int) |