Skip to content

Instantly share code, notes, and snippets.

View stevekm's full-sized avatar

Stephen Kelly stevekm

View GitHub Profile
@stevekm
stevekm / date.md
Created January 3, 2017 03:37
return ISO compliant timestamp from file modification time datetime
>>> import os
>>> import datetime
>>> file = "my_file.txt"
>>> os.stat(file).st_ctime
1483323862.8774118
>>> os.path.getmtime(file)
1483323862.873167
>>> os.path.getmtime(os.path.getmtime(file))
KeyboardInterrupt
@stevekm
stevekm / stuff.md
Last active May 24, 2017 16:12
New MacBook setup essentials guide

Homebrew

# paste of some of the things I've installed

brew install python
brew install pip
brew install pyenv
brew install pip --upgrade
@stevekm
stevekm / sublime.txt
Last active November 18, 2017 00:10
My user settings for Sublime Text Editor. More settings here: http://docs.sublimetext.info/en/latest/reference/settings.html
{
"color_scheme": "Packages/Monokai Extended/Monokai Extended.tmTheme",
"draw_white_space": "all",
"font_size": 18,
"ignored_packages":
[
"Vintage"
],
"ignored_words":
[
@stevekm
stevekm / session.md
Last active November 30, 2016 18:28
R system session information code chunk for reports

The codes:

# system info
system("uname -srv", intern = TRUE)

# dir
system('pwd',intern=T)

# date time
@stevekm
stevekm / pyshell.md
Last active March 10, 2024 14:49
Start an interactive Python shell session from within a script

from here: http://stackoverflow.com/questions/5597836/embed-create-an-interactive-python-shell-inside-a-python-program

paste this inside your script for debugging, to start a Python interactive terminal shell session at that point in the script, super useful for debugging since it lets you explore the Python environment and access objects and variables as they are at that point in the script.

import readline # optional, will allow Up/Down/History in the console
import code
vars = globals().copy()
vars.update(locals())
@stevekm
stevekm / ssh_server_commands.md
Last active December 4, 2023 15:02
handy ssh, rsync, scp commands

Here are some handy commands for connecting to servers and copying files about. These are all for Linux terminal / bash shell

Do cool things with ssh; log in & run command, find files in dir

# log into server
ssh username@server.edu -Y 
# -X      Enables X11 forwarding. <- use this to enable X11 graphical windows, but this will eventually time out & you'll lose the X11 connection
# -Y      Enables trusted X11 forwarding. <- this one preserves your X11 connection while you're logged in
@stevekm
stevekm / igv_test_bat.md
Last active April 28, 2022 06:50
Sample Batch Script for IGV Snapshots
@stevekm
stevekm / pdf_conversions.md
Last active June 29, 2023 01:13
Commands to convert multi-page PDF to/from multiple PNG files with GhostScript & ImageMagick
@stevekm
stevekm / py.md
Created October 27, 2016 04:31
Ordered default dict in Python 2.7 (and maybe 3)

http://stackoverflow.com/questions/6190331/can-i-do-an-ordered-default-dict-in-python

# from collections import OrderedDict, defaultdict
import collections
class OrderedDefaultDict(collections.OrderedDict, collections.defaultdict):
    def __init__(self, default_factory=None, *args, **kwargs):
        #in python3 you can omit the args to super
        super(OrderedDefaultDict, self).__init__(*args, **kwargs)
 self.default_factory = default_factory
@stevekm
stevekm / gist:dc9687be27c777979786b7a1e0546c29
Last active October 26, 2016 19:40
quickly print out chr chromosome names in a format for easy conversion to R character vector
$ cat data/depth13Genome.depth.summary2.averages_sd.txt | cut -f1
chr1
chr10
chr11
chr12
chr13
chr14
chr15
chr16