Skip to content

Instantly share code, notes, and snippets.

@dlidstrom
dlidstrom / boot.js
Last active August 29, 2015 14:16
run-jasmine.js for Jasmine 2.2. Run using phantomjs.exe run-jasmine.js SpecRunner.html
/**
Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js` and `jasmine_html.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.
If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms.
The location of `boot.js` can be specified and/or overridden in `jasmine.yml`.
[jasmine-gem]: http://github.com/pivotal/jasmine-gem
*/
@dlidstrom
dlidstrom / IndexTests.cs
Created March 30, 2015 10:44
Indexer with tests
public class Indexer
{
private readonly Dictionary<string, List<string>> terms =
new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<string, List<string>> docsTerms =
new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
public void Index(string docId, string text)
{
List<string> docTerms;
@dlidstrom
dlidstrom / NTimes.cs
Created April 1, 2015 14:57
Output number of words occurring exactly n times
public class Program
{
static void Main()
{
var words = File.ReadAllText(@"C:\Programming\words.txt")
.Split(' ', '\r', '\n')
.Select(x => x.Trim())
.Where(x => !string.IsNullOrEmpty(x))
.ToArray();
var candidates = new Dictionary<string, int>();
@dlidstrom
dlidstrom / Program.cs
Created June 8, 2015 15:02
Complete example on how to retrieve search highlightings using RavenDB
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Raven.Abstractions.Data;
using Raven.Abstractions.Indexing;
using Raven.Client;
using Raven.Client.Embedded;
using Raven.Client.Indexes;
@dlidstrom
dlidstrom / isPrime.js
Created September 16, 2015 10:05
Primality checking using regular expression.
// http://rosettacode.org/wiki/Primality_by_trial_division#By_Regular_Expression
function isPrime(n) {
var e = /^1?$|^(11+?)\1+$/;
return !e.exec('1'.repeat(n));
}
@dlidstrom
dlidstrom / Bowling.md
Last active September 23, 2015 10:23

“Straighter is greater” — Walter Ray Williams, legendar

“Älska att vinna; få aldrig nog av att göra strike. Alla kan göra strike men vinnaren gör även spärr. Spärra så får du chansen att vinna.” — Lidas, Fredrikshof IF

@dlidstrom
dlidstrom / Specification.markdown
Created January 13, 2011 15:20
Specification

First of all, here’s something you can do with the Specification class to reduce some of the code you have to write. Add the following methods:

public AndSpecification<TEntity> And(Expression<Func<TEntity, bool>> second)
{
    return new AndSpecification<TEntity>(this, new Specification<TEntity>(second));
}

public OrSpecification<TEntity> Or(Expression<Func<TEntity, bool>> second)
{

return new OrSpecification(this, new Specification(second));

@dlidstrom
dlidstrom / Specification.cs
Created January 15, 2011 11:00
Specification design pattern
using System;
using System.Linq;
using System.Linq.Expressions;
using Infrastructure.Data.Extensions;
namespace Infrastructure.Data.Specification
{
public class Specification<TEntity> : ISpecification<TEntity>
{
public Specification(Expression<Func<TEntity, bool>> predicate)
@dlidstrom
dlidstrom / NLog.config
Created January 19, 2011 12:57
How to configure Castle Windsor with logging.
<?xml version="1.0" encoding="utf-8" ?>
<!--
This file needs to be put in the application directory. Make sure to set
'Copy to Output Directory' option in Visual Studio.
-->
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target xsi:type="Console" name="console" layout="${message}" />
<target xsi:type="ColoredConsole" name="console-detailed" layout="${longdate} ${logger} ${level:upperCase=true}: ${message}${newline}(${stacktrace}) ${exception:format=ToString}" />

GridBook, Large Scale Othello

Introduction

This is a project where I am intending to do a large-scale distributed calculation of an opening book for the board game Othello. Positions are stored in a relational database (I have chosen PostgreSQL) using NHibernate object/relational mapper.

The project is still in its infancy, but the goal is to use Edax, a very good Othello engine, to calculate new positions. I am also intending to use a service bus, probably