Skip to content

Instantly share code, notes, and snippets.

View tkanmae's full-sized avatar

Takeshi Kanmae tkanmae

View GitHub Profile
@tkanmae
tkanmae / git-latexdiff.sh
Created August 5, 2011 21:54
A git-diftool utility for a TeX file using `latexdiff`
#!/usr/bin/env bash
# ================================================================================
# A git-diftool utility for a TeX file using `latexdiff`.
#
#
# Usage
# -----
# git latexdiff [<commit>]
# git latexdiff --cached [<commit>]
#
@tkanmae
tkanmae / usercustomize.py
Created August 24, 2011 17:26
My usercustomize.py on Mac OS X
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""My usercustomize.py on Mac OS X"""
import os
import site
import sys
SUFFIX = 'lib/python{0}/site-packages'.format(sys.version[:3])
site.USER_BASE = os.path.expanduser(os.path.join('~', '.local'))
@tkanmae
tkanmae / ipython_wrapper.sh
Last active December 18, 2015 00:28
Call ipython with a per-project profile. It assumes that .ipython directory is in the top level directory managed by git.
#!/usr/bin/env bash
# Call ipython with a per-project profile. It assumes that .ipython directory
# is in the top level directory of a project managed by git.
function ipython() {
local project_root_dir
# If the user specifies `IPYTHONDIR` either by giving --ipython-dir
# option or by an environmental variable IPYTHONDIR, then the specified
# directory should have precedence over per-project `IPYTHONDIR`.
@tkanmae
tkanmae / scan_fortran_unformatted.py
Last active December 18, 2015 02:28
Scan records in a Fortran unformatted file.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division
import itertools
import struct
def scan_fortran_unformatted(fname, marker_size=4):
"""Scan records of a Fortran unformatted file.
@tkanmae
tkanmae / init_data_analysis_project.sh
Last active December 18, 2015 03:39
Initialize a data analysis project.
#!/usr/bin/env bash
\unalias -a
# Print the usage and exit..
#
print_usage_and_exit() {
cat <<EOF
Usage: init_data_analysis_project [-h|--help] PROJECT_NAME
@tkanmae
tkanmae / smtable.py
Last active December 20, 2015 03:28
Display a table of rising and setting times of the Sun and Moon.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division
import argparse
import datetime
import calendar
import ephem
@tkanmae
tkanmae / custom.css
Last active December 22, 2015 12:19
Custom IPython Notebook style.
div#notebook-container {
width: 105ex;
}
div.cell {
margin-left: auto;
margin-right: auto;
}
div.text_cell_render {
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import functools
from lib import lxcat
txt_file = '20131029_Electron_Scattering_Swarm_Data_Dutton_1975.txt'
@tkanmae
tkanmae / extract_zipfile.py
Last active January 1, 2016 00:09
`ZipFile.extractall()` does not preserve file attributes. See http://stackoverflow.com/a/9813471
import os
import time
import zipfile
def extract_zipfile(filename, dest_dir):
"""Extract all files in a ZIP file while preserving date and time.
See http://stackoverflow.com/a/9813471.
"""
@tkanmae
tkanmae / 00-add_git_root_dir.py
Last active August 29, 2015 14:01
IPython startup scripts
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Add the top directory of a git-managed project to `sys.path`."""
import os
import shlex
import subprocess
import sys
cmd = 'git rev-parse --show-toplevel'