Skip to content

Instantly share code, notes, and snippets.

@dieseltravis
dieseltravis / c-sharp.cs
Last active September 22, 2015 21:24
Quarterly helper functions
private System.DateTime GetLastDayOfMonth(int intMonth, int intYear)
{
//todo: move to utility class
return DateAndTime.DateSerial(intYear, intMonth + 1, 0);
}
// Quarterly helper functions:
public static int GetQuarter(DateTime originalDate)
{
@dieseltravis
dieseltravis / gist:45165
Created January 9, 2009 16:44
localize all href/src for a xml/html content string
Public Shared Function LocalizeUrls(ByVal originalUrl As String, ByVal content As String) As String
' make image src's and anchor href's absolute in the string _sourceHtml
' get path for source
Dim siteUri As New Uri(originalUrl)
' modify img[@src] and a[@href]
Dim sources As MatchCollection = Regex.Matches(content, "(src|href)=([""'])(?!\#|http)([^\2]+?)(\2)", RegexOptions.Compiled Or RegexOptions.CultureInvariant Or RegexOptions.IgnoreCase)
For Each src As Match In sources
Dim attribute As String = src.Groups(1).Value
Dim quote As String = src.Groups(2).Value
@dieseltravis
dieseltravis / gist:46038
Created January 12, 2009 16:22
javascript querystring function
function querystring(param) {
if (location.search.length > 1) {
var qsArgs = location.search.substring(1, location.search.length).replace(/\+/g, " ").split("&");
for (var i = 0; i < qsArgs.length; i++) {
var pair = qsArgs[i].split("=");
var key = decodeURIComponent(pair[0]);
if (param == key) {
var value = (pair.length === 2)? decodeURIComponent(pair[1]): key;
return value;
}
@dieseltravis
dieseltravis / update.bat
Last active August 30, 2015 05:55
Keep a local copy of Sysinternals utilities updated
@echo off
Net Start Webclient
robocopy "\\live.sysinternals.com\Tools" "C:\Program Files\SysinternalsSuite" /LEV:0 /Z /XA:H /XF thumbs.db /XO /IT /R:10 /W:10
Net Stop Webclient
pause
@dieseltravis
dieseltravis / gist:99176
Created April 21, 2009 14:48
displaying char and word counts with jQuery
/*
sample HTML:
<div>
<p class="charStats wordStats">
<span class="curChars"><strong class="charVal">0</strong> chars</span>,
<span class="curWords"><strong class="wordVal">0</strong> words</span>
</p>
<textarea rows="2" cols="40" class="charCount wordCount"></textarea>
</div>
*/
@dieseltravis
dieseltravis / gist:100103
Created April 22, 2009 21:40
filtering a list by an object's property in VB.Net 2.0
Private _searchString As String
Private Function FindSomeObjectById(ByVal o As SomeObject) As Boolean
Dim searchID as Integer = 0
Integer.TryParse(_searchString, searchID)
Return o.Id = searchID
End Function
'etc...
@dieseltravis
dieseltravis / Readme.txt
Created June 16, 2009 21:32
A C# ASP.Net handler that concatenates, compresses, and caches CSS/JS files
Example usage:
...in <head>:
<link rel="stylesheet" type="text/css" href="/YuiCompressor.ashx?css=reset,style" />
...just before the </body>:
<script type="text/javascript" src="/YuiCompressor.ashx?js=main,someotherscript"></script>
Changelog:
2010-02-18: Updated to support HTTP compression
@dieseltravis
dieseltravis / gist:138964
Last active November 14, 2018 23:07
html escaping unicode entities with their numeric values: Javascript, VB.Net, C#
html = html.replace(/[\u0080-\uFFFF]/g, function($0) {
return "&#" + ($0).charCodeAt(0) + ";";
});
@dieseltravis
dieseltravis / gist:147952
Created July 15, 2009 20:18
jQuery example that gets/sets text nodes in html
// jQuery example that gets/sets text nodes in html
// wrap all direct child text nodes
$html.contents().filter(function() {
//Node.TEXT_NODE === 3
return (this.nodeType === 3);
}).each(function () {
this.nodeValue = $.trim(this.nodeValue);
if (this.nodeValue.length > 0) {
$(this).wrap("<p></p>");
@dieseltravis
dieseltravis / gist:166584
Created August 12, 2009 15:52
RegEx to match nested list items pasted from Word in IE6, IE7, and Firefox
var nestedListFixer = /(?:<\/li>(?:<\/ol>\s*)+)+(?:<p(?:\sstyle=\"[^\"]+\")?>(?:\s*<span(?:\sstyle=\"[^\"]+\")?>)*(?:(?:&(?:nbsp|\#0*160|x0*A0);)|\s)+(?:<\/span>)*(?:[ivxlcdm]+\.)(?:\s*<span(?:\sstyle=\"[^\"]+\")?>)*(?:(?:&(?:nbsp|\#0*160|x0*A0);)|\s)+(?:<\/span>)*(.*?)(?:<\/span>)*<\/p>\s*)+(?:<ol(?:\sstyle=\"[^\"]+\")?(?:\stype=\"?\w+\"?)?\sstart=\"?\d+\"?>\s*)+/gi;