Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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.
library(RColorBrewer)
library(maptools)
library(ggplot2)
library(mapproj)
library(rgdal)
## make sure you call
gpclibPermit()
data(wrld_simpl)
@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 / 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 / Get YouTube FLV URL
Created September 2, 2008 20:15
Gets a YouTube FLV Url from the source of a page.
// Assuming 'response' is the source of a You Tube video page, this will get the flv url
var vid = id.substring(3);
var r = response;
var doc = r.substring(r.indexOf(".swf?video_id="));
var tpoint = r.indexOf("&t=");
var doc = r.substring(tpoint, r.indexOf("\"", tpoint));
var url = "http://youtube.com/get_video.php?video_id=";
url += vid + doc;
@ayman
ayman / CVExtras.pde
Last active December 19, 2015 17:29
For any Processing PImage, compute the histogram, the normalized histogram, and the overall Shannon entropy.
class CVExtras {
PImage pImage;
int[] hist = new int[256]; // Raw Pixel Counts
double[] histN = new double[256]; // Pixel Percentages (Normalized)
double entropy;
CVExtras(PImage img) {
for (int i = 0; i < 256; i++) {
this.hist[i] = 0;
this.histN[i] = 0.0;
@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"
@ayman
ayman / pistatus.sh
Last active June 9, 2016 00:50
Display a pretty status on a Raspberry Pi. I forget where I found the base script, but this has a few modifications.
#!/bin/bash
## zip=94114
zip="ASI|SG|SN---|SINGAPORE"
if [ -n "$1" ]; then
zip="$1"
fi
ip=`ip addr show scope global | grep inet | cut -d' ' -f6 | cut -d/ -f1 | tr "\n" " "`
oip=`wget -q -O - http://icanhazip.com/ | tail`