Skip to content

Instantly share code, notes, and snippets.

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

Victor lostmsu

💭
–2147483648x developer
View GitHub Profile
using System;
Func<int, int, int> addImpl = (a, b) => a + b;
var add = Infix.Create(addImpl);
Console.WriteLine(41 |add| 1);
public class Infix<T1, T2, TResult> {
public Func<T1, T2, TResult> Op;
public static Infix<T2, TResult> operator |
@lostmsu
lostmsu / IM Layout.xaml
Created January 24, 2022 18:48
Sample screen layout with zones directly capturing certain windows
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:filters="clr-namespace:LostTech.Stack.Extensibility.Filters;assembly=LostTech.Stack.Extensibility"
xmlns:stack="https://schemas.losttech.software/stack/2022/xaml/all"
stack:Layout.Version="2"
>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
@lostmsu
lostmsu / SerializeEquality.cs
Created November 24, 2021 03:13
BinaryFormatter serializes two distinct objects as one
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
unsafe {
IntPtr resource1 = Marshal.AllocHGlobal(sizeof(FakeUnmanagedRefcountedObject));
*(FakeUnmanagedRefcountedObject*)resource1 = default; // zero memory
var i1 = new UnmanagedRefcountWrapper(resource1);
i1.Value = 10;
@lostmsu
lostmsu / ILGPU.Segfault.cs
Created September 9, 2021 17:19
ILGPU crashes when trying to run a specialized kernel
// <PackageReference Include="ILGPU" Version="1.0.0-beta3" />
// <PackageReference Include="TypeNum" Version="0.2.0-CI-20210909-064812" />
using System.Runtime.InteropServices;
using ILGPU;
using ILGPU.Runtime;
using ILGPU.Runtime.CPU;
using TypeNum;
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:zones="clr-namespace:LostTech.Stack.Zones;assembly=Stack"
xmlns:system="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
zones:Layout.Version="2"
Width="1024" Height="576"
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:zones="clr-namespace:LostTech.Stack.Zones;assembly=Stack"
mc:Ignorable="d"
Width="1024" Height="576"
d:DesignWidth="1024"
d:DesignHeight="576"
<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>
>>> class MyList(list):
... def __getitem__(self, idx):
... print('hello')
... return super().__getitem__(idx)
...
>>> l = MyList()
>>> l.append(42)
>>> l[0]
hello
42
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)