Skip to content

Instantly share code, notes, and snippets.

// Useful for browser console operations ala Firebug or Chrome Dev Tools
// http://techrageo.us/2008/03/05/jquery-for-firebug/
j=document.createElement("SCRIPT");
j.src="http://code.jquery.com/jquery-latest.pack.js";
document.getElementsByTagName("HEAD")[0].appendChild(j);
@TheDahv
TheDahv / ManualGoogleAuth.fs
Created October 22, 2010 23:54
For getting a Google auth token using Client Login without Google's libraries in F#
open System.Text
open System.IO
open System.Net
open System.Web
let auth =
let URL = "https://www.google.com/accounts/ClientLogin"
let webRequest = HttpWebRequest.Create(URL)
webRequest.Method <- "POST"
webRequest.ContentType <- "application/x-www-form-urlencoded"
@TheDahv
TheDahv / GoogleAnalytics_GetWebRequestHelper.fs
Created October 22, 2010 23:56
Combined with an auth token, this function returns the contents of a web request to a given URL
GetWebRequestHelper (url:string) =
let req = HttpWebRequest.Create(url)
req.Headers.Add("Authorization: GoogleLogin auth=" + auth)
let response = req.GetResponse()
let responseStream = response.GetResponseStream()
let sr = new StreamReader(responseStream)
sr.ReadToEnd()
@TheDahv
TheDahv / FSharpHttpAsync.fs
Created January 10, 2011 03:48
Function to get the contents of a URL asynchronously
open System.Net
let getHttpContents (url:string) = async {
let req = WebRequest.Create(url)
let! response = req.AsyncGetResponse()
use stream = response.GetResponseStream()
use streamreader = new System.IO.StreamReader(stream)
let contents = streamreader.ReadToEnd()
return contents
}
@TheDahv
TheDahv / FriendHighlight.js
Created April 11, 2011 22:56
My main feed is mixed with friend activity and jquery activity. I want friend activity highlighted.
// ASSUMPTION: jQuery is already loaded on the GitHub home page
// ASSUMPTION: Your username is TheDahv ;)
// JQUERY, I SUMMON YOU TO DO MY BIDDING WITH THIS HORRENDOUS ONE-LINER (FORMATTED FOR CONVENIENCE!!!)
$.get('https://github.com/TheDahv/following',
function (data) {
var members = $(data).find('.members > li').map(function(i,m) { return m.children[0].getAttribute('href').replace(/\//,""); });
$('.news > div.alert').each(
function(i,a) {
var title = a.children[0].children[0];
@TheDahv
TheDahv / scalable_image.html
Created May 18, 2011 16:40
Scalable background image on a site
<html>
<head>
<title>Scalable Image Test</title>
<style type="text/css">
body {
/* Background image rules */
background-attachment: fixed;
background-color: #333;
background-image: url(../img/bgimg.png);
background-position: top right;
var groupedByWeek = new List<DateTime> {
new DateTime(2012, 02, 01),
new DateTime(2012, 02, 02),
new DateTime(2012, 02, 06),
new DateTime(2012, 02, 13)
}.
GroupBy(s => s.DayOfYear / 7).
ToDictionary(
s => (new DateTime(2012, 01, 01).AddDays((s.First().DayOfYear / 7) * 7)),
s => s.Count()
@TheDahv
TheDahv / gist:2142285
Created March 20, 2012 23:11
Teach Cromer how to do JavaScript
// wrapped in anonymous function to protect against
// leaks to global NS
(function () {
// Factory to create objects
var make_thing = function (initial_value) {
var thing = that = {};
thing.value = initial_value;
thing.dosomething = function () {
return that.value; // 'that' is 'closed over'
@TheDahv
TheDahv / gist:2173457
Created March 23, 2012 18:22
NPM Install Failure Report
# node -v => v0.6.13
# npm -v => 1.1.9
# python (IronPython) -v => IronPython 2.7.1 (2.7.0.40) on .NET 4.0.30319.17379
PS C:\Applications\node\js-browser-automation> npm install jsdom
npm http GET https://registry.npmjs.org/jsdom
npm http 304 https://registry.npmjs.org/jsdom
npm http GET https://registry.npmjs.org/cssom
npm http GET https://registry.npmjs.org/contextify
npm http GET https://registry.npmjs.org/request
@TheDahv
TheDahv / template.fs
Created April 23, 2012 19:01
FSharp Html Templating
namespace FSharpTemplate
module Template =
type HtmlElement =
| Html of HtmlElement list
| Head of HtmlElement list
| Title of string
| Body of HtmlElement list
(* id, class, children *)
| Div of string * string * HtmlElement list