Skip to content

Instantly share code, notes, and snippets.

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