Skip to content

Instantly share code, notes, and snippets.

View timvw's full-sized avatar

Tim Van Wassenhove timvw

View GitHub Profile
WITH
[Nums1] AS (SELECT 1 AS [Value] UNION SELECT 2 AS [Value])
, [Nums2] AS (SELECT A.* FROM [Nums1] AS A, [Nums1] AS B, [Nums1] AS C)
, [Nums3] AS (SELECT A.* FROM [Nums2] AS A, [Nums2] AS B, [Nums2] AS C)
, [Nums4] AS (SELECT A.* FROM [Nums3] AS A, [Nums3] AS B)
, [Nums] AS (SELECT TOP(1000) ROW_NUMBER() OVER(ORDER BY (SELECT 0)) AS [n] FROM[Nums4])
, [Data] AS (SELECT 1 AS [id], N'The upcoming release of SQL Server is codenamed Denali. It is also called SQL11 which refers to version 11 and peple misunderstand it to be SQL Server 2011.' AS [comment] UNION SELECT 2 AS [id], N'SQL Server Denali CTP 3 introduced a number of TSQL enhancements.' AS [comment])
, [Sentences] AS (
SELECT [id]
, [comment]
@timvw
timvw / gist:2759128
Created May 20, 2012 18:53
Add missing books to iTunes
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using iTunesLib;
namespace ConsoleApplication1
{
class Program
{
@timvw
timvw / ValueComparer.cs
Created July 22, 2012 06:49
ValueComparer
public class ValueComparer<T> : IEqualityComparer<T>
{
private readonly Func<T, object>[] _valueSelectors;
private readonly Func<T, int> _hashCodeFunction;
public ValueComparer(params Func<T, object>[] valueSelectors)
: this(t => t.GetHashCode(), valueSelectors)
{
_valueSelectors = valueSelectors;
}
@timvw
timvw / ChainedComparer.cs
Created July 27, 2012 08:05
Chained comparisions
public class ChainedComparer<T> : IComparer<T>
{
private readonly Func<T, T, int>[] _compareFunctions;
public ChainedComparer(params Func<T, T, int>[] compareFunctions)
{
_compareFunctions = compareFunctions;
}
public ChainedComparer(params Func<T, IComparable>[] comparableValueSelectors)
@timvw
timvw / convert_podcasts_to_mp3.applescript
Created November 13, 2012 22:42
Use iTunes to convert all non-mp3 podcasts to mp3 in iTunes
tell application "iTunes"
set podcast_playlist to some playlist whose special kind is Podcasts
set podcasts_to_convert to file tracks of podcast_playlist
repeat with podcast_to_convert in podcasts_to_convert
set podcast_location to location of podcast_to_convert
if not podcast_location is missing value then
set podcast_location to "" & podcast_location
if podcast_location does not contain "mp3" then
convert podcast_to_convert
-- display dialog podcast_location
public static class SqlCommandExtensions
{
public static void ResultsToConsole(this SqlCommand sqlCommand)
{
using (var sqlDataReader = sqlCommand.ExecuteReader())
{
while (sqlDataReader.Read())
{
Console.WriteLine();
for (var i = 0; i < sqlDataReader.FieldCount; ++i)
var parser = require('xml2json');
var fs = require('fs');
var cwd = process.cwd();
fs.readdir(cwd, function(err, files) {
if(err){
console.log(err);
return;
}
@timvw
timvw / gist:7906093
Created December 11, 2013 06:56
Cards
type Suit =
| Spades
| Hearts
| Diamonds
| Clubs
type Rank =
| Ace
| King
| Queen
@timvw
timvw / syncgit.sh
Created January 20, 2014 10:12
Call git fetch for each folder in /c/src/Git
#!/bin/bash
find /c/src/Git -type d -mindepth 1 -maxdepth 1 -exec git --work-tree={} --git-dir={}/.git fetch \;
let (|Array|_|) pattern toMatch =
let patternLength = Array.length pattern
let toMatchLength = Array.length toMatch
let tailLength = toMatchLength - patternLength
if patternLength > toMatchLength then
None
else
let firstElementsAreEqual = [ 0 .. (patternLength - 1) ] |> Seq.forall (fun i -> pattern.[i] = toMatch.[i])
if firstElementsAreEqual then