Skip to content

Instantly share code, notes, and snippets.

View tathamoddie's full-sized avatar

Tatham Oddie tathamoddie

View GitHub Profile
@tathamoddie
tathamoddie / gist:b35a8f43e81a1cfd2383
Created June 19, 2014 05:39
window.clockSync.clientTimeAheadOfServerInMilliseconds
<script src="~/Scripts/moment.min.js"></script>
<script>
(function() {
var clientNow = moment();
var serverNow = moment('@(DateTimeOffset.UtcNow.ToString("o"))');
var diff = clientNow.diff(serverNow);
if (!!window.performance && !!window.performance.timing) {
var responseStartToNow = new Date().valueOf() - window.performance.timing.responseStart;
diff -= responseStartToNow;
}
@tathamoddie
tathamoddie / gist:9927848
Created April 2, 2014 04:17
Workaround visual bug with Windows Phone when you change themes, and then fast app switch back
void WorkaroundThemeResumeBugInWindowsPhone()
{
var backgroundColor = (Color)Application.Resources["PhoneBackgroundColor"];
var chromeColor = (Color)Application.Resources["PhoneChromeColor"];
var foregroundColor = (Color)Application.Resources["PhoneForegroundColor"];
RootFrame.Navigated += (sender, args) =>
{
SystemTray.BackgroundColor = backgroundColor;
SystemTray.ForegroundColor = foregroundColor;
@tathamoddie
tathamoddie / DOCO.md
Last active August 29, 2015 13:56
Change all ng- attributes to data-ng- instead

So, you built an AngularJS app.

You used ng- attributes everywhere, and now your W3C validation is failing.

You wish you had used data-ng- instead.

This script will fix them all for you.

.\Fix-AllAngularAttributesForHtml5.ps1 c:\code\myapp\web\Views -TfvcAware -Verbose -PrefixesToQuality @('ng', 'app')

git help {anything}

Find out about any command. For example, git help commit.

git init

Take the current folder, and turn it into a Git repo. (For when you're starting something new.)

@tathamoddie
tathamoddie / Find-JavaExe.ps1
Last active March 1, 2022 21:12
Attempting to find java.exe, on a Windows machine, in a way that's semi-reliable across Java versions, operating system versions, 32 vs 64-bit and whatever else can be thrown at us.
function Find-JavaExe {
<#
.SYNOPSIS
Locates java.exe on the current system via common conventions.
.DESCRIPTION
[alias]
st = status
ci = commit
br = branch
co = checkout
com = checkout master
fe = fetch origin
bn = !git for-each-ref --format='%(refname:short)' `git symbolic-ref HEAD`
rb = rebase
rbm = rebase master
@tathamoddie
tathamoddie / gist:5873372
Created June 27, 2013 01:50
Take all app.*.config transforms and run them, producing complete files with the same names
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<UsingTask TaskName="TransformXml" AssemblyFile="$(VSToolsPath)\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterCompile" Condition="exists('app.$(Configuration).config')">
<!-- Generate transformed app config in the intermediate directory -->
<TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
<!-- Force build process to use the transformed configuration file from now on. -->
<ItemGroup>
@tathamoddie
tathamoddie / LinkFormatting.cs
Last active February 13, 2017 15:01
How to invoke SkyDrive Pro's "Sync a new library" dialog from a webpage via the "grvopen" URI scheme
Uri BuildGrooveUri(Uri libraryUri)
{
const string grooveOpenUriTemplate = "grvopen://{0}/{1}/101?OPENLIST";
var uri = string.Format(
grooveOpenUriTemplate,
Encode(libraryUri.AbsoluteUri),
Encode(Guid.Empty.ToString())
);
return new Uri(uri);
}
@tathamoddie
tathamoddie / ActionTests.cs
Created December 14, 2012 03:18
Some common unit tests that I like to apply to ASP.NET MVC projects
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Security.Permissions;
using System.Web.Mvc;
using Example.Web;
using NUnit.Framework;
namespace Example.UnitTests.Web
@tathamoddie
tathamoddie / _.md
Created October 30, 2012 02:36
Configuring OSQA to use Integrated Windows Authentication on IIS7

This post assumes you have deployed it via Microsoft Web Platform Installer and http://www.helicontech.com/zoo/, and that it's already running.

  1. Disable Anonymous Authentication

  2. Enable Windows Authentication

  3. In settings.py, add these two middleware layers:

     django.contrib.auth.middleware.AuthenticationMiddleware
     django.contrib.auth.middleware.RemoteUserMiddleware
    

Add them between SessionMiddleware and CommonMiddleware, so the full list looks like this: