Skip to content

Instantly share code, notes, and snippets.

View rofr's full-sized avatar

Robert Friberg rofr

View GitHub Profile
@rofr
rofr / gist:8688105
Last active August 29, 2015 13:55
Example OrigoDB Server Razor Query
@using Todo.Core
@{
var listNames = Query(m => m.Lists.Select(list => list.Name).ToArray());
}
<ul>
@foreach (var name in listNames)
{
var tasks = Query(db => db.Lists.Single(list => list.Name == name)
.Tasks.Select(task => task.Title).ToArray());
@rofr
rofr / gist:8688418
Created January 29, 2014 13:53
OrigoDB Server Razor Query: Dump the entire database to JSON
@using Todo.Core
@{}
<pre>
@Json(Query(db => db))
</pre>
void WriteToStream(object graph, Stream target)
{
var formatter = new BinaryFormatter();
formatter.Serialize(target, graph);
}
object ReadFromStream(Stream source)
{
var formatter = new BinaryFormatter();
return formatter.Deserialize(source);
@rofr
rofr / gist:9410254
Created March 7, 2014 12:02
Code from geekstream.devrexlabs.com
public bool RemoveFeedById(int id)
{
Feed feedToRemove;
bool feedExists = TryGetFeedById(id, out feedToRemove);
if (feedExists)
{
_statistics.TotalFeeds--;
_statistics.TotalFeedItems -= feedToRemove.Items.Count;
_feeds[id-1] = null;
@rofr
rofr / gist:9410314
Created March 7, 2014 12:07
More code from geekstream.devrexlabs.com
private void RemoveFeedFromSearchIndex(Feed feed)
{
var searchTermsToRemove = new List<string>();
var itemsToRemove = new HashSet<FeedItem>(feed.Items);
foreach (KeyValuePair<string, HashSet<IndexEntry>> kvp in _searchIndex)
{
var searchTerm = kvp.Key;
var entrySet = kvp.Value;
@rofr
rofr / descriptive.cs
Last active August 29, 2015 13:57
Single letter generic type params or descriptive with T-prefix?
public class LocalEngineClient<TModel> : IEngine<TModel> where TModel : Model
{
public readonly Engine<TModel> Engine;
public LocalEngineClient(Engine<TModel> engine)
{
Engine = engine;
}
public class Args : Dictionary<string,object>{}
public class MyIoc
{
private Dictionary<Type, Dictionary<string, Func<Args, object>>> _registry
= new Dictionary<Type, Dictionary<string, Func<Args, object>>>();
public void Register<T>(Func<Args, T> factory, string name = "") where T : class
{
Type t = typeof(T);
@rofr
rofr / gist:9666089
Created March 20, 2014 15:16
Can't install chocolatey...
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Administrator>@powershell -NoProfile -ExecutionPolicy Unrestricted -Co
mand "iex ((New-Object Net.WebClient).DownloadString('https://chocolatey.org/in
tall.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2014-03-20 16:11 chocInstall
@rofr
rofr / gist:9682677
Last active August 29, 2015 13:57
First origodb scriptcs script
using OrigoDB.Core;
[Serializable]
public class MyModel : Model
{
Dictionary<string,object> _store =
new Dictionary<string,object>();
public void Put(string key, object value)
@rofr
rofr / gist:9683255
Created March 21, 2014 10:19
Output from first origodb scriptcs experiment
$ scriptcs start.csx -repl
scriptcs (ctrl-c to exit)
INFO: Loading preseeded script: start.csx
> db.Keys();
[
"hello"
]
> Enumerable.Range(1,100).ToList().ForEach(n => db.Put(n.ToString(),n*n));
> db.Keys();