Saturday, July 10, 2010
For when you don't want to gut your debugging code for IE.
Mock Console
Just enough to swallow 'console.log()'
if ("undefined" === typeof window.console)
{
window.console = {
"log": function() { }
};
};
Mock Firebug
Fairly complete mock of Firebug.
if (!("undefined" !== typeof window.console && (window.console.firebugVersion || window.console.firebug )))
{
window.console = {
"assert": function() { },
"count": function() { },
"clear": function() { },
"debug": function() { },
"dir": function() { },
"dirxml": function() { },
"info": function() { },
"error": function() { },
"getFirebugElement": function() { },
"group": function() { },
"groupEnd": function() { },
"groupCollapsed": function() { },
"log": function() { },
"notifyFirebug": function() { },
"profile": function() { },
"profileEnd": function() { },
"time": function() { },
"timeEnd": function() { },
"trace": function() { },
"warn": function() { },
"userObjects": [],
"element": {},
"firebug": "foo"
};
};
Tuesday, June 29, 2010
After all the reams of C# and MembershipProvider sample code I have written on stack overflow, a silly
jquery/javascript question is about to eclipse all others.
Thursday, June 10, 2010
The one complaint I have had with my Lenovo T61-p has been the transposition of the CTRL and FN keys.
The keyboard is quite usable for it's size but the ctrl/fn issue makes it unusable, for me. It bugs me so much that I had decided, to my dismay, that I would not buy another Lenovo. If I had hands on experience with the keyboard before cutting the check for this box I would have reconsidered.
So, I have grumbled about this for a couple years. And somehow I never thought of Ctrl2Cap, a sysinternals utility by Mark Russinovich.
Tada! I am back in love with my notebook. Granted, it is a couple years old, but with core2 2.1ghz, 8 gb fast ram and an intel x-25 SSD, I rarely find myself complaining about performance. And now I can hack out code while on the move without toting around an external keyboard. Yay!
Now I just need to install Ctrl2Cap on all my boxes for a consistant UX.
Sunday, May 23, 2010
// Project: Salient
// http://salient.codeplex.com
//
// Copyright 2010, Sky Sanders <sky at skysanders.net>
// Dual licensed under the MIT or GPL Version 2 licenses.
// http://salient.codeplex.com/license
//
// Date: May 24 2010
#region
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ICSharpCode.SharpZipLib.Zip;
#endregion
namespace Salient.IO.Compression
{
public static class DirectoryCompression
{
public static void CompressDirectory(this Stream target, string sourcePath,
Func<string, bool> excludeFromCompression)
{
sourcePath = Path.GetFullPath(sourcePath);
string parentDirectory = Path.GetDirectoryName(sourcePath);
int trimOffset = (string.IsNullOrEmpty(parentDirectory)
? Path.GetPathRoot(sourcePath).Length
: parentDirectory.Length);
List<string> fileSystemEntries = new List<string>();
fileSystemEntries
.AddRange(Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories)
.Select(d => d + "\\"));
fileSystemEntries
.AddRange(Directory.GetFiles(sourcePath, "*", SearchOption.AllDirectories));
using (ZipOutputStream compressor = new ZipOutputStream(target))
{
compressor.SetLevel(9);
foreach (string filePath in fileSystemEntries)
{
if (excludeFromCompression(filePath))
{
continue;
}
compressor.PutNextEntry(new ZipEntry(filePath.Substring(trimOffset)));
if (filePath.EndsWith(@"\"))
{
continue;
}
byte[] data = new byte[2048];
using (FileStream input = File.OpenRead(filePath))
{
int bytesRead;
while ((bytesRead = input.Read(data, 0, data.Length)) > 0)
{
compressor.Write(data, 0, bytesRead);
}
}
}
compressor.Finish();
}
}
public static void DecompressToDirectory(this Stream source, string targetPath, string pwd,
Func<string, bool> excludeFromDecompression)
{
targetPath = Path.GetFullPath(targetPath);
using (ZipInputStream decompressor = new ZipInputStream(source))
{
if (!string.IsNullOrEmpty(pwd))
{
decompressor.Password = pwd;
}
ZipEntry entry;
while ((entry = decompressor.GetNextEntry()) != null)
{
if (excludeFromDecompression(entry.Name))
{
continue;
}
string filePath = Path.Combine(targetPath, entry.Name);
string directoryPath = Path.GetDirectoryName(filePath);
if (!string.IsNullOrEmpty(directoryPath) && !Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
if (entry.IsDirectory)
{
continue;
}
byte[] data = new byte[2048];
using (FileStream streamWriter = File.Create(filePath))
{
int bytesRead;
while ((bytesRead = decompressor.Read(data, 0, data.Length)) > 0)
{
streamWriter.Write(data, 0, bytesRead);
}
}
}
}
}
}
}
Usage
using System;
using System.IO;
using NUnit.Framework;
using Salient.IO.Compression;
namespace CoreFiveConnector.Tests
{
[TestFixture]
public class Class1
{
[Test]
public void Test()
{
Func<string, bool> excludeFromCompression = path => { return false; };
MemoryStream compressed = new MemoryStream();
compressed.CompressDirectory("c:\\Temp", excludeFromCompression);
// sharpzip closes the target so we need to create a new seekable stream
MemoryStream compressed2 = new MemoryStream(compressed.ToArray());
Func<string, bool> excludeFromDecompression = path => { return false; };
compressed2.DecompressToDirectory("c:\\Temp2", null, excludeFromDecompression);
}
}
}
Saturday, May 22, 2010
I have just released the beta build of CassiniDev.VisualStudio, a fully compatibly drop in replacement for the Visual Studio Development Server (WebDev.WebServer.exe)
Why?
Myself and others have found over the years that while WebDev is a reliable development and debugging companion is falls a bit short in some areas including serving the correct content-type for many file types and the lack of discoverable logging.
These issues and more are now covered in CassiniDev, including the Visual Studio builds.
But the most attractive reason to replace WebDev.WebHost with CassiniDev is the ability to further customize the behavior and functionality of your development environment with relative ease.
Check it out and download it here: http://cassinidev.codeplex.com/