Skip to content

Instantly share code, notes, and snippets.

@andyoakley
andyoakley / gist:1651851
Created January 21, 2012 07:05
Include tweets into HTML via javascript
var url_pattern = /(\()((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(\))|(\[)((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(\])|(\{)((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(\})|(<|&(?:lt|#60|#x3c);)((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]+)(>|&(?:gt|#62|#x3e);)|((?:^|[^=\s'"\]])\s*['"]?|[^=\s]\s+)(\b(?:ht|f)tps?:\/\/[a-z0-9\-._~!$'()*+,;=:\/?#[\]@%]+(?:(?!&(?:gt|#0*62|#x0*3e);|&(?:amp|apos|quot|#0*3[49]|#x0*2[27]);[.!&',:?;]?(?:[^a-z0-9\-._~!$&'()*+,;=:\/?#[\]@%]|$))&[a-z0-9\-._~!$'()*+,;=:\/?#[\]@%]*)*[a-z0-9\-_~$()*+=\/#[\]@%])/img;
var url_replace = '$1$4$7$10$13<a href="$2$5$8$11$14">$2$5$8$11$14</a>$3$6$9$12';
requestURL = "http://api.twitter.com/1/statuses/user_timeline/apoakley.json?count=5&include_rts=t&callback=?";
$.getJSON(requestURL, function(json, status){
var content = "";
$.each(json, function(i){
tweet = this['text'].replace(url_pattern, url_replace);
content += "<li class=\"tweets\">" + tweet + "</li>";
});
@andyoakley
andyoakley / gist:1651859
Created January 21, 2012 07:10
Simple PivotTable in Powershell
# Rotates a vertical set similar to an Excel PivotTable
#
# Given $data in the format:
#
# Category Activity Duration
# ------------ ------------ --------
# Management Email 1
# Management Slides 4
# Project A Email 2
# Project A Research 1
@andyoakley
andyoakley / gist:2901757
Created June 9, 2012 16:50
Accessing the TED Footprints Dashboard API
$wc = new-object System.Net.WebClient
$xml = [xml]($wc.DownloadString("http://localhost:9090/dashboarddata"))
$voltage = $xml.DashboardData.VrmsNowDsp
$kw = $xml.DashboardData.KWNow