Skip to content

Instantly share code, notes, and snippets.

View ttrider's full-sized avatar

Vladimir Yangurskiy (AKA TTRider) ttrider

View GitHub Profile
@ttrider
ttrider / extensions.cs
Created November 15, 2016 21:44
Thread-safe wrapper over IMemoryCache
public static class Extensions
{
static readonly ConcurrentDictionary<string, object> TaskDictionary = new ConcurrentDictionary<string, object>();
public static async Task<T> GetOrAdd<T>(this IMemoryCache cache, string key, Func<string, Task<T>> factoryMethod)
{
object result;
if (!cache.TryGetValue(key, out result))
{
var asyncLazy = (AsyncLazy<T>)TaskDictionary.GetOrAdd(key, (k) => {
@ttrider
ttrider / TorrentFileReader.cs
Created March 31, 2015 20:09
parse .torrent file into JSON in C#
using System;
using System.IO;
using System.Text;
using Newtonsoft.Json.Linq;
namespace ReadTorrentFile
{
class Program
{
static void Main(string[] args)
using System.Data.SqlClient;
using System.Linq;
using System.Management.Automation;
using System.Threading.Tasks;
using JetBrains.Annotations;
using TTRider.PowerShellAsync;
namespace PowerShellAsyncExample
{
[Cmdlet(VerbsLifecycle.Invoke, "MultiSql")]
protected async override Task BeginProcessingAsync()
{
// before processing of the first item in a pipeline
}
protected async override Task ProcessRecordAsync()
{
// process item from a pipeline
}
protected override void BeginProcessing()
{
// before processing of the first item in a pipeline
}
protected override void ProcessRecord()
{
// process item from a pipeline
}
protected override void ProcessRecord()
{
// processing logic
}
@ttrider
ttrider / WeightedSet.cs
Created October 16, 2014 18:50
WeightedSet of values
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace TTRider.Collections
{
public class WeightedValue<T>
{
public WeightedValue()
var titlecase = CultureInfo.CurrentCulture
.TextInfo
.ToTitleCase(" here is my string in title case");
// Here Is My String In Title Case
var wrongResult = "Straße" == "Strasse"; // false
var rightResult = string.Equals("Straße", "Strasse", StringComparison.CurrentCulture); // true
bool Better02(string arg)
{
foreach (var str in mystrings)
{
if (string.Equals(arg, str, StringComparison.CurrentCultureIgnoreCase))
{
return true;
}
}
return false;