Skip to content

Instantly share code, notes, and snippets.

View yuxincs's full-sized avatar
💡
Ideas survive in your memory, implementations do not.

Yuxin Wang yuxincs

💡
Ideas survive in your memory, implementations do not.
  • Uber
  • New York City
  • 07:34 (UTC -05:00)
View GitHub Profile
@yuxincs
yuxincs / pdf_to_images.py
Last active November 5, 2025 03:06
PDF to Images
def _pdf_to_images_high_quality(pdf_path, dpi=200):
images = []
with fitz.open(pdf_path) as pdf_document:
zoom = dpi / 72.0
matrix = fitz.Matrix(zoom, zoom)
for page_num in range(pdf_document.page_count):
page = pdf_document[page_num]
@yuxincs
yuxincs / mcmanager.py
Last active August 31, 2021 13:09
Minecraft server manager that automatically shuts down / restarts server for inactivity.
import asyncio
import argparse
import logging
import json
from copy import copy
from typing import Optional, Iterable
logger = logging.getLogger(__name__)
# optional setup for optimizations
@yuxincs
yuxincs / arxiv_cleaner.py
Last active April 28, 2019 19:33
ArXiv Cleaner
import argparse
import os
import re
import logging
import shutil
logging.basicConfig(format='%(levelname)s: %(message)s')
_comment = re.compile(r'\\begin\{comment\}[\s\S]*\\end{comment}|(?<!\\)%.*\n')
_empty_line = re.compile(r'\n\s*\n')
@yuxincs
yuxincs / json2sql.py
Created January 13, 2019 04:48
Convert json to SQL insert statements.
import json
import os
def json2sql(json_path, sql_path, table_name, encoding='utf-8', is_multi_line=False):
# read the data
data = []
with open(json_path, 'r', encoding=encoding) as f:
if is_multi_line:
for line in f:
@yuxincs
yuxincs / type3_font_hack.py
Created August 22, 2018 14:54
Get rid of type 3 fonts from matplotlib.
import matplotlib.pyplot as plt
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
#!/usr/bin/env bash
# Exit on error
set -e
# Ensure script is running as root
if [ "$EUID" -ne 0 ]
then echo "WARN: Please run as root (sudo)"
exit 1
fi
@yuxincs
yuxincs / portable_get_mac_addresses.c
Last active June 5, 2018 17:39 — forked from nuald/listmacaddrs.c
Getting MAC addresses
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <ifaddrs.h>
// works on Linux and macOS
#ifdef AF_LINK
#include <net/if_dl.h>
unsigned char *get_ptr(struct ifaddrs *ifaptr)
{
# Generate your identity key on openwrt
dropbearkey -t rsa -f ~/.ssh/id_rsa
# Convert public key from dropbear binary to openssh text
# Copy and paste output from below to bitbucket account ssh keys
dropbearkey -y -f ~/.ssh/id_rsa | head -n 2 | tail -1
# Change git ssh command
echo "#!/bin/sh" > ~/.gitssh.sh
echo "dbclient -y -i ~/.ssh/id_rsa \$\*" >> ~/.gitssh.sh