Skip to content

Instantly share code, notes, and snippets.

// dbjdbj@gmail.com
// Based on work by http://github.com/dieseltravis
(function () {
var trimLeft = /^\s+/, trimRight = /\s+$/;
// Verify that \s matches non-breaking spaces (IE fails on this test)
if ( !/\s/.test( "\xA0" ) ) {
trimLeft = /^[\s\xA0]+/;
trimRight = /[\s\xA0]+$/;
}
// Use native String.prototype.trim function wherever possible
@dieseltravis
dieseltravis / SendToPng.bat
Last active April 20, 2016 21:43
Usage: png.bat d:\images\
:: use this version when adding an option to Windows's Send To menu
:: https://gist.github.com/dieseltravis/343231
@echo off
setlocal enabledelayedexpansion
:: use passed in folder
SET folder=%~1
:: get original png sizes
set oldsize=0
for %%F in ("%folder%\*.png") do ( set /a oldsize=!oldsize!+%%~zF )
//EnhanceJS isIE test idea
//detect IE and version number through injected conditional comments (no UA detect, no need for cond. compilation / jscript check)
//version arg is for IE version (optional)
//comparison arg supports 'lte', 'gte', etc (optional)
function isIE(version, comparison) {
var cc = 'IE',
b = document.createElement('B'),
setInterval((function () {
console.log(new Date()); // run some arbitrary code
return arguments.callee; // here be the magic
})(), 1000);
// ^---- and that runs the function, and the return val is assign to the interval
@dieseltravis
dieseltravis / gist:360186
Created April 8, 2010 15:33
Splitting XML/XHTML on a node
<!-- Splitting XML/XHTML on a node (HR in this case) -->
<xsl:for-each select="./hr">
<xsl:variable name="currentPosition" select="position()" />
<div>
<xsl:if test="$currentPosition = 1">
<!-- first group of elements -->
<xsl:apply-templates select="preceding-sibling::*" />
</xsl:if>
<xsl:if test="$currentPosition != 1">
@dieseltravis
dieseltravis / Default.aspx.cs
Created July 9, 2010 21:18
NYS DEC KMZ-to-KML-to-CSV for GPS POIs
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Caching;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
@dieseltravis
dieseltravis / gist:479010
Created July 16, 2010 22:29
.net console apps that get a list of files changed by me
using System;
//Microsoft.TeamFoundation.Client.dll
using Microsoft.TeamFoundation.Client;
//Microsoft.TeamFoundation.VersionControl.Client.dll
using Microsoft.TeamFoundation.VersionControl.Client;
namespace GetPendingChanges
{
class Program
{
@dieseltravis
dieseltravis / gist:505715
Created August 3, 2010 02:09
filter an array so that it only contains unique items
var unique = function(thisArray) {
var a = [];
for (var l = thisArray.length; l--;) {
if(a.indexOf(thisArray[l], 0) < 0) {
a.push(thisArray[l]);
}
}
return a;
};
@dieseltravis
dieseltravis / gist:507683
Created August 4, 2010 05:16
reusable click simulator function for keypress event in jQuery
var pretendClick = function (e) {
if (e) {
var key = e.which || e.keyCode;
if (key && (key === 13 || key === 32)) {
e.preventDefault();
e.stopImmediatePropagation();
$(this).trigger("click");
}
}
};
@dieseltravis
dieseltravis / gist:521736
Created August 12, 2010 21:08
Find the RadEditor in a control
// There's a RadEditor in there somewhere...
using Telerik.Web.UI;
private RadEditor GetRadEditor(Control c)
{
RadEditor re = null;
try
{
re = (RadEditor)c;
}