Skip to content

Instantly share code, notes, and snippets.

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

Steven Rockarts rockarts

💭
🐝 🇨🇦
  • Edmonton, AB
View GitHub Profile
require 'minitest/autorun'
class TestDeck < MiniTest::Unit::TestCase
def test_that_deck_has_52_cards
deck = Deck.new
assert_equal 52, deck.cards.count
end
def test_that_deck_is_shuffled
@rockarts
rockarts / TuesdaysCounter.rb
Last active August 29, 2015 14:03
This will fail for any month except the current month but will get the amount of Tuesdays in the current month.
require 'minitest/autorun'
require 'date'
class TestWeekdayCounter < MiniTest::Unit::TestCase
def test_number_of_tuesdays_in_june_2014_should_be_4
thisMonth = Date.new(2014, 6, 1)
nextMonth = Date.new(2014, thisMonth.month + 1, 1) - 1
assert_equal 4, WeekdayCounter.new.get_tuesdays(thisMonth, nextMonth)
end
@rockarts
rockarts / standard_deviation.rb
Created June 24, 2014 03:07
Class For Calculating the Standard Deviation of Arrays
require 'minitest/autorun'
# Test case provided by: http://en.wikipedia.org/wiki/Standard_deviation
class TestStandardDeviation < MiniTest::Unit::TestCase
def setup
@values = [2, 4, 4, 4, 5, 5, 7, 9]
end
def test_average_is_calculated
average = @values.inject{ |memo, element| memo + element} / @values.length
@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"
@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 / gist:5373289
Created April 12, 2013 16:28
Print all embedded resources
Console.Out.WriteLine(string.Join(", ", GetType().Assembly.GetManifestResourceNames()));
@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 / 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 / LCD Numbers
Created December 2, 2011 22:25
LCD Numbers for Ruby Quiz
-- -- -- --
| | | | | | | |
| | | | | | | |
-- -- -- --
| | | | | | |
| | | | | | |
-- -- -- --
- - - -
| | | | | |
@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()"/>