Skip to content

Instantly share code, notes, and snippets.

using System;
using System.IO;
using System.Threading.Tasks;
using SkiaSharp;
public static class ImageHelper
{
private const double Rotate90 = 90d;
private const double Rotate180 = 180d;
@usausa
usausa / TaskExtensions.cs
Created October 12, 2020 23:49
Timeout for CancellationToken unsupported methods
public static class TaskExtensions
{
public static async Task<T> WithTimeout<T>(this Task<T> task, int timeout)
{
using var cts = new CancellationTokenSource();
var completedTask = await Task.WhenAny(task, Task.Delay(timeout, cts.Token)).ConfigureAwait(false);
cts.Cancel();
return completedTask == task ? task.Result : default;
}
}
@usausa
usausa / Reader.cs
Created October 7, 2020 12:38
XmlReaderExtensions
if (!reader.MoveToNextElement(0) || (reader.Name != "Root"))
{
return;
}
while (reader.MoveToNextElement(1))
{
if (reader.Name == "Group1")
{
while (reader.MoveToNextElement(2))
namespace ArrayAccessBenchmark50
{
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Jobs;
@usausa
usausa / MainPage.xaml
Last active September 27, 2020 11:01
Xamarin.Forms custom side menu
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="SideMenuTest.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<AbsoluteLayout>
<StackLayout
AbsoluteLayout.LayoutBounds="0,0,1,1"
AbsoluteLayout.LayoutFlags="All"
namespace OmronSensorTest
{
using System;
using System.Buffers.Binary;
using System.IO.Ports;
using System.Threading;
public static class Program
{
public static void Main(string[] args)
public struct WrapEnumerator<T> : IEnumerator<T>
{
private readonly IEnumerator<T> source;
private bool first;
public WrapEnumerator(IEnumerator<T> source)
{
this.source = source;
first = true;
using System;
using System.Linq.Expressions;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
INSERT INTO Data (Id, Name) VALUES
/*% for (var i = 0; i < list.Count; i++) { */
/*% if (i != 0) { */
/*! , */
/*% } */
/*% var entity = list[i]; */
(/*@ entity.Id */1, /*@ entity.Name */'test')
/*% } */
// <auto-generated />
namespace Example.ConsoleApplication.Accessor
{
using System;
using System.Linq;
using static Smart.Data.Accessor.Scripts.ScriptHelper;
public sealed class IExampleAccessor_Impl : global::Example.ConsoleApplication.Accessor.IExampleAccessor
{
private readonly global::Smart.Data.Accessor.Engine.ExecuteEngine _engine;