Skip to content

Instantly share code, notes, and snippets.

View chadmichel's full-sized avatar
😀
Working

Chad Michel chadmichel

😀
Working
View GitHub Profile
@chadmichel
chadmichel / gist:9917565
Created April 1, 2014 16:20
Extension method to return number of records in an MSMQ.
static class MessageQueueExt
{
/// <summary>
/// Return number of messages in the MSMQ.
/// from: http://stackoverflow.com/questions/3869022/is-there-a-way-to-check-how-many-messages-are-in-a-msmq-queue
/// </summary>
public static int Count(this MessageQueue queue)
{
var queueCounter = new System.Diagnostics.PerformanceCounter(
"MSMQ Queue",
@chadmichel
chadmichel / gist:a19176a7e3ad94000ce3
Created August 26, 2014 04:19
Lame, but quick nodejs / express static file server
var express = require('express');
var app = express();
var path = require('path');
// ugly error handling
app.use(function(err, req, res, next){
console.error(err.stack);
res.send(500, 'Bad things');
});
@chadmichel
chadmichel / ViewController.swift
Last active August 29, 2015 14:07
Super Basic Swift MapKit Example
import UIKit
import MapKit
// source: http://stackoverflow.com/questions/25460310/swift-mapkit-example-project
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet weak var mappy: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
@chadmichel
chadmichel / gist:b2b27efa8ded68b6cbdf
Created January 8, 2015 05:25
Data Accessor Example using Swift and SQLite.Swift
import Foundation
import SQLite
class QuestionSet {
var id: Int = 0
var title: String = ""
@chadmichel
chadmichel / gist:f586a3e585dc0f55fc23
Last active August 29, 2015 14:14
Dismiss keyboard anytime user touches outside of the keyboard
// http://forums.xamarin.com/discussion/5934/ios-newb-how-do-you-get-rid-of-the-keyboard
var g = new UITapGestureRecognizer(() => View.EndEditing(true));
View.AddGestureRecognizer(g);
@chadmichel
chadmichel / gist:7139443
Created October 24, 2013 15:37
Web Api - make routing include Actions
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// ADD ACTION TO routeTemplate BELOW!!!
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
@chadmichel
chadmichel / gist:7413695
Created November 11, 2013 14:08
Super Basic MEF Example
public interface IHello
{
string Message();
}
[Export(typeof(IHello))]
public class Hello : IHello
{
public string Message()
{
@chadmichel
chadmichel / CustomerManager.cs
Created November 12, 2013 15:14
MEF Unit Test Mocking
public class CustomerManager : ICustomerManager
{
[Import]
public ICustomerAccessor CustomerAccessor { get; set; }
public void Upgrade(string customerId)
{
// To upgrade a customer we must first find the customer.
var customer = CustomerAccessor.Find(customerId);
// Set Pro equal to true.
@chadmichel
chadmichel / gist:7434071
Created November 12, 2013 16:32
Transaction Scope and unit tests. Set transaction scope before unit tests. Don't commit and all your DB changes will rollback, great for accessor unit tests.
public class MyTests
{
TransactionScope _testTransactionScope;
#region transaction scope
[TestInitialize]
public void TestInitialize()
{
@chadmichel
chadmichel / AccessorFactory.cs
Created November 12, 2013 16:58
Unit Test example and basic dependency injection
public class AccessorFactory
{
public virtual T Create<T>()
where T : class
{
if (typeof(T).Name == "CustomerAccessor")
return new CustomerAccessor() as T;
return null;
}