Skip to content

Instantly share code, notes, and snippets.

@alanb1501
alanb1501 / server.js
Created March 4, 2015 21:51
very simple node.js http server
var http = require('http');
http.createServer(function (req,res ){
console.log(req);
res.writeHead(200,{'content-type':'text/html'});
res.end('<html><body><h1>HELLO WORLD</h1></body></html>');
}).listen(7777,'localhost');
@alanb1501
alanb1501 / starwars.sh
Last active April 9, 2016 13:34
Reads a random starwars quote in each voice available via the `say` command. (OS X only)
#!/usr/bin/env bash
for voice in $(say -v ? | perl -pe 's/^(.*?)\s.*$/$1/'); do quote=$(curl -s http://www.iheartquotes.com/api/v1/random?source=starwars | perl -pe 's/\[starwars.*?$//g'); echo $voice; say -v $voice $quote; done
@alanb1501
alanb1501 / fib.js
Last active August 29, 2015 14:03
Fibonnaci
/*
A fibonacci number is defined as the sum of the previous 2 numbers in the sequence.
By definition, the first 2 fibonacci numbers are 1 and 1.
Thus the sequence goes: 1,1,2,3,5,8,13,21,34...n-2,n-1,n
or more plainly put:
Fibonacci(n) = Fibonacci(n-1) + Fibonacci(n-2)
Below are 4 different solutions to calculate the Nth number in the fibonacci sequence
*/
@alanb1501
alanb1501 / gist:8778921
Created February 3, 2014 04:38
Google US Chart
<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {'packages': ['geochart']});
google.setOnLoadCallback(drawMarkersMap);
function drawMarkersMap() {
var data = google.visualization.arrayToDataTable([
['State', 'Population'],
@alanb1501
alanb1501 / fulltube.js
Created November 7, 2013 19:40
Takes Youtube and makes it full browser window
javascript: (function() {
var u = document.location.href;
if(!u) { alert('Try using on Youtube'); return; }
if(u.indexOf('youtube.com') == -1) {
alert('Try using on Youtube'); return;
}
var m = u.match(/v=([\w\d]+)/);
if(!m) {
@alanb1501
alanb1501 / d3rollup.js
Created October 12, 2013 23:45
Rolling up data with D3
var arr = d3.nest()
.key(function(d) {
var dt = new Date(d.date);
var ret = [dt.getUTCFullYear(),dt.getUTCMonth()+1,dt.getUTCDate()];
return ret.join('-');
})
.rollup(function(d) {
var sum = 0;
for(var i = 0; i < d.length; ++i) {
sum+= d[i].value;
@alanb1501
alanb1501 / gist:5118348
Created March 8, 2013 17:48
Disable W3C Total Cache caching of other WP plugin content.
add_action('wp_head','inject_javascript');
function inject_javascript() {
?>
<!-- mfunc
$uid = uniqid ();
echo '<!-- Plugin v.01 ID: -->';
echo '<!--'. $uid .'-->';
echo "\n";
-->
<!--/mfunc -->
@alanb1501
alanb1501 / gist:4014596
Created November 5, 2012 00:45
espn.gist
{"sports" :[{"name" :"basketball","id" :40,"leagues" :[{"name" :"National Basketball Assoc.","abbreviation" :"nba","id" :46,"groupId" :7,"shortName" :"NBA","teams" :[{"id" :1,"location" :"Atlanta","name" :"Hawks","abbreviation" :"ATL","color" :"002B5C","links" :{"api" :{"teams" :{"href" :"http://api.espn.com/v1/sports/basketball/nba/teams/1"},"news" :{"href" :"http://api.espn.com/v1/sports/basketball/nba/teams/1/news"},"notes" :{"href" :"http://api.espn.com/v1/sports/basketball/nba/teams/1/news/notes"}},"web" :{"teams" :{"href" :"http://espn.go.com/nba/team/_/name/atl/atlanta-hawks?ex_cid=espnapi_public"}},"mobile" :{"teams" :{"href" :"http://m.espn.go.com/nba/clubhouse?teamId=1&ex_cid=espnapi_public"}}}},{"id" :2,"location" :"Boston","name" :"Celtics","abbreviation" :"BOS","color" :"006532","links" :{"api" :{"teams" :{"href" :"http://api.espn.com/v1/sports/basketball/nba/teams/2"},"news" :{"href" :"http://api.espn.com/v1/sports/basketball/nba/teams/2/news"},"notes" :{"href" :"http://api.espn.com/v1/sports/ba
@alanb1501
alanb1501 / fizzbuzz.lingpad.cs
Created March 6, 2012 05:57
fizzbuzz linqpad
for(int i = 1; i <= 100; ++i)
{
if (i % 15 == 0)
{
"FizzBuzz".Dump();
}
else if(i % 3 == 0)
{ "Fizz".Dump();}
else if( i % 5 == 0)
{ "Buzz".Dump();}