Skip to content

Instantly share code, notes, and snippets.

@ayman
ayman / ziplen.R
Last active February 3, 2022 20:55
Compute the distances between all US Zipcodes in R.
## Compute the distances between all US Zipcodes.
## To save time we just compute the diagonal and use multiple cores.
require(parallel)
library(geosphere)
library(MASS)
library(zipcode)
data(zipcode)
## Uncode for testing
## zipcode <- zipcode[1:10,]
zips.num = dim(zipcode)[1]
@ayman
ayman / bingReverseGeocode.swift
Created August 17, 2015 18:33
Simple Lookup to Bing for their ReverseGeocoder
class func bingReverseGeocode(inout location: CLLocation,
callback: (CLLocation) -> Void) {
var bingAPIKey = "ABCDEF-1234567890"
var lat = location.coordinate.latitude
var lon = location.coordinate.longitude
var u = "http://dev.virtualearth.net/REST/v1/Locations/\(lat),\(lon)?o=json&key=\(bingAPIKey)"
var url = NSURL(string: u)
var request: NSURLRequest = NSURLRequest(URL: url!)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url!, completionHandler: {data, response, error -> Void in
@ayman
ayman / init-jabber.el
Last active August 29, 2015 14:23
Making MacOS notifications kinda work.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Jabber Terminal Notifier
;; requires 'init-terminal-notifier.el'
;; https://gist.github.com/ayman/bb72a25e16af9e6f30bf
(defun jabber-info-terminal-notify (infotype buffer text)
"Pushing info notifications through terminal-notify."
(unless (get-buffer-window buffer)
(terminal-notifier-notify "Jabber" (jabber-escape-xml text))))
@ayman
ayman / init-terminal-notifier.el
Last active April 21, 2024 20:04 — forked from justinhj/gist:eb2d354d06631076566f
Add native MacOS notifications to Emacs...simply.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Terminal notifier
;; requires 'sudo port install terminal-notifier'
;; stolen from erc-notifier
;;
;; (terminal-notifier-notify "Emacs notification"
;; "Something amusing happened")
(defvar terminal-notifier-command
(executable-find "terminal-notifier")
library(RColorBrewer)
library(maptools)
library(ggplot2)
library(mapproj)
library(rgdal)
## make sure you call
gpclibPermit()
data(wrld_simpl)
@ayman
ayman / readRowCount.R
Created May 21, 2015 18:12
By setting the number of rows a file is before it's read, R speeds up tremendously and doesn't leak memory. Here's a quick trick to get a file's row count within R.
f.name <- "file.csv"
f.command <- paste("wc -l",
f.name,
"| cut -d \" \" -f 2")
f.rows <- as.numeric(system(f.command, intern = TRUE))
f <- read.csv(f.name,
nrows=f.rows,
col.names=c("user", "phone", "total", "percent"),
colClasses=c("numeric","numeric","numeric","numeric"),
header=FALSE)
@ayman
ayman / RGBCountrViewController.swift
Last active August 29, 2015 14:20
Simply take one photo and remember it, then count the RGB diff from the next photo. Ideally one should do this via histograms but this was quick and simple.
//
// RGBCountrViewController.swift
// RGBCountr
//
// Created by David A. Shamma on 4/9/15.
// Some parts taken from around the web.
//
// Simply take one photo and remember it,
// then count the RGB diff from the next photo.
// Ideally one should do this via histograms but this was quick.
@ayman
ayman / get_cited_by_dois.py
Last active August 29, 2015 14:16
Get the DOIs for an ACM DL Citation...a simple scraper.
### Get the DOIs for an ACM DL Citation.
###
### David A. Shamma - GNU 2.0 License
###
## Call like this:
## get_citations('1290082.1290120', True)
## or just the tail/acm id
## get_citations('1290120')
##
## Prints to the console:
@ayman
ayman / areagraph.R
Created March 13, 2014 15:04
Some code for making AreaGraphs in R (from a tutorial but I made some memory and speed optimizations).
# Type 0: stacked area, 1: themeriver, 2: streamgraph
areaGraph <- function(thedata, type=2, smooth=TRUE) {
## Color palette
nColors <- 15
## pal <- colorRampPalette(c("#0f7fb4", "#e2e2e2"))
## pal <- colorRampPalette(c("#6364a9", "#e2e2e2")) # Purple
pal <- colorRampPalette(c("#48611d", "#f0f0f0"))
colors <- pal(nColors)
weights <- rowSums(thedata)
## Sort the data
@ayman
ayman / adafruitlightpaint4pi.py
Created September 25, 2013 05:42 — forked from ladyada/adafruitlightpaint4pi.py
Adafruit Light Painting with Pi (with added resize code)
#!/usr/bin/python
# Light painting / POV demo for Raspberry Pi using
# Adafruit Digital Addressable RGB LED flex strip.
# ----> http://adafruit.com/products/306
import RPi.GPIO as GPIO, Image, time
# Configurable values
filename = "hello.png"