Skip to content

Instantly share code, notes, and snippets.

View rohitfarmer's full-sized avatar

Rohit Farmer rohitfarmer

View GitHub Profile
@rohitfarmer
rohitfarmer / helper.md
Last active January 30, 2019 22:20
Helper functions

Function to add indicator column(s) in a Pandas dataframe.

def add_indicator(df):
    """
    Purpose
    -------
    Add indicator column next to any column that has one or more NaNs.
    The indicator column contains 1 at the index that has NaN in the parent data column.
    The NaNs in the parent data columns are replaced with 0.
@rohitfarmer
rohitfarmer / screen.md
Created November 19, 2018 16:34
Commands for Linux Screen

To scroll in screen session
Press "Ctrl-A" on the keyboard and press "Esc."

Press the "Up" and "Down" arrow keys or the "PgUp" and "PgDn" keys to scroll through previous output.

Press "Esc" to exit scrollback mode.

Screen output logging to a file
screen -L -S testscreen

@rohitfarmer
rohitfarmer / tensorboard.md
Created November 16, 2018 16:29
Commands related to tensorboard

Script to write tensorboard logs during execution.

import tensorflow as tf

a = tf.constant(2, name='a')
b = tf.constant(3, name='b')
x = tf.add(a,b, name='add')

writer = tf.summary.FileWriter('./graphs', tf.get_default_graph())
@rohitfarmer
rohitfarmer / python_cheats.md
Created November 8, 2018 16:29
Example code in Python

To get the index of a value in a list
indx = [i for i, v in enumerate(lis) if v == 1]

@rohitfarmer
rohitfarmer / pandas.md
Last active March 14, 2019 19:21
Pandas examples

Merge, join and concat

To merge dataframes when their indexes are same but may not be of equal length i.e. some samples may be missing in either of the df.
p_m_smi = pd.merge(p_smi, met_smi, left_index=True, right_index=True, how='outer', sort=False)

[left, right]_index : True to use indexes to merge on. For columns set left_on or right_on.
Outer: means union, Pandas will put NaN for the rows that are missing in either of the dataframes.
Sort: keep false if the dataframes are already sorted for efficiency.

To concatenate column wise

@rohitfarmer
rohitfarmer / vim.md
Last active November 2, 2018 16:29
Commands for VIM

Commands for Matt's implementation of VI

Toggle nerd tree: / + n
To open a file in the nerd tree in split window: s
Switch screen: ctrl + ww
To run the script without quitting VI: :! python name.py

Visualization mode to cut, copy, paste etc.
shift + v

@rohitfarmer
rohitfarmer / tensorflow.md
Created November 2, 2018 16:18
Cheat sheet for tensorflow

Using Tensor Board

import tensorflow as tf

a = tf.constant(2, name='a')
b = tf.constant(3, name='b')
x = tf.add(a,b, name='add')

writer = tf.summary.FileWriter('./graphs', tf.get_default_graph())
with tf.Session() as sess:
@rohitfarmer
rohitfarmer / nvidia.md
Created November 2, 2018 16:14
Command for NVIDIA GPUs

To get the diver info

modinfo nvidia

To get summary info

nvidia-smi
nvidia-smi --query-gpu=driver_version --format=csv,noheader
@rohitfarmer
rohitfarmer / hpc.md
Last active April 11, 2019 15:22
HPC commands
@rohitfarmer
rohitfarmer / basic-recipes.md
Created October 22, 2018 18:30 — forked from andypiper/basic-recipes.md
Some recipes for the Twitter API for twurl +jq, and other useful Twitter code snippets and tools

The basics

This is a collection of basic "recipes", many using twurl (the Swiss Army Knife for the Twitter API!) and jq to query the Twitter API and format the results. Also, some scripts to test or automate common actions.