Skip to content

Instantly share code, notes, and snippets.

View mvacha's full-sized avatar

Michal Vácha mvacha

View GitHub Profile
public static Task<SqlDataReader> ExecuteReaderAsync(this SqlCommand command)
{
return Task.Factory.FromAsync(command.BeginExecuteReader, command.EndExecuteReader, null);
}
public static Task<object> ExecuteScalarAsync(this SqlCommand command)
{
return command.ExecuteReaderAsync().ContinueWith((executeTask) =>
{
TaskCompletionSource<object> source = new TaskCompletionSource<object>();
@mvacha
mvacha / NumLock.txt
Created April 9, 2016 10:41
How to turn on NumLock in Windows 10 (on Intel NUC), definitive guide:
How to turn on NumLock in Windows 10(on Intel NUC), definitive guide:
1) Power options > Choose what the power buttons do > Uncheck "Turn on fast startup"
2) Registry key: HKEY_USERS/.Default/Control Panel/Keyboard/InitialKeyboardIndicators = 2147483650
3) Registry key: HKEY_CURRENT_USER/Control Panel/Keyboard/InitialKeyboardIndicators = 2
4) Intel UEFI BIOS: BootupNumLock State = On, FastBoot = On
<ScrollViewer HorizontalScrollMode="Enabled"
VerticalScrollMode="Enabled"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
IsHorizontalRailEnabled="True"
IsVerticalRailEnabled="True"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Grid>
<ScrollViewer HorizontalScrollMode="Enabled"
@mvacha
mvacha / page.cs
Last active April 15, 2016 09:54 — forked from igorkulman/page.cs
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
InputPane.GetForCurrentView().Showing += OnKeyboardShowing;
InputPane.GetForCurrentView().Hiding += OnKeyboardHiding;
}
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
public static async Task ChangeViewAsync(this ScrollViewer scrollViewer, double? horizontalOffset, double? verticalOffset, bool disableAnimation)
{
var tcs = new TaskCompletionSource<object>();
EventHandler<ScrollViewerViewChangedEventArgs> viewChanged = (s, e) => tcs.TrySetResult(null);
try
{
scrollViewer.ViewChanged += viewChanged;
scrollViewer.ChangeView(horizontalOffset, verticalOffset, null, disableAnimation);
await tcs.Task;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace WpfTest
static State Request(this State state, Transition transition) =>
(state, transition) match
(
case (State.Running, Transition.Suspend): State.Suspended
case (State.Suspended, Transition.Resume): State.Running
case (State.Suspended, Transition.Terminate): State.NotRunning
case (State.NotRunning, Transition.Activate): State.Running
case *: throw new InvalidOperationException()
);
Task.Factory.StartNew(async () =>
{
try
{
var res = await connectedTCS.Task;
if (res.IsFailure)
{
DeviceEvent.AuthenticationFailure(this);
connectedEvent.Set();
return;
public bool Start()
{
Gateway = new GatewayConnection(IPAddress, Port, UserName, Password, AppId);
var connectedEvent = new ManualResetEvent(false);
var cancel = new CancellationTokenSource();
var connectedSuccessfully = false;
var rootNode = default(SiteNode);
var connectedTCS = new TaskCompletionSource<Result>(cancel);
private async Task<Result<T>> Send<T>(string urlSuffix, Func<HttpContent, T> responseParser)
{
try
{
var answer = await SendInternal(urlSuffix);
if (answer.IsSuccessStatusCode)
{
return Result.Ok(responseParser(answer.Content));
}
else