Skip to content

Instantly share code, notes, and snippets.

View yevhen's full-sized avatar
🇺🇦

Yevhen Bobrov yevhen

🇺🇦
View GitHub Profile
@yevhen
yevhen / asyncio_loop_in_thread.py
Created November 23, 2023 19:33 — forked from dmfigol/asyncio_loop_in_thread.py
Python asyncio event loop in a separate thread
"""
This gist shows how to run asyncio loop in a separate thread.
It could be useful if you want to mix sync and async code together.
Python 3.7+
"""
import asyncio
from datetime import datetime
from threading import Thread
from typing import Tuple, List, Iterable
@yevhen
yevhen / 00 Dealing elements.md
Created September 11, 2021 10:28 — forked from ericnormand/00 Dealing elements.md
440 PurelyFunctional.tv Newsletter

Dealing elements

There's a function in clojure.core called partition-all. It creates subsequences of a given maximum size.

(partition-all 3 [1 2 3 4 5 6 7 8]);=> [[1 2 3] [4 5 6] [7 8]]

Notice that the first sequence gets the first three elements, the second sequence gets the second three elements, etc. We could get the original sequence again by concatenating the sequences back together.

@yevhen
yevhen / MakePowerShellRememberSSHPassphrase.md
Created July 5, 2021 16:45 — forked from danieldogeanu/MakePowerShellRememberSSHPassphrase.md
How to make Powershell remember the SSH key passphrase.

You should not use the Open SSH client that comes with Git for Windows. Instead, Windows 10 has its own implementation of Open SSH that is integrated with the system. To achieve this:

  1. Start the ssh-agent from Windows Services:
  • Type Services in the Start Menu or Win+R and then type services.msc to launch the Services window;
  • Find the OpenSSH Authentication Agent in the list and double click on it;
  • In the OpenSSH Authentication Agent Properties window that appears, choose Automatic from the Startup type: dropdown and click Start from Service status:. Make sure it now says Service status: Running.
  1. Configure Git to use the Windows 10 implementation of OpenSSH by issuing the following command in Powershell:
git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe
@yevhen
yevhen / capslock_remap_alt.ahk
Created May 28, 2021 21:04 — forked from Danik/capslock_remap_alt.ahk
Autohotkey Capslock Remapping Script. Makes Capslock function as a modifier key to get cursor keys etc. on the left side of the keyboard, so you never have to move your hand to the right.
; Autohotkey Capslock Remapping Script
; Danik
; More info at http://danikgames.com/blog/?p=714
; danikgames.com
;
; Functionality:
; - Deactivates capslock for normal (accidental) use.
; - Hold Capslock and drag anywhere in a window to move it (not just the title bar).
; - Access the following functions when pressing Capslock:
; Cursor keys - J, K, L, I
@yevhen
yevhen / A_README.md
Created July 27, 2018 15:07 — forked from gmamaladze/A_README.md
HashSet that preserves insertion order or .NET implementation of LinkedHashSet

HashSet that preserves insertion order or .NET implementation of LinkedHashSet

Many people naively assume an ordinary .NET HashSet preserves insertion order. Indeed HashSet accidentally preserves insertion order until you remove and re-add some elements. There is such a data structure in Java - LinkedHashSet which respects order and has O(1) RW times.

No, I did not find a (working) corresponding implementation in .NET. That's I wrote this one.

The implementation uses linked list in combination with dictionary to define the iteration, ordering and at the same time allow O(1) removal.

The order is not affected if an element is re-inserted into the set it retains it's old position.

@yevhen
yevhen / ComplexTypeConvention.cs
Created March 30, 2018 12:16 — forked from tugberkugurlu/ComplexTypeConvention.cs
Bind complex type objects from body by default on ASP.NET Core 1
using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.AspNet.Mvc.ModelBinding;
using System;
namespace Foo.Web.Infrastructure.Conventions
{
public class ComplexTypeConvention : IActionModelConvention
{
public void Apply(ActionModel action)
{
@yevhen
yevhen / ComplexTypeConvention.cs
Created March 30, 2018 12:16 — forked from tugberkugurlu/ComplexTypeConvention.cs
Bind complex type objects from body by default on ASP.NET Core 1
using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.AspNet.Mvc.ModelBinding;
using System;
namespace Foo.Web.Infrastructure.Conventions
{
public class ComplexTypeConvention : IActionModelConvention
{
public void Apply(ActionModel action)
{
readonly HttpClient http = new HttpClient();
async Task<DownloadResult[]> DownloadUrlsAsync(string path) =>
await Task.WhenAll(File.ReadLines(path).Select(DownloadAsync));
async Task<DownloadResult> DownloadAsync(string url)
{
var time = Stopwatch.StartNew();
try
@yevhen
yevhen / StackTraceLoss.cs
Created October 3, 2017 16:48
Code in question - Stack trace is lost
// https://stackoverflow.com/questions/46467275/weird-stack-trace-growth-with-async-await-and-taskcompletionsource
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
using System.Threading.Tasks;
@yevhen
yevhen / DurableTask.cs
Created August 13, 2017 13:50
Example of hierarchical FSM using Orleankka "behaviors"
/*
This represents simple durable task which do some work in background.
The task is automatically saved after every successful transition.
It is modeled as workflow with the following transitions:
1. Initial -> Start -> Started
Accept user request and start preparation
2. Started -> Prepared -> Running
On activation of Started it schedules a one-off timer to delay actual execution of Prepare
to finish previous user request and return control to the caller (Orleans is RPC, so it's the hack)
3. Running -> Executed -> Running