Skip to content

Instantly share code, notes, and snippets.

View mastoj's full-sized avatar

Tomas Jansson mastoj

View GitHub Profile
@mastoj
mastoj / Deserialized types to json
Created June 12, 2014 17:05
Deserialized types to json
{
"commands": [
"Folkeregister.Contracts.Commands.CreatePerson",
"Folkeregister.Contracts.Commands.AddAdressToPerson"
],
"types": [
{
"$type": "Folkeregister.Web.TypeDeserialization.ObjectModel, Folkeregister.Web",
"type": "Folkeregister.Contracts.Commands.CreatePerson",
"name": "CreatePerson",
#r "../packages/FsPickler.Json.0.9.6/lib/net45/FsPickler.Json.dll"
#r "../packages/FsPickler.0.9.6/lib/net45/FsPickler.dll"
#r "../packages/Newtonsoft.Json.6.0.3/lib/net45/Newtonsoft.Json.dll"
open Nessos.FsPickler
open Nessos.FsPickler.Json
open Nessos.FsPickler.Combinators
open System.IO
let res y =
let jsp = FsPickler.CreateJson()
@mastoj
mastoj / StartEs
Created September 9, 2014 11:49
Sample to start Elasticsearch that fails
java -classpath ".\*;.\sigar\*;" -Delasticsearch -Des-foreground=yes -Des.path.home=".." -Des.path.data="c:\tmp\elas\data" -Des.http.port=9201 org.elasticsearch.bootstrap.Bootstrap
@mastoj
mastoj / chocolateyInstall.ps1
Created October 20, 2014 18:08
Chocolatey install script for SQL Server 2012
$setupExe = "c:/files/SQLEXPRWT_x64_ENU.exe"
$adminsGroupName = (New-Object Security.Principal.SecurityIdentifier 'S-1-5-32-544').Translate([Security.Principal.NTAccount]).Value
Install-ChocolateyPackage 'SqlServer2012Express' 'exe' "/Q /INDICATEPROGRESS /ACTION=Install /FEATURES=SQL,Tools /TCPENABLED=1 /INSTANCENAME=SQLEXPRESS /SQLSVCACCOUNT=`"NT AUTHORITY\Network Service`" /SQLSYSADMINACCOUNTS=`"$adminsGroupName`" /AGTSVCACCOUNT=`"NT AUTHORITY\Network Service`" /IACCEPTSQLSERVERLICENSETERMS " $setupExe -validExitcodes @(0,3010)
#The exe referenced is the official for SQL Express 2012, http://download.microsoft.com/download/8/D/D/8DD7BDBA-CEF7-4D8E-8C16-D9F69527F909/ENU/x64/SQLEXPRWT_x64_ENU.exe
@mastoj
mastoj / luke1.fsx
Last active August 29, 2015 14:10
Kalender 2014
open System
let toDecStr = sprintf "%i"
let toOctStr = sprintf "%o"
let revStr (x:string) = String(x.ToCharArray() |> Array.rev)
let isPalindrom x = x = (revStr x)
let numPalCheck conv x = x |> conv |> isPalindrom
let decCheck = numPalCheck toDecStr
let octCheck = numPalCheck toOctStr
let checker x = (octCheck x) && (decCheck x)
let result = [1..1000000] |> Seq.filter checker |> Seq.length
@mastoj
mastoj / Diamond.fs
Created February 9, 2015 20:23
F# Diamond
open System
type CharSpec = {Char:char; SndOffset: int}
type DiamondSpec = CharSpec list
let printDiamondRow charSpec =
match charSpec with
| {Char = x; SndOffset = 0} -> sprintf "%c" x
| {Char = x; SndOffset = y} -> sprintf "%c%s%c" x (String(' ', (y-1))) x
let padRow size (row:string) =
@mastoj
mastoj / lottery.fsx
Created March 23, 2015 18:15
F# Draw for meetup on meetups.com
#r "./FSharp.Data.2.2.0/lib/net40/FSharp.Data.dll"
open FSharp.Data
open System
let rnd = Random()
// Implemented Jimmy Bogard's https://github.com/jbogard/presentations/tree/master/WickedDomainModels/After in F#
namespace FSharp.Wicked
open System
module Types =
type Id = Id of Guid
type Entity<'T> = Id * 'T
let createEntity state = Guid.NewGuid(), state
@mastoj
mastoj / Person.cs
Last active August 29, 2015 14:21
Helps clearify things for this blog post: http://blog.bjartwolf.com/?p=4522
public class Person
{
private readonly PersonState _state;
public Person(string name)
{
_state = new PersonState(name);
}
public string GetName()
@mastoj
mastoj / money.cs
Created June 11, 2015 11:39
Simple implementation of money for C#
namespace Money
{
public class Money<TCurrency> where TCurrency : ICurrency
{
private readonly decimal _value;
public Money(decimal value)
{
_value = value;
}