Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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;