Skip to content

Instantly share code, notes, and snippets.

View yymao's full-sized avatar

Yao-Yuan Mao yymao

View GitHub Profile
@yymao
yymao / TracyWidom.py
Last active January 13, 2021 07:18
Moved to https://github.com/yymao/TracyWidom - Provide the Tracy-Widom distribution functions for beta = 1, 2, or 4 in Python. Dependencies: NumPy and SciPy.
"""
This project has been moved to https://github.com/yymao/TracyWidom
You can install this package by `pip install TracyWidom`
Please open issues at https://github.com/yymao/TracyWidom/issues
TracyWidom.py
A Python module to generate Tracy-Widom distribution functions
Author: Yao-Yuan Mao (yymao)
The MIT License (MIT)
@yymao
yymao / SimulationCheatsheet.py
Last active August 29, 2015 14:05
A python script to generate a "simulation cheat sheet" which shows the relation between number of particles, box sizes and mass resolutions.
# Simulation Cheatsheet by Yao-Yuan Mao
import math
import numpy as np
import matplotlib.pyplot as plt
rho_crit = 2.7745945707e+11
log10_rhom_30 = math.log10(rho_crit*0.30)
log10_rhom_25 = math.log10(rho_crit*0.25)
log2_10 = math.log(10, 2)
@yymao
yymao / astro-portal.php
Last active November 4, 2019 12:22
astro portal: search for arXiv, DOI, ADS bibcode, and first author + year, without typing syntax keywords!
<?php
if(isset($_GET['q'])){
$url_base = 'https://ui.adsabs.harvard.edu/#search/q=';
#doi
$re = '/\b10\.\d{4,}(?:\.\d+)*\/(?:(?![\'"&<>])\S)+/';
if (preg_match($re, $_GET['q'], $matches)){
if (isset($_GET['rd'])){
$url = $url_base . 'doi%3A' . urlencode($matches[0]);
}
@yymao
yymao / adstex.md
Last active November 13, 2019 20:23
This project has been moved to https://github.com/yymao/adstex

This project has been moved to https://github.com/yymao/adstex

You can now install adstex by

pip install adstex

and then run it with

adstex file1.tex [file2.tex [...]] -o references.bib
@yymao
yymao / scatter.php
Last active August 4, 2017 17:52
Plots of Everything vs. Everything: A web interface which shows scatter plots with any two columns in a Google Spreadsheet with Google Charts API.
<?php
if (!isset($_GET['url']) or !preg_match('/(?:\/spreadsheets\/d\/|[?&]key=)([\w-]+)/', $_GET['url'], $matches)) {
?>
<!DOCTYPE html>
<html>
<head>
<title>Plots of Everything vs. Everything</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/purecss@1.0.0/build/pure-min.css">
@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'
@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'
#!/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 = ''
#!/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')
@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}