Skip to content

Instantly share code, notes, and snippets.

@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 / TrackRegexRetweeter.py
Created March 8, 2010 23:40
This is a simple Twitter bot which listens to a track stream for a comma delimited list of terms/tags (PRIMARY_TRACK_LIST). From this stream, it will retweet any tweet that matches the secondary regex (SECONDARY_REGEX_FILTER).
#!/usr/bin/env python
# This is a simple Twitter bot which listens to a track stream for a comma delimited
# list of terms/tags (PRIMARY_TRACK_LIST). From this stream, it will retweet any
# tweet that matches the secondary regex (SECONDARY_REGEX_FILTER).
#
# This example is a #Haiti & #Chile Twitter stream listener for TweakTheTweet syntax.
#
# Requires Python 2.6
# Requires Tweepy http://github.com/joshthecoder/tweepy
#
@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 / 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.
@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)
library(RColorBrewer)
library(maptools)
library(ggplot2)
library(mapproj)
library(rgdal)
## make sure you call
gpclibPermit()
data(wrld_simpl)
@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")