Skip to content

Instantly share code, notes, and snippets.

View SeanSyue's full-sized avatar
Nature Lover

Yuchen Xue SeanSyue

Nature Lover
View GitHub Profile
SeanSyue /
Created December 9, 2023 09:55
A generator function that flattens a nested `Mapping` object.
from typing import Any, TypeAlias, TypeVar, Union
from import MutableSequence, Iterable, Mapping, Iterator
import copy
MS = TypeVar("MS", bound=MutableSequence)
Nested: TypeAlias = Mapping[Any, Union[Iterable, "Nested"]]
def nested_mapping_serializer(
SeanSyue /
Created December 8, 2023 21:56
An extension of the SimpleNamespace type, where the members of whose IndexableNamespace instance can also be accessed and modified by indexing.
from types import SimpleNamespace
class IndexableNamespace(SimpleNamespace):
An extension of the SimpleNamespace type.
The members of an IndexableNamespace instance can also be
accessed and modified by indexing.
SeanSyue / Julia-learning.ipynb
Created November 27, 2023 09:06
Get started with Julia using Jupyter Notebook
View Julia-learning.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
SeanSyue /
Last active February 19, 2023 20:28
Python list sort alphanumerically.
Since os.listdir returns filenames in an arbitary order,
this function is very handy for generating well-ordered filenames list.
import re
def sorted_alphanumeric(data):
convert = lambda text: int(text) if text.isdigit() else text.lower()
alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)]
return sorted(data, key=alphanum_key)
SeanSyue /
Last active November 24, 2020 02:37
Download all files from [Megaface Challenge](
#! /bin/bash
# Specify the destination of donwloaded files
# You may get the credential by following the instructions in
# ``
# Follow the below format for the credential file:
# ```
# machine
# login <your-login-name>
SeanSyue / Dockerfile
Created June 17, 2020 15:49
Yumdownloader Dockerfile
View Dockerfile
# docker image to download yum rpms via dependencies
# these are the centos tags you can use below if you want to use a different version of centos
#latest, centos7, 7 (docker/Dockerfile)
#centos6, 6 (docker/Dockerfile)
#centos5, 5 (docker/Dockerfile)
#centos7.1.1503, 7.1.1503 (docker/Dockerfile)
#centos7.0.1406, 7.0.1406 (docker/Dockerfile)
#centos6.7, 6.7 (docker/Dockerfile)
#centos6.6, 6.6 (docker/Dockerfile)
#centos5.11, 5.11 (docker/Dockerfile)
###### Get docker machine ip ######
# able to resolve docker ip for both Docker Toolbox and Docker Desktop
if [[ -z "${DOCKER_HOST_IP-}" ]]; then
docker_host_ip=$(docker run --rm --net host alpine ip address show eth0 | awk '$1=="inet" {print $2}' | cut -f1 -d'/')
# Work around Docker for Mac 1.12.0-rc2-beta16 (build: 9493)
if [[ $docker_host_ip = '' ]]; then
docker_host_ip=$(/sbin/ifconfig | grep -v '' | awk '$1=="inet" {print $2}' | cut -f1 -d'/' | head -n 1)
export DOCKER_HOST_IP=$docker_host_ip
SeanSyue /
Created July 12, 2019 04:07
Remove Android Studio on MacOS
# with small modification
rm -Rf /Applications/Android\
rm -Rf ~/Library/Preferences/AndroidStudio*
rm -Rf ~/Library/Preferences/*
rm -Rf ~/Library/Preferences/*
rm -Rf ~/Library/Application\ Support/AndroidStudio*
rm -Rf ~/Library/Android/*
rm -Rf ~/Library/Logs/AndroidStudio*
rm -Rf ~/Library/Caches/AndroidStudio*
SeanSyue /
Created July 12, 2019 04:07
Remove python 3.6 on MacOS
sudo rm '/usr/local/bin/2to3'
sudo rm '/usr/local/bin/2to3-3.6'
sudo rm '/usr/local/bin/idle3'
sudo rm '/usr/local/bin/idle3.6'
sudo rm '/usr/local/bin/pydoc3'
sudo rm '/usr/local/bin/pydoc3.6'
sudo rm '/usr/local/bin/python3'
sudo rm '/usr/local/bin/python3-32'
sudo rm '/usr/local/bin/python3-config'
sudo rm '/usr/local/bin/python3.6'
SeanSyue /
Created August 24, 2018 04:10
[TEST] Download images from "meitulu" using `selenium`
import urllib.request
import requests
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from import By
from import WebDriverWait
from import expected_conditions as EC
from bs4 import BeautifulSoup
import time