Skip to content

Instantly share code, notes, and snippets.

View whistler's full-sized avatar

Ibrahim Muhammad whistler

View GitHub Profile
@whistler
whistler / unicode.rb
Created September 17, 2012 01:22
Unicode is Ruby file
# encoding: UTF-8
# Add the about comment in the ruby file
@whistler
whistler / gist:4699578
Created February 2, 2013 22:39
Install Rails on Mac
# Pre-requisite: X-Code Command Line Tools: http://connect.apple.com
# install homebrew
/usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
# git
brew install git
#rbenv
@whistler
whistler / ubuntu_nodejs.sh
Created June 30, 2013 09:59
This script installs nodejs, coffeescript and git on an Ubuntu machine. Configures git to use with Github and clones a repository with a node project and installs its dependencies.
# This script installs nodejs, coffeescript and git on an Ubuntu machine.
# Configures git to use with Github and clones a repository with a node
# project and installs its dependencies.
# 30 Jun 2013
# Ibrahim Muhammad
# http://ibrahimmuhammad.com
# install node prereqs
sudo apt-get install python-software-properties python g++ make
@whistler
whistler / client.coffee
Last active December 20, 2015 02:49
How to use socket.io-client to keep retrying for server or connect to a different server
client = require 'socket.io-client'
socket = null
host = "http://localhost:12345"
connect_client = () ->
console.log('connecting')
socket = client.connect(host, {'force new connection': true})
socket.on('connect', ()->
console.log('connected')
@whistler
whistler / google_analytics.py
Created August 16, 2016 21:26
Fetch Page View Data from Google Analytics
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 / async_await.js
Created February 21, 2017 21:23
Javascript Async Await
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 / list_comprehension_benchmark.py
Created February 21, 2017 21:31
Benchmark loops vs list comprehension
N = 10000000
def loops():
nums = []
for num in range(N):
nums.append(num*2)
#print nums
def list_comprehensions():
@whistler
whistler / add_swap.sh
Created November 2, 2017 03:32
Add more swap space on Ubuntu 17
count=12288
sudo swapoff -a
sudo dd if=/dev/zero of=/swapfile bs=1M count=1024
sudo mkswap /swapfile
sudo swapon /swapfile
@whistler
whistler / merge_aois.py
Created April 6, 2018 02:47
Merge two GeoJSON AOIs into one
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 / setup.sh
Last active July 25, 2018 21:54
Conda environment for deep learning, image processing, data science
# 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