Skip to content

Instantly share code, notes, and snippets.

@RabbitLee
RabbitLee / kmeans_image_compression.py
Last active November 11, 2020 00:54
K-means clustering for image compression
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import cv2
import numpy as np
@RabbitLee
RabbitLee / 4.cpp
Created September 27, 2020 14:05
Problem 4 in LeetCode Weekly Contest 208 (TLE version)
class Solution {
public:
vector<bool> ap;
int maxReq = 0;
int maximumRequests(int n, vector<vector<int>>& requests) {
int res = 0;
for (auto it = requests.begin(); it != requests.end();) {
if ((*it)[0] == (*it)[1]) {
it = requests.erase(it);
res++;
@RabbitLee
RabbitLee / spider.py
Last active July 2, 2020 23:43
python web spider with coroutine and multiprocessing (using asyncio, aiohttp and aiofiles to speedup the network requesting and file I/O process)
# coroutine
import asyncio
import aiohttp
import aiofile
# set up coroutine
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
# get tasks
tasks = []
for index, img_url in enumerate(img_url_list):
@RabbitLee
RabbitLee / gist:d35c277d2ac2019f4c0fa50788c0262f
Created April 26, 2019 11:38
install package in Jupiter notebook
# Install a conda package in the current Jupyter kernel
import sys
!conda install --yes --prefix {sys.prefix} numpy
# url: https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/#How-to-use-Conda-from-the-Jupyter-Notebook