Skip to content

Instantly share code, notes, and snippets.

View lostmsu's full-sized avatar
💭
–2147483648x developer

Victor lostmsu

💭
–2147483648x developer
View GitHub Profile
@lostmsu
lostmsu / IAsyncSaveService.cs
Created October 1, 2016 23:31
The problem interface for the Responsive Autosave Problem (lookup the post on blogger)
// Instances of this class are not thread-safe
// E.g. only one thread can safely call Save and DisposeAsync
//
interface IAsyncSaveService {
// this function schedules save operation to be performed
// implementers of this interface must ensure, that only one save operation can run at the same time
// saveOperation is considered completed when the task it returned is completed
void Save(Func<Task> saveOperation);
// after a call to this function no calls to Save are allowed and must throw ObjectDisposedException
// this function can be called any number of times
@lostmsu
lostmsu / DynDns.csx
Created December 23, 2016 08:06
Simple dynamic DNS client for namecheap. Looks for files in \ProgramData\DynDns in form of <yourdomain>.namecheap, containing dyndns password. Can be used with csi (C# script) and Task Scheduler
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Security.AccessControl;
IPAddress GetMyExternalIpAddress() {
var dnsQuery = new ProcessStartInfo("nslookup", "myip.opendns.com. resolver1.opendns.com")
{
@lostmsu
lostmsu / LifeSpan.cs
Last active April 10, 2024 06:54
Control LifeSpan treadmill from C# (treadmill drops connection if not kept alive)
// License: MIT
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
public class LifeSpanTreadmill: IDisposable
{
namespace FormattingTest
{
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Formatting;
@lostmsu
lostmsu / MyTree.cs
Created October 22, 2019 20:02
How to register converter for a generic type?
using Python.Runtime;
class MyNonGenericTree
{
}
PyTypeConversion<MyNonGenericTree>.Converter = tree => ...;
class MyTree<T>
{
@lostmsu
lostmsu / Static_vs_InlineReadonly.cs
Created May 12, 2020 20:16
Comparing static readonly bool field to static property, set to a value computable at compile time
namespace Inline_vs_Static_Readonly
{
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
[SimpleJob(RuntimeMoniker.Net48)]
[SimpleJob(RuntimeMoniker.Mono)]
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
public class InlineOrStaticReadonly
class List:
def add(self, item): ...
class ListMixin:
def append(self, item): return self.add(item)
def mix_in(target_type, mixin):
???
mix_in(List, ListMixin)
>>> class MyList(list):
... def __getitem__(self, idx):
... print('hello')
... return super().__getitem__(idx)
...
>>> l = MyList()
>>> l.append(42)
>>> l[0]
hello
42
<zones:Zone.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, ElementName=StackLeftSide}" Value="True">
<Setter Property="zones:Zone.Layout">
<Setter.Value>
<ItemsPanelTemplate>
<UniformGrid Columns="1" />
</ItemsPanelTemplate>
</Setter.Value>
<zones:Zone.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, ElementName=StackLeftSide}" Value="True">
<Setter Property="zones:Zone.Layout">
<Setter.Value>
<ItemsPanelTemplate>
<UniformGrid Columns="1" />
</ItemsPanelTemplate>
</Setter.Value>