Skip to content

Instantly share code, notes, and snippets.

View bennage's full-sized avatar
📺
please stay tuned

Christopher Bennage bennage

📺
please stay tuned
View GitHub Profile
@bennage
bennage / NormalizeLineEndings.cs
Created March 16, 2012 22:43
quick and dirty for normalizing all the line endings in project (curse you autocrlf!)
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace NormalizeLineEndings
{
internal class Program
{
@bennage
bennage / math.rb
Created September 29, 2011 03:57
Adah's First Ruby Script
# adah's first program
puts 'what is the number to divide?'
x=gets.to_i
puts 'what do you want to divide it by?'
y=gets.to_i
puts 'here is the answer.'
puts x/y
r=x%y
if r != 0 then
@bennage
bennage / ezekiel.cs
Created July 27, 2011 05:15
a console app for Windows that monitors changes to a directory and restarts node.js for me
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
namespace ezekiel
{
class Program
@bennage
bennage / jslint-helper-for-wsh.js
Created April 26, 2011 07:20
a script for executing jslint on a command line in Windows. Execute with: cscript.exe jslint-helper-for-wsh.js file-to-test.js
/*jslint evil: true, white: true, onevar: true, undef: true, nomen: true, regexp: true, plusplus: true, bitwise: true, newcap: true, maxerr: 10, indent: 4 */
/*global JSLINT, WScript, ActiveXObject, Enumerator*/
(function () {
var jslint_path = 'jslint.js',
jslint_source = '',
utf8 = '',
fso = new ActiveXObject('Scripting.FileSystemObject'),
files = [],
args = WScript.Arguments;
@bennage
bennage / Can_insert_async_and_get_sync.cs
Created January 17, 2011 15:43
example of a Raven client test on the .NET side
[Fact]
public void Can_insert_async_and_get_sync()
{
using (var server = GetNewServer(port, path))
{
var documentStore = new DocumentStore { Url = "http://localhost:" + port };
documentStore.Initialize();
var entity = new Company { Name = "Async Company" };
using (var session = documentStore.OpenAsyncSession())
@bennage
bennage / AsyncDocumentStoreServerTests.cs
Created January 15, 2011 22:19
improved syntax for Raven's Silverlight unit tests
namespace Raven.Tests.Silverlight
{
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Client.Document;
using Client.Extensions;
using Database.Data;
using Database.Indexing;
using Document;
@bennage
bennage / pattern-matching.fs
Created November 19, 2010 20:08
a simple example of pattern matching in F#
type Shape =
| Circle of float
| Rectangle of double*double
| EquilateralTriangle of double
let pi = 3.141592654
let area shape =
match shape with
| Circle r -> r*r*pi
@bennage
bennage / reduce.cs
Created September 12, 2010 05:00
reduce function, functional version
// functional version - recursion instead of a loop
static int ReduceF(Func<int, int, int> reducer, IEnumerable<int> values, int seed)
{
return values.Any()
? ReduceF(reducer, values.Skip(1), reducer(seed, values.First()))
: seed;
}
@bennage
bennage / reduce.cs
Created September 12, 2010 04:54
reduce function, imperative version
// imperative version - uses a loop
static int Reduce(Func<int, int, int> reducer, IEnumerable<int> values)
{
int accum = 0;
foreach (var i in values)
{
accum = reducer(accum, i);
}
return accum;
}
open System
open System.ComponentModel
open System.Web.Mvc
open Microsoft.FSharp.Reflection
// inspired by http://www.atrevido.net/blog/CommentView,guid,d5591bdc-add1-4fbc-b1d9-0c25359433a6.aspx
type MyModelBinder() =
let rec makeDefaultRecord ty =