Skip to content

Instantly share code, notes, and snippets.

@dlidstrom
dlidstrom / Teachers.cs
Last active October 25, 2018 12:08
Plan teachers week schedule
namespace Csp
{
using System;
using System.Collections.Generic;
using System.Linq;
using Decider.Csp.BaseTypes;
using Decider.Csp.Global;
using Decider.Csp.Integer;
public static class Program
@dlidstrom
dlidstrom / commandBuffer-es6.js
Last active January 16, 2017 08:03
Command buffer service for AngularJS used to manage asynchronous calls in a synchronized fashion.
/**
* This service is used to serialize asynchronous events.
* It uses a buffering solution: http://ricostacruz.com/backbone-patterns/animation-buffer.html
* To use it, put your asynchronous actions (animations/ajax) inside an anonymous function
* to be passed into add().
* Be sure to trigger next() when done.
*
* Example:
* commandBuffer.add(next => {
* somePromise.done(next);

Logging & Meta Tests

Logging

Define the operations being done by the application as discrete units of work. Examples: commands, queries, startup, shutdown. Define explicit boundaries between units of work. This makes it easy to log the operations of the application.

  • Log startup scenario together with settings. I.e. read all settings at application startup, and only there.
  • Log commands and queries. For commands, log command type and eventual return value. For queries, log the query type and the query result.
  • Define a logging gateway with convenience methods for logging application events. Define a class that represents an application event and define all known application events in a single, static and application-specific, class. Application events are lower-level than business events. For example: ExecutingCommand, CommandResult, Starting, Started, ShuttingDown, BeginRequest, EndRequest.
  • Application events should have their own event id.
  • Build infrastructure layer that takes care of applicat
// Preferences.sublime-settings
// Settings in here override those in "Default/Preferences.sublime-settings", and
// are overridden in turn by file type specific settings.
{
    "draw_white_space": "all",
    "translate_tabs_to_spaces": true,
    "trim_trailing_white_space_on_save": true
}
using (var md5 = System.Security.Cryptography.MD5.Create())
{
var hash = md5.ComputeHash(Encoding.ASCII.GetBytes("dlidstrom@gmail.com"));
var sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("x2"));
}
@dlidstrom
dlidstrom / watch.ps1
Created June 15, 2016 10:12
watch a file changes in the current directory
# watch a file changes in the current directory,
# execute some command when a file is changed or renamed
param($BatFile)
if (($BatFile -eq $null) -or (-not (Test-Path -Path $Batfile)))
{
"Specify bat file to run continuously."
exit
}
public abstract class JobBase : IInterruptableJob
{
protected JobBase()
{
Log = LogManager.GetLogger(GetType());
}
public IKernel Kernel { get; set; }
protected ILog Log { get; private set; }
public abstract class JobStartable : IStartable
{
private static readonly ILog Log = LogManager.GetLogger(typeof(JobStartable));
private readonly IScheduler scheduler;
protected JobStartable(IScheduler scheduler)
{
this.scheduler = scheduler;
}
public class JobInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(
Classes.FromThisAssembly()
.BasedOn<IJob>()
.WithServiceAllInterfaces()
.Configure(x => x.Named(x.Implementation.ToString()))
.LifestylePerThread());
public class BackgroundTasksQueueProcessor : MessageQueueProcessorBase
{
private static readonly JsonSerializerSettings SerializerSettings
= new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All };
private readonly IKernel kernel;
public BackgroundTasksQueueProcessor(
IKernel kernel,
string importQueue,