Skip to content

Instantly share code, notes, and snippets.

// https://stackoverflow.com/a/3670089/1933104
public static bool ScrambledEquals<T>(this ICollection<T> self, ICollection<T> other)
{
if (self == null)
{
throw new ArgumentNullException(nameof(self));
}
if (other == null)
public class DateRange : IEquatable<DateRange>
{
public DateTime Start { get; }
public DateTime End { get; }
public double Days { get; }
public DateRange(DateTime start, DateTime end)
{
@kosorin
kosorin / ItemClickAction.cs
Created January 18, 2019 21:45
UWP behavior
public class ItemClickAction : DependencyObject, IAction
{
public ICommand Command
{
get { return (ICommand)GetValue(CommandProperty); }
set { SetValue(CommandProperty, value); }
}
public static readonly DependencyProperty CommandProperty =
DependencyProperty.Register(nameof(Command), typeof(ICommand), typeof(ItemClickAction), new PropertyMetadata(null));
@kosorin
kosorin / ObjectActivatorFactory.cs
Created February 22, 2019 16:38
Fast instance creation with compiled lambda expressions.
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
public static class ObjectActivatorFactory
{
public static Func<TObject> Create<TObject>()
{
return CreateAs<TObject>(typeof(TObject));
public static class TimeConstants
{
public const int MillisecondsPerSecond = 1000;
public const int MillisecondsPerMinute = MillisecondsPerSecond * SecondsPerMinute;
public const int MillisecondsPerHour = MillisecondsPerMinute * MinutesPerHour;
public const int MillisecondsPerDay = MillisecondsPerHour * HoursPerDay;
public const int MillisecondsPerWeek = MillisecondsPerDay * DaysPerWeek;
public const int SecondsPerMinute = 60;
public const int SecondsPerHour = SecondsPerMinute * MinutesPerHour;
@kosorin
kosorin / temnota-plus.user.js
Last active February 14, 2020 18:14
Temnota.cz UserScript
// ==UserScript==
// @name Temnota Plus
// @namespace http://temnota.cz
// @include http://temnota.cz/*
// @include http://www.temnota.cz/*
// @version 7.1.1
// @grant none
// @require https://code.jquery.com/jquery-3.2.1.min.js
// @require https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js
// ==/UserScript==
@kosorin
kosorin / serialzone-plus.user.js
Last active April 15, 2020 13:04
SerialZone.cz UserScript
// ==UserScript==
// @name SerialZone.cz PLUS
// @namespace https://www.serialzone.cz/
// @version 3.1.1
// @author David Kosorin
// @match https://www.serialzone.cz/*
// @grant none
// ==/UserScript==
try {
@kosorin
kosorin / TcpSocket.cs
Last active November 12, 2020 01:51
TCP socket wrapper with stream parser
public class TcpSocket : IDisposable
{
private readonly ProtocolProcessor _protocolProcessor = new ProtocolProcessor();
private readonly Socket _socket;
private readonly AutoResetEvent _connectEvent = new AutoResetEvent(false);
private readonly SocketAsyncEventArgs _receiveToken;
private readonly IObjectPool<SocketAsyncEventArgs> _sendTokenPool;
public TcpSocket(InternetEndPoint remoteEndPoint)
@kosorin
kosorin / CsfdExporter.csproj
Created February 27, 2021 00:22
ČSFD exporter (to IMDb format)
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.30" />
@kosorin
kosorin / Crc32.cs
Created March 17, 2021 11:26
CRC32
// https://github.com/force-net/Crc32.NET with Span<T> support
using System;
internal static class Crc32
{
public const uint CheckHash = 0x2144DF1Cu;
public const int HashLength = sizeof(uint);