Skip to content

Instantly share code, notes, and snippets.

View rockarts's full-sized avatar
💭
🐝 🇨🇦

Steven Rockarts rockarts

💭
🐝 🇨🇦
  • Edmonton, AB
View GitHub Profile
@rockarts
rockarts / USAZipCodes
Created July 6, 2011 16:37
USA Zip Codes
35004
35005
35006
35007
35010
35014
35016
35019
35020
35023
@rockarts
rockarts / Restore.rb
Created August 9, 2011 22:06
Builds a restore database script to execute with SQLCMD.
class Restore
def initialize(settings)
@settings = settings
end
def Build()
"#{@settings['sqlcmd']} -E -Q \" RESTORE DATABASE #{@settings['projectname']} FROM DISK = \'#{@settings['database_path']}#{@settings['projectname']}.bak\'\""
end
@rockarts
rockarts / Backup.rb
Created August 9, 2011 22:16
A Class that uses SQLCMD runner to backup a database.
class Backup
def initialize(settings)
@settings = settings
end
def Run()
"#{@settings['sqlcmd']} -E -Q \" BACKUP DATABASE #{@settings['projectname']} TO DISK = \'#{@settings['database_path']}#{@settings['projectname']}.bak\'\""
end
end
@rockarts
rockarts / filter.xslt
Created October 26, 2011 20:04
XSLT Filtering of Output from the Wix Harvest.exe
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
<xsl:output method="xml" indent="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
@rockarts
rockarts / LCD Numbers
Created December 2, 2011 22:25
LCD Numbers for Ruby Quiz
-- -- -- --
| | | | | | | |
| | | | | | | |
-- -- -- --
| | | | | | |
| | | | | | |
-- -- -- --
- - - -
| | | | | |
@rockarts
rockarts / TicketMachineTest.cs
Created March 1, 2012 21:00
Port of http://gmoeck.github.com/2011/10/26/stubbing-is-not-enough.html to C# Asserts on the behaviour of an object instead of the state.
using NUnit.Framework;
using Rhino.Mocks;
namespace ScratchPad
{
[TestFixture]
public class TicketMachineTest
{
[Test]
public void ShouldReserveTheNumberofTicketsInputtedWhenTheUserSubmitsARequest()
@rockarts
rockarts / XML Diff
Created November 14, 2012 23:36
Compares 2 XMl documents and spits out the merged file with additions, updates and deleted nodes removed.
public void CompareTwoXmlFilesInMemory()
{
using (MemoryStream diffgram = new MemoryStream())
{
XmlTextWriter diffgramWriter = new XmlTextWriter(new StreamWriter(diffgram));
XmlDiff xmldiff =
new XmlDiff(XmlDiffOptions.IgnoreChildOrder | XmlDiffOptions.IgnoreNamespaces | XmlDiffOptions.IgnorePrefixes);
bool identical = xmldiff.Compare(@"appconfig2.xml", @"appconfig3.xml", false, diffgramWriter);
@rockarts
rockarts / gist:5373289
Created April 12, 2013 16:28
Print all embedded resources
Console.Out.WriteLine(string.Join(", ", GetType().Assembly.GetManifestResourceNames()));
@rockarts
rockarts / VerifyCopyComplete.cs
Created June 19, 2013 17:53
Notice that I have passed the FileStream to the ProcessFiles. This creates a readlock on the file, making it impossible to let the file being opened by another program or thread. You use the FileStream to read the acquired file (eg StreamReader sr = new StreamReader(myFileStream) ).
string[] existingFiles = Directory.GetFiles(ProcessPath, "*.xml");
foreach (string fileName in existingFiles)
{
FileInfo fi = new FileInfo(fileName);
FileStream fs = null;
while (fs == null && fi.Exists)
{
try
{
fs = fi.Open(FileMode.Open, FileAccess.Read, FileShare.None);
@rockarts
rockarts / .githelpers
Created May 14, 2014 05:41
Git Helpers
HASH="%C(yellow)%h%C(reset)"
RELATIVE_TIME="%C(green)%ar%C(reset)"
AUTHOR="%C(bold blue)%an%C(reset)"
REFS="%C(red)%d%C(reset)"
SUBJECT="%s"
FORMAT="$HASH $RELATIVE_TIME $AUTHOR $REFS $SUBJECT"
function pretty_git_log() {
git log --graph --pretty="tformat:$FORMAT"