Skip to content

Instantly share code, notes, and snippets.

@sleemer
sleemer / TcpSubscriber.cs
Created October 10, 2016 20:24
Rx implementation of tcp subscriber of the remote observable sequence.
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Reactive.Linq;
using Newtonsoft.Json;
public static class TcpSubscriber
{
/// <summary>
@sleemer
sleemer / iterm2.md
Created August 21, 2021 07:49 — forked from squarism/iterm2.md
iterm2 cheatsheet

Tabs and Windows

Function Shortcut
New Tab + T
Close Tab or Window + W (same as many mac apps)
Go to Tab + Number Key (ie: ⌘2 is 2nd tab)
Go to Split Pane by Direction + Option + Arrow Key
Cycle iTerm Windows + backtick (true of all mac apps and works with desktops/mission control)
@sleemer
sleemer / .editorconfig
Last active December 21, 2020 15:12
My config files for .net projects
# EditorConfig is awesome:http://EditorConfig.org
# top-most EditorConfig file
root = true
# Don't use tabs for indentation.
[*]
indent_style = space
# (Please don't specify an indent_size here; that has too many unintended consequences.)
@sleemer
sleemer / gist:f9849b7a8a2c17a30e771df30ed8c55c
Last active June 28, 2018 15:49
Word frequency counter algorithm based on MemoryMappedFile
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Linq;
namespace WordFrequencyCounter
{
public sealed class WordCounter
{
@sleemer
sleemer / Dockerfile.debug
Last active June 6, 2017 05:29
Investigation report of how to set up debugging of aspnetcore:2 containerised app in @VScode
FROM microsoft/aspnetcore-build:2
ENV NUGET_XMLDOC_MODE skip
WORKDIR /vsdbg
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
unzip \
&& rm -rf /var/lib/apt/lists/* \
&& curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l /vsdbg
RUN mkdir /app
@sleemer
sleemer / TwitterListener.cs
Created November 22, 2016 18:48
Simple sample of using Twitter streaming API using TweetinviAPI
using System;
using System.Linq;
using Tweetinvi;
using Tweetinvi.Core.Extensions;
using Tweetinvi.Events;
using Tweetinvi.Models;
public class Program
{
public static void Main(string[] args)
@sleemer
sleemer / algorithms-stack-and-xor-or.cs
Created November 11, 2016 13:04
Implementation of algorithm that solves 'And-Xor-Or' problem from hackerrank.com
// https://www.hackerrank.com/challenges/and-xor-or
// Original statement could be simplified: ((M1&M2)^(M1|M2))&(M1^M2) == M1^M2
public int MaxAndOrXor(string input)
{
var numbers = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
.Select(int.Parse)
.ToArray();
var max = 0;
foreach (var pair in GetSmallestPairs(numbers))
{
@sleemer
sleemer / algorithms-stack-poisoned-plants.cs
Created November 8, 2016 20:03
Implementation of variation of 'The stock span problem'
// https://www.hackerrank.com/challenges/poisonous-plants/submissions/code/31921305
// Stack will be used to track series of plants splitted by the survived plants.
// Stack is a tuple of index of plant and amount of day that it will servive (0 - will live forever).
// eaxamle input: 3 7 1 2 4 8 2 7 9
// serie splitter: | |
// index: 0 1 2 3 4 5 6 7 8
// amount of days: 0 1 0 1 1 1 2 1 1
// maximum: 2
public int PoisonousPlants(string input)
{
@sleemer
sleemer / speaking-wroclaw-dotnet-meetup-3.md
Last active November 3, 2016 21:55
Notes for my presentation on WroclawDotNetMeetup#3 (03.11.2016)
@sleemer
sleemer / algorithms-stack-largest-rectangle.cs
Last active October 31, 2016 19:04
C# implementation of algorithm of calculation LargestRectangle
/// Description of the problem can be found at https://www.hackerrank.com/challenges/largest-rectangle/editorial
/// As a real use case we could consider usage of this algorithm to find out the largest rectangular subarray containing only ones.
/// For more details go to http://www.drdobbs.com/database/the-maximal-rectangle-problem/184410529
public int LargestRectangle(string input)
{
var heights = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
.Select(int.Parse)
.Concat(new[] { 0 }) // add tail 0 to force calculation when we reach the last element
.ToArray();
var positions = new Stack<int>();