Skip to content

Instantly share code, notes, and snippets.

View gamlerhart's full-sized avatar

Roman Stoffel gamlerhart

View GitHub Profile
public static class RelationManagementExtensions
{
[ThreadStatic]
private static bool inAddToParentCall;
[ThreadStatic]
private static readonly ICollection<Tuple<object,object>> InChildAction = new HashSet<Tuple<object, object>>();
public static TParent AddToParent<TChild, TParent>(this TParent parent, TChild child, Func<Action<TChild>> addToParentAction) where TParent:class
{
try
.gist .gist-file .gist-data .gist-highlight pre{
font-family: "Consolas", "Courier New", Courier, "Bitstream Vera Sans Mono", monospace;
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Db4objects.Db4o;
using Db4objects.Db4o.Config;
namespace Gamlor.Db4oForum
{
class RunBenchmark
public class Program
{
private static void Main(string[] args)
{
File.Delete("tmp.db4o");
using (var db = OpenDB())
{
var usr = new User();
db.Store(usr);
// ==UserScript==
// @name YoutubeProtectionRemover
// @include http://www.youtube.com/*
// @description Removes lame protection on YouTube
// @copyright 2010, Snap
// ==/UserScript==
window.opera.addEventListener(
'BeforeScript',
function (ev){
Action workItem = () =>
{
throw new ExpectedExeption();
};
var syncHandle = workItem.BeginInvoke(null, null);
// later
try
{
workItem.EndInvoke(syncHandle);
}catch (ExpectedExeption e)
// Even a cast generates a warning
List<MyClass> data = (List<MyClass>) legacyLibraryCall();
public class BootsTrapper {
private final static String APPLICATION_PATH = "./application";
private final static String APPLICATION_MAIN = "info.gamlor.application.ApplicationMain";
public static void main(String[] args) {
final File file = new File(APPLICATION_PATH);
try {
tryStartUp(file,args);
} catch (Exception e) {
System.err.println("Unexpected exception'" + file + "'.");
class MyPrimitiveSynchronisationContext : SynchronizationContext
{
private readonly Queue<Action> messagesToProcess = new Queue<Action>();
private readonly object syncHandle = new object();
private bool isRunning = true;
public override void Send(SendOrPostCallback codeToRun, object state)
{
throw new NotImplementedException();
}
@gamlerhart
gamlerhart / MyBusinessLogic-1.cs
Created November 3, 2010 19:52
async&unit-test: Simple Result
public string AwesomeBusinessOperation()
{
var firstPart = TakesALongTimeToProcess("Tons");
var secondPart = TakesALongTimeToProcess(firstPart+" of ");
var result = TakesALongTimeToProcess(secondPart+"money");
return result;
}
private string TakesALongTimeToProcess(string word)
{