This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Huxley.MongoDb.Serialization { | |
class StringToObjectSerializer<T> : SerializerBase<T> { | |
private readonly Func<string, T> valueDeserializer; | |
private readonly Func<T, string> valueSerializer; | |
public StringToObjectSerializer(Func<string, T> valueDeserializer, Func<T, string> valueSerializer) { | |
this.valueDeserializer = valueDeserializer; | |
this.valueSerializer = valueSerializer; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClassSerializer : SerializerBase<Plate> { | |
public override MyClass Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) { | |
string value = context.Reader.ReadString(); | |
return new MyClass(value); | |
} | |
public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, MyClass obj) { | |
context.Writer.WriteString(obj.Value); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vagrant.configure("2") do |config| | |
config.vm.define "linux-sqlserver"do |linux| | |
linux.vm.box = "ubuntu/xenial64" | |
linux.vm.network "forwarded_port", guest: 1433, host: 1433 | |
linux.vm.provider "virtualbox" do |vb| | |
vb.name = "my-sqlserver" | |
vb.memory = 2048 | |
vb.cpus = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function process(tpl, params) { | |
return Object.keys(params).reduce(function(acc, curr) { return acc.replace("[" + curr + "]", params[curr]);}, tpl) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Specialized; | |
using System.Configuration; | |
public static class ConfigurationExtension { | |
public static string ReadSetting(this NameValueCollection self, string key) { | |
return self[$"{Environment.MachineName}.{key}"] ?? self[key]; | |
} | |
public static string ReadConnectionString(this ConnectionStringSettingsCollection self, string name) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace TestingSupport { | |
public class ConcurrentExecutor { | |
public int ThreadCount { get; set; } = 50; | |
public int RepetitionsCount { get; set; } = 200; | |
public bool RandomDelayBetweenExecutions { get; set; } = true; | |
private readonly Random random = new Random(); | |
public void Execute(Action action) { | |
Barrier startBarrier = new Barrier(ThreadCount); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function option(x) { | |
return { | |
map: function(f) { | |
return x ? option(f(x)) : option() | |
}, | |
valueOr: function(d) { | |
return x || d | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function range(first, last) { | |
const length = last - first + 1 | |
return new Array(length).fill(-1, 0, length).map(function(v, i) { return i + first; }) | |
} | |
function factZeros(n) { | |
return range(1, Math.floor(Math.log(n) / Math.log(5))).map(x => Math.pow(5, x)).map(x => Math.floor(n / x)).reduce((acc, curr) => acc + curr, 0) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let timerId = null | |
const delay = 2000 | |
function delayedHandler() { | |
console.log('Hello, World!') | |
} | |
function onEvent() { | |
if(timerId) { | |
clearTimeout(timerId) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Data; | |
using System.Data.SqlClient; | |
namespace Plastiline.Core.Utils.Sql { | |
public static class ConnectionStringExtension { | |
public static void Execute(this string connectionString, Action<IDbConnection> action) { | |
using (IDbConnection conn = new SqlConnection(connectionString)) { | |
conn.Open(); | |
action(conn); |
NewerOlder