Skip to content

Instantly share code, notes, and snippets.

View captainsafia's full-sized avatar

Safia Abdalla captainsafia

View GitHub Profile
@captainsafia
captainsafia / deploy.js
Last active September 16, 2017 11:06
A quick Node script to allow multi-environment deploys with now
#! /usr/bin/env node
'use strict';
const program = require('commander');
const fs = require('fs');
const { spawn } = require('child_process');
program
.version('1.0.0')
.option('-e, --environment <environment>', 'Environment to deploy to')
@captainsafia
captainsafia / touchp.sh
Created August 30, 2017 16:20
Create a file and any intermediary directories if necessary
function touchp() {
mkdir -p "$(dirname "$1")/" && touch "$1"
}
import argparse
import csv
import sys
parser = argparse.ArgumentParser(description='Replace values on a column level in CSV')
parser.add_argument('--column', help='The column to replace in', required=True)
parser.add_argument('--search', help='The value to search for', required=True)
parser.add_argument('--replace', help='The value to replace it with', required=True)
@captainsafia
captainsafia / prompt_party
Created May 26, 2017 13:58
Set different parts of your command prompt with different random colors
# Prints username@hostname working-directory>
function prompt_party {
PS1="\[\033[38;5;$(jot -r 1 1 256)m\]\u\[\033[00m\]"
PS1="$PS1\[\033[38;5;$(jot -r 1 1 256)m\]@\[\033[00m\]"
PS1="$PS1\[\033[38;5;$(jot -r 1 1 256)m\]\h\[\033[00m\] "
PS1="$PS1\[\033[38;5;$(jot -r 1 1 256)m\]\w\[\033[00m\]> "
}
PROMPT_COMMAND=prompt_party
captainsafia@eniac ~> ipython
Python 2.7.12 (default, Jun 29 2016, 14:05:02)
Type "copyright", "credits" or "license" for more information.
IPython 4.2.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: # What's the fastest way to convert a column of minutes to hours?
In [2]: import pandas as pd
In [3]: import numpy as np
In [4]: minutes = pd.Series(np.random.randint(0, 1440, size=(20000)))
In [5]: minutes.shape
Out[5]: (20000,)
@captainsafia
captainsafia / usage.md
Last active April 19, 2017 20:03
A poor woman's filesystem watcher

To use watchman, run watchman file-to-watch sleep-time command-to-execute like so.

watchman test.txt 1 echo 'Tada!'
@captainsafia
captainsafia / zippy.fish
Created April 18, 2017 02:58
Save yourself a keypress when zipping folders
function zippy
zip -r $argv[1].zip $argv[1]
end
@captainsafia
captainsafia / gh-pull.fish
Last active March 16, 2017 16:55
A fish function that allows you to quickly checkout a branch for a pull request on a repo
function gh-pull
git fetch $argv[1] pull/$argv[2]/head:pr-$argv[2]
git checkout pr-$argv[2]
end
@captainsafia
captainsafia / quesadilla.bash
Created February 23, 2017 18:17
When the user has changed into a git directory, rebase with upstream if there are no uncommitted files.
function cd {
# Run the system CD command on the parameters that were passed in
builtin cd "$@"
# Check if the directory we are in now is a git directory
if [ -d ".git" ]; then
# If so, check to see that there are no uncommitted files
if [ $(git status --porcelain 2>/dev/null| egrep "^(M| M)" | wc -l) ]; then
# Rebase our current branch with upstream/master
git fetch upstream && git rebase upstream/master
fi