Skip to content

Instantly share code, notes, and snippets.

View timgaunt's full-sized avatar

Tim Gaunt timgaunt

View GitHub Profile
@timgaunt
timgaunt / gist:2659362
Created May 11, 2012 12:35
Facebook Like link without cookies or JavaScript
<a id="share-facebook" class="facebook" rel="nofollow" target="_blank" href="http://www.facebook.com/sharer.php?u=http://www.myurl.com" _fcksavedurl="http://www.facebook.com/sharer.php?u=http://www.myurl.com" title="Facebook - Link opens in a new window">Facebook</a>
@timgaunt
timgaunt / gist:2725813
Created May 18, 2012 15:17
Quick menu system for console applications
namespace TheSiteDoctor.Example
{
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
private static readonly IEnumerable<Tuple<string, string, Action>> menu = new List<Tuple<string, string, Action>>
{
@timgaunt
timgaunt / gist:2757576
Created May 20, 2012 10:19
Check the maximum length of a column
DECLARE @sql VARCHAR(max)
SELECT @sql = ''
SELECT
@sql = @sql + 'select ''' + table_name + ''',''' + column_name + ''',max(len([' + column_name + '])) from [' + table_name + '] union all '
FROM
information_schema.columns
SET @sql = left(@sql, len(@sql) - 9)
@timgaunt
timgaunt / gist:3620149
Created September 4, 2012 11:00
Non blocking Console.WriteLine
public static class NonBlockingConsole
{
private BlockingCollection<string> m_Queue = new BlockingCollection<string>();
static NonBlockingConsole()
{
var thread = new Thread(
() =>
{
while (true) Console.WriteLine(m_Queue.Take());
@timgaunt
timgaunt / gist:3620155
Created September 4, 2012 11:01
Queued Console.WriteLine
public static class QueuedConsole
{
private static StringBuilder _sb = new StringBuilder();
private static int _lineCount;
public void WriteLine(string message)
{
_sb.AppendLine(message);
++_lineCount;
if (_lineCount >= 10)
@timgaunt
timgaunt / DeleteByDatePattern.bat
Last active July 19, 2016 11:07
Automatically delete log files by filename pattern
@ECHO OFF
ECHO Delete By Date Pattern
ECHO Written by: Jason Faulkner
ECHO SysadminGeek.com (article: http://www.howtogeek.com/50528/automating-the-process-of-deleting-old-log-files/)
ECHO.
ECHO.
REM Delete/Select files based on a date which utilizes MM and/or DD for file naming patterns.
REM
REM Usage:
@timgaunt
timgaunt / jQuery.ConversionTracker.js
Created October 24, 2012 15:59
Google Analytics and Google AdWords link and button click tracker
/*!
* Conversion Tracker: a jQuery Plugin that tracks an event in both Google Analytics and Google AdWords
* @author: Tim Gaunt (@timgaunt)
* @url: http://blogs.thesitedoctor.co.uk/tim
* @documentation: http://blogs.thesitedoctor.co.uk/tim
* @published: 24/10/2012
* @license Creative Commons Attribution Non-Commercial Share Alike 3.0 Licence
* http://creativecommons.org/licenses/by-nc-sa/3.0/
*
* ----------------------
@timgaunt
timgaunt / gist:3999892
Created November 2, 2012 10:03
DATEDIFF (day, @LastTimesheetEntry, @DateNow) - (2 * DATEDIFF(week, @LastTimesheetEntry, @DateNow)) - CASE WHEN DATEPART(weekday, @LastTimesheetEntry + @@DATEFIRST) = 1 THEN 1 ELSE 0 END - CASE WHEN DATEPART(weekday, @DateNow + @@DATEFIRST) = 1 THEN 1 ELS
DATEDIFF (day, @LastTimesheetEntry, @DateNow) - (2 * DATEDIFF(week, @LastTimesheetEntry, @DateNow)) - CASE WHEN DATEPART(weekday, @LastTimesheetEntry + @@DATEFIRST) = 1 THEN 1 ELSE 0 END - CASE WHEN DATEPART(weekday, @DateNow + @@DATEFIRST) = 1 THEN 1 ELSE 0 END
@timgaunt
timgaunt / gist:3999899
Created November 2, 2012 10:04
List the length of every field in the table
DECLARE @table SYSNAME, @field SYSNAME
set @table = '## Your table name ##'
CREATE TABLE #Temp (TableName SYSNAME, ColumnName SYSNAME, MaxLength INT)
DECLARE a_cursor CURSOR STATIC
FOR
SELECT name FROM syscolumns c WHERE id = object_id(@table)
OPEN a_cursor
@timgaunt
timgaunt / gist:3999906
Created November 2, 2012 10:06
Umbraco - Sort By Date
<xsl:sort select="umbraco.library:FormatDateTime(##Date Field##, 'yyyyMMdd')" data-type="number" order="descending" />