Skip to content

Instantly share code, notes, and snippets.

@balupton
balupton / README.md
Last active February 10, 2025 05:38
Ajaxify a Website with the HTML5 History API using History.js, jQuery and ScrollTo
namespace Nancy.Demo.Hosting.Self
{
using System;
using System.Diagnostics;
using Nancy.Hosting.Self;
class Program
{
static void Main()
@kevinswiber
kevinswiber / Program.cs
Created November 23, 2011 23:05
Passing messages between Node.js and C#.
using System;
using System.Text;
namespace NodeIPC
{
class Program
{
static void Main(string[] args)
{
var input = Console.OpenStandardInput();
static readonly string[] videoCardBlacklist = {"8086:0116"};
static void DisableHwRenderingForCrapVideoCards()
{
if (!String.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("MY_VIDEO_CARD_REALLY_WORKS")))
{
return;
}
int osVersion = Environment.OSVersion.Version.Major * 100 + Environment.OSVersion.Version.Minor;
if (osVersion < 601)
@kellabyte
kellabyte / CQS_and_CQRS.cs
Created March 3, 2012 03:19
CQS_and_CQRS
// CQS (Command-Query Separation)
// Bertrand Meyer devised the CQS principle
// It states that every method should either be a command that performs an action, or a
// query that returns data to the caller, but not both. In other words, asking a question
// should not change the answer. More formally, methods should return a value only if they
// are referentially transparent and hence possess no side effects.
//
// Example:
public class CustomerService
anonymous
anonymous / gist:2291780
Created April 3, 2012 12:55
Convention based routing with MVC
public class DefaultRouteConventions: RouteConventions
{
public DefaultRouteConventions()
{
MapAction("Index").ConstraintToVerb(HttpVerbs.Get);
MapAction("List").ToRootPlural().ConstraintToVerb(HttpVerbs.Get);
MapAction("Details").WithParameters(
new List<ActionParam>() { new ActionParam() { IsComplexType = false, Name = "id" } }
@anaisbetts
anaisbetts / the original guy used autocrlf false
Created May 27, 2012 06:58
.gitattributes to solve your problems
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
@badsyntax
badsyntax / example.html
Created June 5, 2012 14:43
Twitter bootstrap tabs & jQuery BBQ hashchange history example
<!-- Tab sets have to have an id set -->
<div class="tabs" id="mytab1">
<ul class="nav nav-tabs">
<li><a href="#tab1">Tab 1</a></li>
<li><a href="#tab2">Tab 2</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane" id="tab1">
Content for tab 1
</div>
// TRY HARD SHIT.
// I did and I'm learning a lot.
//
// 2 days ago I had no idea what I was doing but I decided I was going to create
// a database. I figured this would be a great way to learn even more about the
// databases I use today. I will write better software because I will know how they are
// designed and the optimizations and limitations they have to work with.
//
// After two days I have:
// - Modelled column based data model (like Cassandra) on top of a key/value store (SQLite4 does I think).
@mikeeast
mikeeast / gist:4175450
Created November 30, 2012 12:15
GetValueSafe extension method
public static TResult GetValueSafe<TInstance, TResult>(this TInstance instance, Func<TInstance, TResult> accessor, TResult defaultValue = default(TResult))
where TInstance : class
{
return instance != null ? accessor(instance) : defaultValue;
}
usage:
someNullableObject.GetValueSafe(p => p.SomeProperty)
or