Skip to content

Instantly share code, notes, and snippets.

@myazdani
myazdani / copy-files-to-chunks.py
Created April 15, 2015 20:37
copy a list of files to a target directory split into evenly sized chunks
import os
import shutil
src_path = "/Users/myazdaniUCSD/Desktop/hourly_colors/"
num_chunks = 6
target_path = "/Users/myazdaniUCSD/Desktop/some_dir/"
def chunks(l, n):
""" Yield successive n-sized chunks from l.
"""
@myazdani
myazdani / Images_From_CSV_to_dir.py
Last active August 29, 2015 14:22
Copy Image paths specified in a CSV column to a specific directory
import pandas as pd
import os
import shutil
import sys
if len(sys.argv) < 1:
print "provide CSV file argument, followed by target directory argument,",\
" followed by which column to use from csv file (optional)"
elif len(sys.argv) < 4:
in_file = sys.argv[1]
@myazdani
myazdani / resize_images_batch.py
Created July 20, 2015 21:36
resize images to a base width maintaining aspect ratio given a target directory
import os
from PIL import Image
src_path = "./testing2/"
out_path = "./"
basewidth = 75
image_type = (".jpg", ".png", ".JPG", ".PNG", ".JPEG", ".tif", ".tiff", ".TIFF")
image_paths = []
@myazdani
myazdani / gist:b990558ca0df3ca10f77
Created August 20, 2015 15:50
batch rename images png to jpg
ls *.png | awk '{print("mv "$1" "$1)}' | sed 's/png/jpg/2' | /bin/sh
@myazdani
myazdani / dir_check.py
Created July 6, 2017 00:14
Check if a directory exists and create
import os
directory = "sample_dir"
if not os.path.exists(directory):
os.makedirs(directory)
@myazdani
myazdani / plotly-2d-scatter.ipynb
Created December 20, 2017 20:29
Brain dead implementation of 2d interactive scatter plots with plotly in python for rending in a jupyter notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# jupyter notebook --NotebookApp.iopub_data_rate_limit=1.0e10
import plotly.graph_objs as go
import plotly.graph_objs as go
import plotly.offline as offline
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
offline.init_notebook_mode()
@myazdani
myazdani / glove-embeddings-load.py
Created March 31, 2019 18:44
Loading glove embeddings in Pandas DataFrame
import pandas as pd
import csv
glove_df = pd.read_csv("glove.6B.50d.txt.zip", sep=" ", index_col=0, header=None,
quoting=csv.QUOTE_NONE)
"new york" in glove_df.index
vocabs = list(glove_df.index)
@myazdani
myazdani / time-stamped-logdir.py
Created November 5, 2019 12:29
Creating a unique name for a logging based on current time stamp.
from datetime import datetime
now = datetime.utcnow().strftime("%Y%m%d%H%M%S")
root_logdir = "tf_logs"
logdir = "{}/run-{}/".format(root_logdir, now)
@myazdani
myazdani / father_son_heights.tsv
Created December 2, 2019 23:10
Tab separated data of father and son heights as collected by Karl Pearson.
Father Son
65.0 59.8
63.3 63.2
65.0 63.3
65.8 62.8
61.1 64.3
63.0 64.2
65.4 64.1
64.7 64.0
66.1 64.6