Skip to content

Instantly share code, notes, and snippets.

@danielwertheim
danielwertheim / gist:1306558
Created October 22, 2011 22:21
ServiceStack ISet
JSON:
{"StructureId":"45748284fbfce011910a544249037e42","Names":{"First":"Daniel","Last":"Wertheim"},"Values":{"Value":{"Is":99},"Guid":"19adfa6da12748e09291aeb75e8ca23c","Int":42,"Long":142,"String":"String in ValuesContainer.","Double":1.33,"Decimal":3.14,"Bool":true},"NullValuesContainer":{"Guid":"60d977f995fc40fd9a7e6827e920370f","Int":42,"Long":142,"String":"String in NullValuesContainer.","Double":1.33,"Decimal":3.14,"Bool":true},"NullValuesContainerWithNulls":{},"ValuesInArray":[{"Is":1},{"Is":2},{"Is":3}],"ValuesInIList":[{"Is":31},{"Is":32},{"Is":33}],"ValuesInList":[{"Is":41},{"Is":42},{"Is":43}],"ValuesInISet":[{"Is":11},{"Is":12},{"Is":13}],"ValuesInHashSet":[{"Is":21},{"Is":22},{"Is":23}]}
NOTE! ValuesInIList is deserialized to member but ValuesInISet is not.
public class MyClass
{
public MyClass() {}
... ... ...
@danielwertheim
danielwertheim / IDbDataTypeTranslator
Created October 28, 2011 11:51
DbDataTypeTransaltor
public interface IDbDataTypeTranslator
{
string ToDbType(IIndexAccessor indexAccessor);
string ToDbType(Type dataType);
}
@danielwertheim
danielwertheim / Query.sql
Created November 6, 2011 20:43
Key-value querying
-- C# Predicate: item.SortOrder == 2 || (item.SortOrder == 1 && item.StringValue == "B").Take(2).SortBy(item => item.StringValue)
-- Existing rows
-- {"StructureId":"208fad84b608e111b21c544249037e42","SortOrder":2,"StringValue":"D"}
-- {"StructureId":"218fad84b608e111b21c544249037e42","SortOrder":2,"StringValue":"C"}
-- {"StructureId":"228fad84b608e111b21c544249037e42","SortOrder":1,"StringValue":"B"}
-- {"StructureId":"238fad84b608e111b21c544249037e42","SortOrder":1,"StringValue":"A"}
@danielwertheim
danielwertheim / gist:1423261
Created December 2, 2011 13:35
Boilerplate stuff for MSpec
public class AssemblyInitializer : IAssemblyContext
{
private static bool _isInitialized;
public void OnAssemblyStart()
{
if (_isInitialized)
return;
_isInitialized = true;
@danielwertheim
danielwertheim / gist:1431128
Created December 4, 2011 20:01
Git .ignore
#v0.12
# Dev stuff
[Aa]pp_[Dd]ata/
[Bb]uild/
[Bb]uilds/
[Oo]bj/
[Bb]in/
[D]ebug/
[Tt]est[Rr]esult/
[Tt]emp/
@danielwertheim
danielwertheim / Factory.cs
Created December 28, 2011 20:36
Some fun with private ctors
public static class Factory<T> where T : class
{
private static readonly Func<T> FactoryFn;
static Factory()
{
//FactoryFn = CreateUsingActivator();
FactoryFn = CreateUsingLambdas();
}
@danielwertheim
danielwertheim / program.cs
Created January 9, 2012 21:22
ServiceStack struct fun
Content2 is represented as name in the Json, event if it's ToString returns null. Tried SerializeFn to.
var r = session.Query<Photo>().ToEnumerableOfJson()
.Select(s => s.Deserialize(new { Votes = 0, User = "" })) //The call
.GroupBy(s => s.User).ToArray();
//Ok, so the problem is that Votes and User doesn't get setters, right? But the have fields.
//E.g "<Votes>i__Field" which could be used
//Or perhaps the contract could be used to create a typed dictionary.
@danielwertheim
danielwertheim / gist:1709682
Created January 31, 2012 09:52
SisoDb - New transaction and session behavior
//Behavior today. Everything within the Session is treated as ONE atom transaction.
using(var session = db.BeginSession())
{
session.Insert(myFoo);
session.InsertMany(myBars);
session.Update(mySuperFoo);
}
//Thinking of.... each operation against session is treated as ONE atom operation.
using(var session = db.BeginSession())
@danielwertheim
danielwertheim / Step1.cs
Created February 20, 2012 23:27
Wiki controller example
[HandleError]
public class WikiController : Controller
{
[OutputCache(CacheProfile = "KiwiWikiCache")]
public ActionResult Doc(string docId)
{
return View(MvcApplication.MarkdownService.GetDocument(docId));
}
}