Skip to content

Instantly share code, notes, and snippets.

View rgilmutdinov's full-sized avatar

Ruslan Gilmutdinov rgilmutdinov

  • Booking.com
  • Amsterdam
View GitHub Profile
@rgilmutdinov
rgilmutdinov / MergeSort1.cs
Last active April 22, 2021 09:49
Merge sort
// Top-down in-place merge sort. Complexity: O(n^2)
public class Solution {
public void Merge(int[] nums, int lo1, int mid, int hi) {
int lo2 = mid + 1;
if (nums[mid] <= nums[lo2]) {
return;
}
while (lo1 <= mid && lo2 <= hi) {
@rgilmutdinov
rgilmutdinov / BinarySearch1.cs
Created April 2, 2021 12:51
binary search templates
public int BinarySearch1(int[] nums, int target){
if (nums == null || nums.Length == 0) {
return -1;
}
int lo = 0, hi = nums.Length - 1;
while (lo <= hi) {
// Prevent (lo + hi) overflow
int mid = lo + (hi - lo) / 2;
if (nums[mid] == target) {
@rgilmutdinov
rgilmutdinov / .PowerShell Zip Provider
Last active June 2, 2022 09:54
ZipFileProvider for PowerShell
// Import module
Import-Module ./PSZip.dll
// Create new drive referring to .zip arvhive
New-PSDrive -Name "ZIP" -PSProvider "ZipFile" -Root "D:\files\archive.zip"
// List zip archive contents
Get-ChildItem -Path ZIP: -Recurse
// List only *.txt files
@rgilmutdinov
rgilmutdinov / KeyboardMessage.cs
Last active March 4, 2021 18:51
Synthesizes keystrokes
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Windows.Input;
namespace KeyboardHooks
{
public static class KeyboardMessage
{
public const uint KEYEVENTF_EXTENDEDKEY = 0x0001;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace AesCipher
{
@rgilmutdinov
rgilmutdinov / Selfmap.cs
Last active February 26, 2021 13:38
Self model projection does not take into account `Ignore` option for inner collections
using System;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using System.Collections.Generic;
using System.Linq;
public class ClassA
{
public string Name { get; set; }
public string Type { get; set; }