Skip to content

Instantly share code, notes, and snippets.

View AtmaMani's full-sized avatar

Atma Mani AtmaMani

View GitHub Profile
@AtmaMani
AtmaMani / zshrc.md
Last active October 23, 2020 23:00
custom-zsh-profile.md

Newer Mac OS uses ZSH instead of bash. This wiki will talk through setting it up with nice features such as autocomplete, colorized ls, git & conda aware prompts etc.

Steps

  1. After upgrading to zsh, confirm you have it by typing zsh in terminal.
  2. Install a framework such as Oh my zsh which will simplify the whole process. Rest of steps assume you have it running. As of today, you can install it by running

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)".

Restart terminal.

@AtmaMani
AtmaMani / bash_commands.md
Last active December 2, 2022 05:10
Bash commands

Frequently used bash commands

Recursively list or count files of a particular extension

To search for all notebook files: find . -type f -name "*.ipynb" | wc -l will return the count in all subdirectories.

To just list the files, do: find . -type f -name "*.ipynb"

Compress and archive a directory

@AtmaMani
AtmaMani / custom.bashprofile.md
Last active October 11, 2019 20:51
Mac terminal bash profile

Tell ls to be colorful

export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='ls -GFh'

To display git repo status with colors and branch name

parse_git_branch() {
@AtmaMani
AtmaMani / dsx-snippets.md
Last active September 18, 2020 20:39
DSX snippets

Jupyter tricks

Creating note cells

<div class="alert alert-info">
    <b>Note:</b> If you are running this guide in an environment <b>without <code>arcpy</code></b>, you can comment out the line that imports it and proceed with the guide. The Python API will look for <code>shapely</code> library and use it for geometry operations.
</div>

Embed Python API map widgets within HBox and VBox

@AtmaMani
AtmaMani / git-pr-review-workflow.md
Last active July 23, 2019 20:54
Push up changes to a PR while reviewing

How to checkout a branch from a fork of your repo?

git remote add <name> <url.git>

This adds the forked repo as a remote. You don't need this if you have merge privileges. You can then fetch and checkout the branch of your choice

git fetch <name or remote>
git checkout  # allow tab completion to help you here.
@AtmaMani
AtmaMani / python-shortcuts.py
Last active August 8, 2022 18:46
Python shortcuts and optimizations
#flatten a list of list
extent = [[-84.28620418884404, 33.98540048952816], [-84.09769613557806, 34.090609514767856]]
flat_list = [element for sublist in extent for element in sublist]
# [-84.28620418884404, 33.98540048952816, -84.09769613557806, 34.090609514767856]
#stringify a list of numbers
stringified_flat_list = ','.join(str(e) for e in flat_list)
# '-84.28620418884404,33.98540048952816,-84.09769613557806,34.090609514767856'
@AtmaMani
AtmaMani / parallel-downloader.py
Created September 11, 2017 23:55
Script to download images in parallel
import requests
from pathlib import Path
import multiprocessing
#read the download file
with open('./download_links.txt','r') as fhandle:
files = fhandle.readlines()
def downloader(url):
img_name = Path(url).name.rstrip('\n')
@AtmaMani
AtmaMani / module_walker.py
Created August 4, 2017 17:51
Python Module walker
# simple python script to walk a module and print publicly accessible identifiers
#Import your library
from arcgis.gis import GIS
import inspect
#instantiate your root object
gis = GIS()
#build up a list of primitive/builtin types to ignore. You can add your custom types as well.
@AtmaMani
AtmaMani / python-ftp-file-downloader.py
Created May 25, 2017 20:19
python-ftp-file-downloader
import ftplib
# connect to the server
ftp = ftplib.FTP('ftp.ncdc.noaa.gov') #pass the url without protocol
ftp.login() #pass credentials if anonymous access is not allowed
# switch to the directory containing the data
ftp.cwd('/pub/data/swdi/database-csv/v2/')
ftp.pwd()
@AtmaMani
AtmaMani / fetch_pyvideo.py
Created May 21, 2017 22:21 — forked from codeinthehole/fetch_pyvideo.py
Fetch PyCon videos from pyvideo.org and convert them to M4V so they can be synced to your iPhone
# Hacky script for downloading videos from PyVideo and converting them to m4v
# format so they can be synced onto your apple device. Useful if you
# want to see everything that happened at PyCon while commuting.
#
# Requirements:
# * pip install requests BeautifulSoup
# * youtube-dl (from https://github.com/rg3/youtube-dl/) - add this to the
# directory where this script runs and ensure its execute bit is set.
# This was the only YouTube downloader I found that worked. It doesn't
# really have a good Python API so I call it through os.system.