Skip to content

Instantly share code, notes, and snippets.

View ipan's full-sized avatar

Ivan Pan ipan

  • Thermo Fisher Scientific, Inc.
  • San Francisco, CA
View GitHub Profile
@ipan
ipan / argparse-usage.py
Created January 14, 2018 05:52
quick examples of argparse usage
import argparse
parser = argparse.ArgumentParser(description="script description")
parser.add_argument('input_names', nargs="*", help="input name(s)")
parser.add_argument('-t', '--target', required=True)
parser.add_argument('-of', '--option-flag', action='store_true', default=False, help="description for option flag")
parser.add_argument('--number', type=int, default=0, help="description for int num")
args = parser.parse_args()
@ipan
ipan / subprocess-examples.py
Created January 14, 2018 05:58
subprocess examples
import subprocess
import shlex
cmd = 'ls -lhrt python'
subprocess.call(shlex.split(cmd))
try:
subprocess.check_output(['ls'])
except subprocess.CalledProcessError as e:
@ipan
ipan / ssh-keygen.sh
Last active January 14, 2018 23:31
generate rsa keys #ssh
ssh-keygen -t rsa -C "your.email@example.com" -b 4096
"""
example dockerfile for longprocess:
https://github.com/ipan/dockerfiles/tree/master/longprocess
"""
import docker
client = docker.from_env()
lp = client.containers.run("longprocess", "/src/run.sh 5", detach=True)
@ipan
ipan / rand-string.py
Created January 15, 2018 02:00
generate random string
def rand_string(length):
""" Generates a random string of numbers, lower- and uppercase chars. """
rand_str = ''.join(random.choice(string.ascii_lowercase
+ string.ascii_uppercase
+ string.digits)
for i in range(length))
return rand_str
print(rand_string(10))
@ipan
ipan / sudo.vim
Last active January 15, 2018 20:58
save vim with sudo permission #vim
:w !sudo tee %
@ipan
ipan / byobu.md
Created January 16, 2018 04:42
byobu: split screen #screen #byobu

Ctrl-A | (horizontal) or Ctrl-A % (vertical) to split, arrow key to navigate

  • Split screen horizontally:
    • Shift+F2 or
    • Ctrl+A then |
  • Split screen vertically:
    • Ctrl+F2 or
    • Ctrl+A then %
  • Switch focus:
  • Shift+↑ ↓ ← → or
@ipan
ipan / diff-jq.md
Created January 16, 2018 04:47
compare two JSONs with jq #json #jq
@ipan
ipan / rsync.md
Created January 16, 2018 05:06
rsync copy only *.sh in subdirectory #rsync
@ipan
ipan / xcode.md
Created January 16, 2018 05:10
Xcode command line tools #xcode

Accepting licenses

sudo xcodebuild -license accept