Skip to content

Instantly share code, notes, and snippets.

View gamlerhart's full-sized avatar

Roman Stoffel gamlerhart

View GitHub Profile
public event Action<string> OperationFinishedNotification;
public string AwesomeBusinessOperation()
{
var firstPart = TakesALongTimeToProcess("Tons");
var secondPart = TakesALongTimeToProcess(firstPart + " of ");
var result = TakesALongTimeToProcess(secondPart + "money");
var eventToFire = OperationFinishedNotification;
if(null!=eventToFire)
@gamlerhart
gamlerhart / ComplexBusinessOperations-1.cs
Created November 8, 2010 20:49
Unit Testing, Part II, Synchronisation Issues
public class ComplexBusinessOperations
{
private int moneyEarnedSoFar;
public int MoneyEarnedSoFar
{
get { return moneyEarnedSoFar; }
}
public void EarnMoney(int investment)
@gamlerhart
gamlerhart / Awaiter.cs
Created November 11, 2010 19:50
ComplexBusinessOperations-1.cs
public class Awaiter
{
private readonly MyPrimitiveSynchronisationContext syncContext;
internal Awaiter(MyPrimitiveSynchronisationContext syncContext)
{
this.syncContext = syncContext;
}
public void WaitFor(IAsyncResult toWaitOn)
@gamlerhart
gamlerhart / CannotPassAsMethod.java
Created November 24, 2010 18:25
OhNo.its.JDO.java
// Just works
List<String> listOfString = cast(list);
// Doesn't work
printAll(cast(list));
@gamlerhart
gamlerhart / CollectionUtils.java
Created December 2, 2010 21:26
old-school-collections.java
public class CollectionUtils {
private CollectionUtils(){
}
public static <T> List<T> list(){
return new ArrayList<T>();
}
public static <T> List<T> list(T...elements){
return new ArrayList<T>(asList(elements));
@gamlerhart
gamlerhart / FocusSwitcher.cs
Created February 14, 2011 21:57
A global mutex across the machine
public class FocusSwitcher
{
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(HandleRef hWnd, int nCmdShow);
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
private const int SW_MAXIMIZE = 3;
public static void SwitchToCurrent()
{
<transparent-activation-step>
<regexp pattern="^com\.mycompany\.persistence\.data" /> <!-- Hier anpassen? -->
<!-- <regexp pattern="^enhancement\.model\." /> -->
</transparent-activation-step>
namespace NDependExperiments
{
public class DataBaseOperation
{
public void Store(object obj) {/** Do stuff **/}
}
class BusinessOperations
{
private readonly DataBaseOperation dbConnection = new DataBaseOperation();
using (var db = Db4oEmbedded.OpenFile("databaseWithArrayFields.db4o"))
{
var metaData = db.Ext().KnownClasses();
// process the data
foreach (var aClass in metaData)
{
// analyse the class
var fields = aClass.GetDeclaredFields();
foreach (var aField in fields)
{
@gamlerhart
gamlerhart / CompositeComparator.java
Created April 4, 2011 15:07
CompositeComparator.java
public final class CompositeComparator<T> implements Comparator<T>{
private final List<Comparator<? super T>> comparators;
CompositeComparator(List<Comparator<? super T>> comparators) {
this.comparators = comparators;
}
public static <TCompare> Comparator<TCompare> compareWith(Comparator<? super TCompare>... comparators){
return new CompositeComparator<TCompare>(Arrays.asList(comparators));
}