This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
http://www.JSON.org/json2.js | |
2010-08-25 | |
Public Domain. | |
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. | |
See http://www.JSON.org/js.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'nokogiri' | |
require 'yaml' | |
class File | |
def writeline(value) | |
self.write(value + "\n") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
via: http://javascriptweblog.wordpress.com/2010/09/20/auto-generating-javascript-unit-tests/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+JavascriptJavascript+(JavaScript,+JavaScript) | |
*/ | |
var tester = { | |
testing: [], | |
console: window.console || {log: function(a) {window.status = a}, warn: alert}, | |
defineBaseTests: function() { | |
this.baseTestBefore = [this.argumentsDefinedTest, this.thisBindingTest]; | |
this.baseTestAfter = [this.returnTest]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var func = WrapLambda<Outie, Innie, bool>(j => j.BoolVal, "Inner").Compile(); | |
var resultTrue = func(new Outie { Inner = new Innie { BoolVal = true } }); | |
var resultFalse = func(new Outie { Inner = new Innie() }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This is a model that will be used in each of the examples below. | |
public class Product | |
{ | |
public Product() | |
{ | |
// Default values are to be set here | |
Shipping = new Address(); | |
} | |
public ObjectId _id{get;set;} | |
public double Price{get;set;} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var db = Mongo.Create ("mongodb://localhost/testdb")) | |
{ | |
var posts = db.GetCollection<Post> (); | |
//you can just put a lambda expression in for the fields that you want indexed. | |
posts.CreateIndex (j => new { j.Body, j.Title }, | |
"Compound_Post_Index",true,IndexOption.Ascending); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Post GetMostRecentPost() | |
{ | |
Post mostRecentPost; | |
using(var db = Mongo.Create("mongodb://localhost/BlogApp")) | |
{ | |
var posts = db.GetCollection<Post>(); | |
//create a LINQ queryable to search the DB. | |
var q = posts.AsQueryable(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Norm; | |
using Norm.Responses; | |
using Norm.Collections; | |
using Norm.Linq; | |
public class MongoSession { | |
private string _connectionString; | |
public MongoSession() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Widget | |
{ | |
public ObjectId Id {get;set;} | |
public String Color {get;set;} | |
public double Price {get;set;} | |
public DateTime ReleaseDate {get;set;} | |
public IEnumerable Reviews {get;set;} | |
} | |
//Next, spool up a connection to your database | |
//(The DB doesn't have to exist yet, but MongoDB DOES need to be running) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Makes a hex string from bytes. | |
public static String HexStringForBytes(this IEnumerable<bytes> bytes) | |
{ | |
return bytes.Aggregate(new StringBuilder(), (seed,current)=>seed.AppendFormat("{0:x2}",current)).ToString(); | |
} |