Skip to content

Instantly share code, notes, and snippets.

View leviwilson's full-sized avatar

Levi Wilson leviwilson

  • Northwoods
  • Colorado, USA
View GitHub Profile
@leviwilson
leviwilson / CppUTest_MockTest.cpp
Created February 17, 2011 16:42
CppUTest - expectNCalls fails with ignoreOtherParameters
#include <iostream>
#include <CppUTest/CommandLineTestRunner.h>
#include <CppUTestExt/MockSupport.h>
using namespace std;
class Foo
{
public:
virtual void MyFunction(int something)
#ifndef MemLeakCheckingTest_h
#define MemLeakCheckingTest_h
#include <gtest/gtest.h>
#if defined(WIN32) && defined(_DEBUG)
// Used to redirect _CrtXXX functions output to stderr, instead of the MSVC
// trace window.
int __cdecl crtReportHook(int reportType, char *szMsg, int *retVal)
@leviwilson
leviwilson / otl_old_vs_new.cpp
Created March 3, 2011 22:10
OTL vs Embedded SQL Dll
extern "C"
{
int InitSQL();
int Rollback();
int Commit();
int DoMySelect(MyItem** ppItems);
};
void DoSomethingTheOldWay();
@leviwilson
leviwilson / gist:1057757
Created July 1, 2011 02:21
RoR Associations
#rails gen model Player name:string
class Player < ActiveRecord:Base
has_many :wins, :class_name => "Game", :foreign_key => "winner"
has_many :losses, :class_name => "Game", :foreign_key => "loser"
end
#rails gen model Game winner:integer loser:integer
class Game < ActiveRecord:Base
belongs_to :winner, :class_name => "Player", :foreign_key => "player_id"
belongs_to :loser, :class_name => "Player", :foreign_key => "player_id"
@leviwilson
leviwilson / gist:1236687
Created September 23, 2011 03:31
Crap VB.NET Early Returns
void Sub exampleBtn_Click(Object sender, EventArgs e)
{
if( txtBox1.Value <> "" ) then
if( txtBox1.Value = "some other bad thing" ) then
Exit Sub
end if
end if
' 50 million things like this, sometimes nested deeper
}
@leviwilson
leviwilson / sharepoint_claims_guid.cs
Created October 18, 2011 17:16
Getting User Guid From SharePoint
public class SharepointHelper
{
public static string UserName
{
get { return CurrentClaim.Value; }
}
private static SPClaim CurrentClaim
{
get { return SPClaimProviderManager.Local.DecodeClaim(SPContext.Current.Web.CurrentUser.LoginName); }
@leviwilson
leviwilson / Noesis.JavaScript.Headless.Example.cs
Created November 4, 2011 13:41
Noesis.Javascript.Headless Example
using NUnit.Framework;
using Noesis.Javascript.Headless;
using Noesis.Javascript.Headless.Reporters;
namespace Noesis.Javascript.Headless.Example.Specs
{
[TestFixture]
public class JasmineSpecs
{
private JavaScriptTestRunner _jsTestRunner;
@leviwilson
leviwilson / nunit.jasmine.results.cs
Created November 7, 2011 05:12
Reporting Jasmine Results
public class ResultsReporter : IJavaScriptReporter
{
private readonly Dictionary<string, string> _results = new Dictionary<string,string>();
public Dictionary<string, string> Results
{
get { return _results; }
}
public string Result
{
@leviwilson
leviwilson / EnumerableExtensions.cs
Created November 7, 2011 16:08
Example Extension Methods
public static class EnumerableExtensions
{
public static void ForEach<T>(this IEnumerable<T> items, Action<T> action)
{
foreach (var item in items)
action(item);
}
}
@leviwilson
leviwilson / backbone-view-spec.js
Created November 7, 2011 16:17
Jasmine Spy Misuse
describe('Backbone View Example', function () {
beforeEach(function () {
this.collection = jasmine.createSpyObj(MyModels, ['bind']);
this.view = new MyView({collection: this.collection});
});
it('should render itself when the collection changes', function () {
expect(this.collection.bind)
.toHaveBeenCalledWith(['change', this.view.render]);
});