Skip to content

Instantly share code, notes, and snippets.

@andrevdm
andrevdm / Agent.cs
Last active September 28, 2015 05:38
Simple C# clojure like agent. Supports async/await and returning values from the wrapped data structure
//Serialised, asynchronous access to data structures
public class Agent<T>
{
private readonly T m_data;
private readonly BlockingCollection<Action<T>> m_actions = new BlockingCollection<Action<T>>( new ConcurrentQueue<Action<T>>() );
public Agent( T data )
{
if( data == null )
@andrevdm
andrevdm / LoggingExample.cs
Created August 22, 2012 18:20
Q&D MongoDB logging
using System;
using System.Diagnostics;
using MongoDB.Driver;
namespace MongoDbLogging
{
class Program
{
private static bool g_logCalls;
@andrevdm
andrevdm / updateProjectFileVersion.cs
Last active December 17, 2015 18:48
C# pre-build script to update a AssemblyFileVersion with each build.
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
//From http://trycatch.me/automatically-update-the-assemblyfileversion-attribute-of-a-net-assembly/ but starting powershell for each build was too slow.
//Pass the C# project path as the only parameter
public class Updater
{
public static void Main( string[] args )
@andrevdm
andrevdm / makeMonoProjectsAndSln.cs
Last active December 17, 2015 18:48
Automatically create mono compatible solution and project files from existing windows ones
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
// Convert a C# windows soltion so that it can easily be built on mono. I've found this easier than trying to get a single solution working on both
// This script will
// 1) Create a .mono.sln from the sln
// 1.1) Change the file version from 12 to 11 for MonoDevelop
// 1.2) Change all project includes from .csproj to .mono.csproj
@andrevdm
andrevdm / NuGet.mono.targets
Created May 28, 2013 06:23
Mono compatible NuGet.targets
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
<!-- Enable the restore command to run before builds -->
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>
<!-- Property that enables building a package from a project -->
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
@andrevdm
andrevdm / mongoEg.cs
Last active January 2, 2016 01:59
MongoDB C# journal write test
public class Data
{
public ObjectId Id { get; set; }
public string Value { get; set; }
}
static void Main( string[] args )
{
var client = new MongoClient( "mongodb://localhost:27017" );
var server = client.GetServer();
@andrevdm
andrevdm / rigolCsv.fsx
Last active August 29, 2015 14:13
F# "logic" parser for rigol oscilloscope CSV files, outputs hex values
open System
open System.IO
open System.Text
open System.Globalization
open System.Text.RegularExpressions
let ttlTrue = 2.3
let getLines (fname:string) = seq{
use stream = new StreamReader( fname )
@andrevdm
andrevdm / rigolCsvAdc.fsx
Last active June 2, 2016 23:13
F# "logic" parser for rigol oscilloscope CSV files, outputs hex values. Interprets analogue data as 3 state (i.e. two data "lines" on a single channel)
open System
open System.IO
open System.Text
open System.Globalization
open System.Text.RegularExpressions
let l1 = 1.0
let l2 = 2.0
let ttlTrue = 2.3
@andrevdm
andrevdm / init.el
Created April 14, 2015 07:55
init.el
;;package sources
(load "package")
(package-initialize)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(add-to-list 'package-archives
'("gnu" . "http://elpa.gnu.org/packages/") t)
(add-to-list 'package-archives
open System
type PersonAge = PersonAge of int
type Person = { id: Guid; name: string; age: PersonAge}
let bjorn = { id=System.Guid.NewGuid(); name="Bjørn Einar"; age=PersonAge 34}
let changedName = {bjorn with name ="Bjørn the confused"}
let createAge age =