Skip to content

Instantly share code, notes, and snippets.

@mountain
mountain / pdfc.py
Created November 20, 2025 02:39
High quality converter to compress pdf
import fitz # PyMuPDF
import cv2
import numpy as np
import os
from tqdm import tqdm
class HighQualityMRCConverter:
def __init__(self, input_path, output_path, quality=60, downsample=2, dpi=300):
"""
@mountain
mountain / chatbot.py
Last active February 13, 2023 06:08
GPT3 Chatbot can play word game in less than 100 python lines
"""
This is a demo script to debug prompts
Example
艾达你好我是艾达竭诚为您服务有什么可以帮到你的吗
麦克我们可以一起玩个游戏吗
艾达当然可以你有什么喜欢的游戏
麦克猜谜语
艾达好的那我们就开始吧第一个谜语是:“我有四个脚但不能走路我会在水里游来游去你知道我是什么吗?”
@mountain
mountain / tkz-euclid-cheatsheet.en.md
Created October 13, 2021 16:44 — forked from kpym/tkz-euclid-cheatsheet.en.md
cheatsheet : tkz-euclid (latex library based on tikz)

Gist

Package

\usepackage{tkz-euclide} % checked for version 3.02c

Point definitions

import cv2
import numpy as np
# constructing an image with a frame in the center
img = np.zeros([255, 255], dtype=np.int)
img[64:192, 64] = np.ones([128], dtype=np.int) * 255
img[64:192, 192] = np.ones([128], dtype=np.int) * 255
img[64, 64:192] = np.ones([128], dtype=np.int) * 255
img[192, 64:192] = np.ones([128], dtype=np.int) * 255
DIRECTION=$1
SOURCE=$2
if test -f $HOME/.xiaoyi ; then
. $HOME/.xiaoyi
else
echo "Please input ip of your node: "
read NODEIP
echo "NODEIP=$NODEIP" > $HOME/.xiaoyi
fi
@mountain
mountain / search_crossword_chinese_poetries.py
Last active February 17, 2020 03:09
search crossword for Chinese poetries
# -*- coding: utf-8 -*-
'''
This simple program is used to search for crossword sentences in selected Chinese poetries
The selected Chinese poetries here is stored in a text file - tang_poetry_5char.txt.
You can change to your version of candidates
You should install networkx by pip
# -*- coding: utf-8 -*-
import numpy as np
import sys
import keras
from keras.layers import Input, Dense
from keras.models import Model

Keybase proof

I hereby claim:

  • I am mountain on github.
  • I am mingliyuan (https://keybase.io/mingliyuan) on keybase.
  • I have a public key whose fingerprint is ED86 CD82 A682 45D7 5CC5 2C3E 6EFF 88CB 304F 50A2

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am mountain on github.
  • I am mingliyuan (https://keybase.io/mingliyuan) on keybase.
  • I have a public key whose fingerprint is ED86 CD82 A682 45D7 5CC5 2C3E 6EFF 88CB 304F 50A2

To claim this, I am signing this object:

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs