Skip to content

Instantly share code, notes, and snippets.

View mvacha's full-sized avatar

Michal Vácha mvacha

View GitHub Profile
var result = await _connectedTCS.Task.FailOnCancel()
.OnSuccess(async () => await _userStatusTCS.Task.FailOnCancel())
.OnSuccess(async () => await _profileTCS.Task.FailOnCancel());
result.OnSuccess(() =>
{
Log.Info("Connecting to the Gateway successful");
connectedSuccessfully = true;
RootNode = _profileTCS.Task.Result.Value;
connectedEvent.Set();
try
{
var res = await _connectedTCS.Task;
if (res.Result)
{
var res2 = await _userStatusTCS.Task;
if (res2.Result)
{
var res3 = await _profileTCS.Task;
if (res3.Result)
@mvacha
mvacha / nbsp.cs
Created September 20, 2016 13:12
internal class Typografie
{
public Typografie()
{
}
public static void HledejMezery(string s, ref List<int> indexy)
{
indexy.Clear();
s = Typografie.SmazSpecialniJazyky(s);
public static T GetVisualChildByType<T>(this DependencyObject referenceVisual) where T : DependencyObject
{
DependencyObject child = null;
for (Int32 i = 0; i < VisualTreeHelper.GetChildrenCount(referenceVisual); i++)
{
child = VisualTreeHelper.GetChild(referenceVisual, i) as DependencyObject;
if (child != null && child is T)
{
break;
}
@mvacha
mvacha / bc.cs
Created September 27, 2016 15:00
using System;
using Gamanet.C4;
using Gamanet.C4.DriverFramework;
using Gamanet.C4.Logging;
using Gamanet.C4.DriverFramework.Communication;
using System.Collections.Generic;
using System.Linq;
namespace NetGlade.C4Driver.Devices
{
10:00-12:00 Športovský palác
14:00-17:00 Budova Elektrických podniků
14:00 Bydlení na Letné
16:00 Veletržní palác
18:00 Nová budova - Národní muzeum
using Newtonsoft.Json;
using PipeGuard.Data.Code;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace PipeGuard.Data.Services
{
public class ConfigService
@mvacha
mvacha / PeakDet.cs
Created July 17, 2017 02:00
C# implementation of PeakDet algorithm from: http://www.billauer.co.il/peakdet.html
public static IList<(int pos, double val)> PeakDet(this IList<double> vector, double triggerDelta)
{
double mn = Double.PositiveInfinity;
double mx = Double.NegativeInfinity;
int mnpos = 0;
int mxpos = 0;
bool lookformax = true;
var maxtab_tmp = new List<(int pos, double val)>();
//var mintab_tmp = new List<(int pos, double val)>();
@mvacha
mvacha / ThresholdingAlgo.cs
Created July 21, 2017 18:01
C# implementation of Thresholding algorithm used for peek (and through) detection from https://stackoverflow.com/questions/22583391/peak-signal-detection-in-realtime-timeseries-data/22771985
/// <summary>
/// Algo from: https://stackoverflow.com/questions/22583391/peak-signal-detection-in-realtime-timeseries-data/22771985
/// </summary>
public static (IList<double> avg, IList<double> sd, IList<int> detected)
ThresholdingAlgo(this IList<double> values, int windowSize, double threshold, double influence){
//number in constructor represent capacity, not size
var avg = new List<double>(values.Count);
var mad = new List<double>(values.Count);
var filteredValues = new List<double>(values.Count); //used for calculating avg and sd
static Compilation Compile(string code)
{
var parserOptions = new CSharpParseOptions(languageVersion: LanguageVersion.CSharp7);
var parsedTree = CSharpSyntaxTree.ParseText(code, options: parserOptions);
//Assert parser success
Debug.Assert(!parsedTree.GetRoot().HasErrors());
//Enable flow-analysis feature flag
var options = parsedTree.Options.WithFeatures(new[] { new KeyValuePair<string, string>("flow-analysis", "true") });