Skip to content

Instantly share code, notes, and snippets.

@felixmon
felixmon / pdf_to_image.py
Created October 18, 2023 14:12
Use PDFTK and Convert to convert specified pages from a pdf file into images
import os
import subprocess
def extract_pages_from_pdf(source_file, page_range, output_file):
try:
subprocess.run(['pdftk', source_file, 'cat', page_range, 'output', output_file], check=True, capture_output=True, text=True)
except subprocess.CalledProcessError as e:
print(f"Error during 'pdftk' execution:\n{e.stderr}")
exit(1)
@felixmon
felixmon / list.py
Last active May 26, 2023 16:02
找出证券业协会证券公司排名中特定证券公司的所有排名
import pandas as pd
import numpy as np
# Specify the path to your excel file
file_path = 'list.xlsx'
# Read the Excel file
df = pd.read_excel(file_path)
# Drop rows with missing values
@felixmon
felixmon / vertical-chinese
Last active March 25, 2023 15:22
Display Chinese characters vertically in the right way in Matplotlib
# use index values, which are all Chinese characteres, as x labels,
# but not enought space to display, so we need to display the characters vertically,
# not jsut rotate x lables
# but to display the characters one at each line.
# reference & courtesy: https://blog.csdn.net/ai_clay/article/details/126038824
df_new=df_filtered.index # get the index values from the original df
df_new= df_new.map(lambda x: '\n'.join(x)) # one character each line
@felixmon
felixmon / comparinson_numbers.md
Created October 20, 2020 07:38
Comparison of two numbers

比较两个数字的大小,包含正负数的情形

A, B

A, B 为实数A

A 比 B 大了多少(百分比):

[(A/B)-1]/[B/ABS(B)]

@felixmon
felixmon / rsync.md
Last active October 17, 2020 02:16
Linux (mv or cp) specific files from a text list of files
rsync -a /source/directory --files-from=/full/path/to/listfile /destination/directory

example:

rsync -a ./source --files-from=./list.txt ./new
@felixmon
felixmon / install_termux.md
Last active September 23, 2020 01:45
Install Termux

Startup Scripts

Just like Linux

nano ~/.bashrc
## write some scripts

Matplotlib on Termux

In a nut shell, you need to install some dependencies manually before actually install matplotlib.

@felixmon
felixmon / SimpleHTTPServerWithUpload.py
Created September 17, 2020 15:44 — forked from touilleMan/SimpleHTTPServerWithUpload.py
Simple Python Http Server with Upload - Python3 version
#!/usr/bin/env python3
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
see: https://gist.github.com/UniIsland/3346170
"""
@felixmon
felixmon / latex-win32.md
Last active August 31, 2020 01:51
Install LaTeX on Windows

Install LaTex on Windows

Softwares to download

  1. MikTex
  2. Texmaker

Settings

Texmaker -> Options/Configure Texmaker/Commands/LaTeX

@felixmon
felixmon / python-gists.md
Last active August 28, 2020 06:05
Python Gists

System

Check bit version

python -c "import ctypes; print(32 if ctypes.sizeof(ctypes.c_voidp)==4 else 64, 'bit CPU')"

Functions

List dict

fruits = ['lemon', 'pear', 'watermelon', 'tomato']
@felixmon
felixmon / jupyer_installation_windows.md
Last active September 15, 2020 08:03
Install Jupyter on Windows (errors)

Install Jupyter on Windows 10

1. Requirements

  1. Windows 10 64 bit
  2. Python 3.x 64 bit or errors will occour when installing pywinpty
  3. MS Visual Studio Build Tools (for c++ compiler)

2. Steps

  1. Set Python and Python/Scripts paths to system path (reboot required).
  2. pip install pywinpty