Skip to content

Instantly share code, notes, and snippets.

View yymao's full-sized avatar

Yao-Yuan Mao yymao

View GitHub Profile
@yymao
yymao / hlist2parquet.py
Created June 3, 2022 21:54
Convert hlist to parquet format
#/usr/bin/env python
import sys
import pyarrow as pa
import pyarrow.parquet as pq
from helpers.io_utils import hlist2pandas
import tqdm
def main(input_filename):
reader = hlist2pandas(input_filename, sanitize_column_names=True, chunksize=1000000)
@yymao
yymao / environment.yml
Last active February 12, 2024 16:16
My Python environment
# environment.yml
# Author: Yao-Yuan Mao @yymao
# Usage:
# wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh
# sh Miniforge3-Linux-x86_64.sh
# wget https://gist.githubusercontent.com/yymao/a1fcd607925996d8786a1d963fb01deb/raw/environment.yml
# mamba env create -f environment.yml
name: mypy
channels:
@yymao
yymao / start-kernel-cli.py
Created December 3, 2018 16:25
start a bash that has the same environment as a jupyter kernel
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
import subprocess
import json
import re
def abort(message, errorstatus=1):
@yymao
yymao / hyperlink-year-only-natbib-patch.tex
Last active January 4, 2024 21:19
hyperlink-year-only-natbib-patch
class Name(object):
"""
For better name comparison
"""
def __init__(self, name, exact=False):
self.name = name
if ',' in name:
name = '{0[1]} {0[0]}'.format(name.split(','))
self.names = tuple((n.lower() for n in name.replace('-', ' ').replace('.', '. ').split() if n != '.'))
assert self.names, '*name* must not be empty'
@yymao
yymao / aastex61.cls
Last active September 5, 2017 21:57
AASTeX 6.1 with the page break after abstract removed. Copyright 2016 American Astronomical Society
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% AASTeX61.cls %%
%% October 5, 2016 %%
%% December 28, 2016 (bug fix on .bib file) %%
%% Copyright 2016 American Astronomical Society %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\currversion{6.1}
#!/usr/bin/env python
import os
from shutil import copyfileobj
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
SLAC_KNOWN_HOSTS_URL = 'ftp://ftp.slac.stanford.edu/admin/known_hosts'
KNOWN_HOSTS_PATH = os.path.join(os.getenv('HOME'), '.ssh', 'known_hosts')
#!/usr/bin/env python
from __future__ import print_function
import re
import argparse
def _find_ending_brace(s, open_brace=1):
escaping = False
output = ''
remain = ''
@yymao
yymao / nbserver.py
Last active April 11, 2023 22:26
Start a Jupyter server on a remote server and tunnel to localhost
#!/usr/bin/env python
from __future__ import print_function
import subprocess
import argparse
from contextlib import closing
import socket
import random
__author__ = 'Yao-Yuan Mao'
@yymao
yymao / run-ctrees.py
Last active August 29, 2015 14:15
A Python script to run Peter Behroozi's Consistent Trees (replacing do_merger_tree.pl).
#!/usr/bin/env python
import os
import time
from argparse import ArgumentParser
#user settings
_perl_exe = 'perl'
_default_ctrees_dir = os.getenv('HOME') + '/software/consistent-trees'