Skip to content

Instantly share code, notes, and snippets.

View dadhi's full-sized avatar
🎯
Focusing

Maksim Volkau dadhi

🎯
Focusing
View GitHub Profile
@dadhi
dadhi / HeapSort.cs
Created January 9, 2024 23:06
Heap sort of string in place instead of insertion sort
// https://www.hackertouch.com/csharp-generic-heap-sort.html
using System;
public static class HeapSortMethods
{
public static void HeapSort(string[] a)
{
// build binary heap from all items
for (int i = 0; i < a.Length; i++)
@dadhi
dadhi / CSharpBench.cs
Created December 15, 2023 21:34 — forked from stolnikov/CSharpBench.cs
Odin vs C#
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
namespace CSharpLib;
public class CSharpBench
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int[] CSharp_Bench2(int[] a, int[] b, int[] result, int size)
@dadhi
dadhi / fix-wsl2-dns-resolution
Created November 27, 2023 14:17 — forked from coltenkrauter/fix-wsl2-dns-resolution
Fix DNS resolution in WSL2
More recent resolution:
1. cd ~/../../etc (go to etc folder in WSL).
2. echo "[network]" | sudo tee wsl.conf (Create wsl.conf file and add the first line).
3. echo "generateResolvConf = false" | sudo tee -a wsl.conf (Append wsl.conf the next line).
4. wsl --terminate Debian (Terminate WSL in Windows cmd, in case is Ubuntu not Debian).
5. cd ~/../../etc (go to etc folder in WSL).
6. sudo rm -Rf resolv.conf (Delete the resolv.conf file).
7. In windows cmd, ps or terminal with the vpn connected do: Get-NetIPInterface or ipconfig /all for get the dns primary and
secondary.
@dadhi
dadhi / interview_question_phone_permutations.cs
Last active September 27, 2023 10:07
Phone permutations interview question
using System;
using System.Collections.Generic;
// Image of a telephone's keypad: https://upload.wikimedia.org/wikipedia/commons/thumb/7/73/Telephone-keypad2.svg/2880px-Telephone-keypad2.svg.png
// Problem: Given phone number, output all possible letter values or "words".
// Example:
// Input: 123-000
// Output: 1ad-000 1ae-000 1af-000 1bd-000 1be-000 1bf-000 1cd-000 1ce-000 1cf-000
//
// Example:
@dadhi
dadhi / AsyncQueueWithLimitedParalellizm.cs
Created September 26, 2023 16:49
The possible interview question about the work queue in C# // @ThePrimeagen
// ## Dumb-dumb initial solution
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
public class Program
{
public static async Task Main()
{
@dadhi
dadhi / JsonParser.java
Created December 10, 2022 15:03
Java json parser with Jackson library
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JsonParserIterator {
public static void main(String[] args) throws IOException {
String json = "{ \"fx\": [{ \"pk\": \"ALL=\" }, { \"pk\": \"EUR=\" }] }";
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(json);
@dadhi
dadhi / fastest_way_to_emit_ctor_call_eg_opcodes_newobj.cs
Created July 26, 2022 11:33
Optimize ILGenerator.Emit(OpCodes.Newobj, ctor)
using System;
using System.Reflection.Emit;
using System.Diagnostics;
public class Program
{
public static void Main()
{
var con = typeof(B<int>).GetConstructors()[0];
@dadhi
dadhi / playground.rs
Last active July 20, 2022 11:02 — forked from rust-play/playground.rs
MaybeUninit and type_name implemented as AnyExt
#![allow(unused)]
fn main() {
use std::mem::{self, MaybeUninit};
let data = {
// Create an uninitialized array of `MaybeUninit`. The `assume_init` is
// safe because the type we are claiming to have initialized here is a
// bunch of `MaybeUninit`s, which do not require initialization.
let mut data: [MaybeUninit<Vec<u32>>; 1000] = unsafe {
MaybeUninit::uninit().assume_init()
@dadhi
dadhi / code.cs
Created July 16, 2022 19:25 — forked from hypeartist/code.cs
Type instantiation (.ctor with parameters)
object obj;
var r = 0;
const int cnt = 1000000;
var constructorInfo = typeof(Class).GetConstructor(new[] { typeof(int) })!;
var hCtor = constructorInfo.MethodHandle;
RuntimeHelpers.PrepareMethod(RuntimeMethodHandle.FromIntPtr(hCtor.Value));
var pCtor = (delegate* managed<object, int, void>)hCtor.GetFunctionPointer();
@dadhi
dadhi / Quic.cs
Created May 12, 2022 07:13 — forked from davidfowl/Quic.cs
using System.IO.Pipelines;
using System.Net;
using System.Net.Security;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Connections.Features;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core;
var builder = WebApplication.CreateBuilder(args);