Skip to content

Instantly share code, notes, and snippets.

View whistler's full-sized avatar

Ibrahim Muhammad whistler

View GitHub Profile
@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 / console.js
Last active August 29, 2015 13:57
Access Angular service from console
service = angular.element('*[ng-app]').injector().get('serviceName')
@whistler
whistler / canvas_image.js
Created October 17, 2014 16:33
Add Image to Canvas
window.onload = function ()
{
var canvas = document.getElementById("overlay_canvas");
var ctx = canvas.getContext("2d");
var image = new Image();
image.src = "http://placekitten.com/4536/3024";
image.onload = function () {
ctx.drawImage(image, 0, 0);
image_ctx = image.getContext("2d");
debugger;
@whistler
whistler / import.sh
Created March 16, 2015 17:31
Copy files to another repository while saving git history
# 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
@whistler
whistler / backspace.py
Created March 26, 2015 00:31
Backspace Test
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 / ofx2csv.py
Created April 19, 2015 23:32
Convert QFX/OFX to CSV
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:
@whistler
whistler / this.js
Last active August 29, 2015 14:23
this in if
var AnimalView = Backbone.View.extend({
..
save: function() {
var that = this;
if(!this.isSaved) {
that.model.save()
} else {
that.alreadySaved();
}
},
@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) {