Skip to content

Instantly share code, notes, and snippets.

View mattjohnsonpint's full-sized avatar

Matt Johnson-Pint mattjohnsonpint

View GitHub Profile
@mattjohnsonpint
mattjohnsonpint / AsyncTest.cs
Created February 19, 2014 01:23
Test showing parallel async tasks
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Tests
{
[TestClass]
public class AsyncTest
@mattjohnsonpint
mattjohnsonpint / LinqLuceneTest.cs
Created February 22, 2014 01:41
Testing fluent mappings in linq to lucene
using System.Linq;
using Lucene.Net.Linq;
using Lucene.Net.Linq.Fluent;
using Lucene.Net.Store;
using Lucene.Net.Util;
using NUnit.Framework;
namespace LinqLuceneTest
{
public class Customer
@mattjohnsonpint
mattjohnsonpint / DateRangeTest.cs
Created February 24, 2014 00:28
Testing half-open interval date range
using System;
using System.Linq;
using Raven.Tests.Helpers;
using Xunit;
namespace RavenTests
{
public class DateRangeTest : RavenTestBase
{
public class Foo
@mattjohnsonpint
mattjohnsonpint / Q22795924.cs
Created April 2, 2014 04:53
Answer for SO Q22795924
int days = 678;
// First, you need a starting point
Instant now = SystemClock.Instance.Now;
DateTimeZone timeZone = DateTimeZoneProviders.Bcl.GetSystemDefault(); // or whatever the applicable time zone is
LocalDate today = now.InZone(timeZone).Date;
// then just add the number of days
LocalDate future = today.PlusDays(days);
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
This shows how you can calculate the elapsed time in MSBuild
-->
<Target Name="BeforeBuild">
<PropertyGroup>
<startTime>$([System.DateTime]::UtcNow)</startTime>
using System;
using System.Globalization;
using System.Threading;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
@mattjohnsonpint
mattjohnsonpint / Test.cs
Created July 4, 2015 00:30
xUnit / Json issue
using Newtonsoft.Json;
using Xunit;
using Xunit.Abstractions;
namespace XUnitJsonTest
{
public class Class1
{
private readonly ITestOutputHelper _output;
@mattjohnsonpint
mattjohnsonpint / 1-code.cs
Last active August 29, 2015 14:24
Testing MySql
using System;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
namespace TestMySql
{
class Program
{
static void Main(string[] args)
{
var builder = new ContainerBuilder();
builder.RegisterInstance(store)
.As<IDocumentStore>()
.SingleInstance();
builder.Register(ctx => ctx.Resolve<IDocumentStore>().OpenSession())
.As<IDocumentSession>()
.InstancePerLifetimeScope();
@mattjohnsonpint
mattjohnsonpint / moment-timezone-detection.js
Last active October 5, 2015 16:02
WIP for guessing the current time zone using moment.js & moment-timezone
function guessTimeZone() {
// First try ECMA-402 time zone detection, unless true is passed for testing the rest of this function.
if (!arguments[0] && typeof Intl === "object" && typeof Intl.DateTimeFormat === "function") {
var tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
if (tz === "UTC") return "Etc/UTC";
if (tz && tz.indexOf('/') > -1) return tz;
}
// get the current timestamp - used throughout