Skip to content

Instantly share code, notes, and snippets.

@hoangitk
hoangitk / docker_collection.md
Created November 5, 2020 05:02
[Docker] #docker #collection

Docker

Docker Compose

  • Run
$ docker-compose up -d
  • Exec
$ docker-compose exec devbox-db psql devbox
@hoangitk
hoangitk / Pattern.cs
Created November 4, 2020 03:12 — forked from michael-wolfenden/Pattern.cs
Pattern
public class Pattern<TReturn>
: List<(Type Type, Func<object, TReturn> Map)>
{
public void Add<T>(Func<T, TReturn> map)
=> Add((typeof(T), o => map((T)o)));
public Pattern<TReturn> Default(TReturn val)
{
Add((object _) => val);
return this;
@hoangitk
hoangitk / Chrome_snippets.md
Created October 21, 2020 02:14
[Chrome snippets] #chrome #snippets

Chrome Snippets

List all urls

urls = []
$$('*').forEach(element => {
  urls.push(element.src)
  urls.push(element.href)
  urls.push(element.url)
}); console.log(...new Set(urls)) 
@hoangitk
hoangitk / Git reset remote repo.md
Last active September 18, 2021 05:40
[Git reset remote repo] #git

Re-init

Method 1 - reset, keep history and push --force

git reset --soft HEAD^
git add -A .
git commit -m "rewriting history"
git push --force origin master
@hoangitk
hoangitk / ConsolePortScanner.cs
Created September 11, 2020 06:39 — forked from jonlabelle/ConsolePortScanner.cs
Simple async C# Open Port Network Scanner
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Net.Sockets;
namespace ConsolePortScanner
{
class MainClass
@hoangitk
hoangitk / WSL.md
Last active April 25, 2023 11:50
[WSL] #wsl

WSL

Command

  • List all distros
wsl -l -v

Move distro to other location

  1. Shutdown all WSL distros
@hoangitk
hoangitk / csharp_data_annotation.md
Last active August 20, 2020 04:33
[CSharp_DataAnnotation] #csharp #validation
@hoangitk
hoangitk / LockingConcurrentDictionary.cs
Created July 30, 2020 02:39
[LockingConcurrentDictionary.cs] #csharp #metaprogramming
/*https://github.com/AutoMapper/AutoMapper/blob/18f974a091c910675eea599e6164e8b70ca3aae8/src/AutoMapper/Internal/LockingConcurrentDictionary.cs*/
public struct LockingConcurrentDictionary<TKey, TValue>
{
private readonly ConcurrentDictionary<TKey, Lazy<TValue>> _dictionary;
private readonly Func<TKey, Lazy<TValue>> _valueFactory;
public LockingConcurrentDictionary(Func<TKey, TValue> valueFactory)
{
_dictionary = new ConcurrentDictionary<TKey, Lazy<TValue>>();
_valueFactory = key => new Lazy<TValue>(() => valueFactory(key));
@hoangitk
hoangitk / ProxyGenerator.cs
Last active July 30, 2020 02:40
[ProxyGenerator.cs] #csharp #metaprogramming
/*https://github.com/AutoMapper/AutoMapper/blob/18f974a091c910675eea599e6164e8b70ca3aae8/src/AutoMapper/Execution/ProxyGenerator.cs*/
public static class ProxyGenerator
{
private static readonly byte[] privateKey =
StringToByteArray(
"002400000480000094000000060200000024000052534131000400000100010079dfef85ed6ba841717e154f13182c0a6029a40794a6ecd2886c7dc38825f6a4c05b0622723a01cd080f9879126708eef58f134accdc99627947425960ac2397162067507e3c627992aa6b92656ad3380999b30b5d5645ba46cc3fcc6a1de5de7afebcf896c65fb4f9547a6c0c6433045fceccb1fa15e960d519d0cd694b29a4");
private static readonly byte[] privateKeyToken = StringToByteArray("be96cd2c38ef1005");
private static readonly MethodInfo delegate_Combine = typeof(Delegate).GetRuntimeMethod("Combine", new[] { typeof(Delegate), typeof(Delegate) });
@hoangitk
hoangitk / git_commands.md
Last active November 24, 2021 06:52
[Git command] #git #collection

Git Commands

How to remove local untracked files from the current Git branch

  • List of untracked files
git clean -n