Skip to content

Instantly share code, notes, and snippets.

Ibrahim Muhammad whistler

View GitHub Profile
@whistler
whistler / setup.sh
Last active Jul 25, 2018
Conda environment for deep learning, image processing, data science
View setup.sh
# To install the most recent version go to https://www.anaconda.com/download/
wget https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh
bash Anaconda3-5.2.0-Linux-x86_64.sh
conda install -y -c conda-forge jupyterlab
conda install -y scikit-learn
conda install -y pytorch torchvision cuda91 -c pytorch
conda install -y opencv matplotlib scikit-image
conda install -y affine #rasterio
pip install rasterio==1.0.1 # conda does not have v1 of rasterio yet
@whistler
whistler / merge_aois.py
Created Apr 6, 2018
Merge two GeoJSON AOIs into one
View merge_aois.py
from functools import reduce
import shapely.geometry
import geojson
def merge_aois(aois):
shapes = (shapely.geometry.asShape(aoi) for aoi in aois)
union = reduce(lambda a, b: a.union(b), shapes)
merged_aoi = geojson.Feature(geometry=union, properties={})
return merged_aoi
@whistler
whistler / add_swap.sh
Created Nov 2, 2017
Add more swap space on Ubuntu 17
View add_swap.sh
count=12288
sudo swapoff -a
sudo dd if=/dev/zero of=/swapfile bs=1M count=1024
sudo mkswap /swapfile
sudo swapon /swapfile
@whistler
whistler / list_comprehension_benchmark.py
Created Feb 21, 2017
Benchmark loops vs list comprehension
View list_comprehension_benchmark.py
N = 10000000
def loops():
nums = []
for num in range(N):
nums.append(num*2)
#print nums
def list_comprehensions():
@whistler
whistler / async_await.js
Created Feb 21, 2017
Javascript Async Await
View async_await.js
function fetch(url, callback) {
console.log('Getting ' + url);
var delay = (Math.round(Math.random() * 1E4) % 4000) + 1000
var response = 'Content for ' + url;
setTimeout(function() {
callback(response)
}, delay);
}
function promiseFetch(url) {
@whistler
whistler / google_analytics.py
Created Aug 16, 2016
Fetch Page View Data from Google Analytics
View google_analytics.py
import os
import json
import httplib2
import flask
from oauth2client import client
from apiclient.discovery import build
http_auth = None
view_id = '00000000' # Add view id here
@whistler
whistler / this.js
Last active Aug 29, 2015
this in if
View this.js
var AnimalView = Backbone.View.extend({
..
save: function() {
var that = this;
if(!this.isSaved) {
that.model.save()
} else {
that.alreadySaved();
}
},
@whistler
whistler / ofx2csv.py
Created Apr 19, 2015
Convert QFX/OFX to CSV
View ofx2csv.py
from csv import DictWriter
from glob import glob
from ofxparse import OfxParser
DATE_FORMAT = "%m/%d/%Y"
def write_csv(statement, out_file):
print "Writing: " + out_file
fields = ['date', 'payee', 'debit', 'credit', 'balance']
with open(out_file, 'w') as f:
View backspace.py
import sys
import time
for i in range(10):
print '\r', # print is Ok, and comma is needed.
time.sleep(0.3)
print i,
sys.stdout.flush() # flush is needed.
@whistler
whistler / import.sh
Created Mar 16, 2015
Copy files to another repository while saving git history
View import.sh
# copied from http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/
git clone <git repository A url> # clone source repository
cd <git repository A directory>
git remote rm origin # to make sure it doesn't affect the original repository
git filter-branch --subdirectory-filter <directory 1> -- --all # remove all files other than the ones needed
mkdir <directory 1> # move them into another directory where they will be stored in the destination repository (if needed)
mv * <directory 1>
git add .
git commit
You can’t perform that action at this time.