Skip to content

Instantly share code, notes, and snippets.

@Andrey2G
Andrey2G / GetHashCode.cs
Last active November 12, 2022 21:26
Overriding GetHashCode
public class MyValueObject:ValueObject<MyValueObject>
{
public int field1{get;}
public double field2{get;}
public string field3{get;}
public override int GetHashCode()
{
//don't forget to check fields for null
unchecked
@Andrey2G
Andrey2G / optomize-docker-desktop-wsl-ext4-vhdx-file.ps
Created September 18, 2022 19:44
When you working with Docker Desktop for a long time you will found that the file ext4.vhdx increasing the size and in some cases it happen very fast. You are also can click on Clean/Purge data on Docker Desktop side.
#stop Docker Desktop and wait when it completely stopped
#Run it as Administrator
Optimize-VHD -Path $ENV:UserProfile\AppData\Local\Docker\wsl\data\ext4.vhdx -Mode Full
@Andrey2G
Andrey2G / program.cs
Last active March 31, 2022 13:01
Updating Inbound rules in specified Security Group (AWS EC2)
using Amazon;
using Amazon.EC2;
const string CREDENTIALS_PROFILE = "mine";
const string SECUTIRY_GROUP = "sg-XXXXXXXXX";
const string MATCH_PHRASE = "any part of description";
const string RULE_DESCRIPTION = "new description";
RegionEndpoint region=Amazon.RegionEndpoint.USEast1;
using var httpClient = new HttpClient();
@Andrey2G
Andrey2G / encoding.txt
Last active April 7, 2024 13:00
Video Encoding with multiple resolutions
ffmpeg -i "c:/videos/sample.mp4
-map 0:v:0 -map 0:a:0 -map 0:v:0 -map 0:a:0 -map 0:v:0 -map 0:a:0
-c:v libx264 -crf 22 -c:a aac -ar 48000
-filter:v:0 scale=w=480:h=360 -maxrate:v:0 600k -b:a:0 64k
-filter:v:1 scale=w=640:h=480 -maxrate:v:1 900k -b:a:1 128k
-filter:v:2 scale=w=1280:h=720 -maxrate:v:2 900k -b:a:2 128k
-var_stream_map "v:0,a:0,name:360p v:1,a:1,name:480p v:2,a:2,name:720p"
-preset slow -hls_list_size 0 -threads 0 -f hls -hls_playlist_type event -hls_time 3
-hls_flags independent_segments -master_pl_name "name-pl.m3u8"
"c:/videos/encoded/name-%v.m3u8"
@Andrey2G
Andrey2G / Restoring TFS Database without ldf files.sql
Last active January 25, 2019 14:40
restoring TFS Database on the other server without ldf files
USE master
GO
CREATE DATABASE Tfs_DefaultCollection
GO
ALTER DATABASE Tfs_DefaultCollection SET OFFLINE
GO
-- NOW Delete Tfs_DefaultCollection mdf and ldf files
-- AND copy mdf you need to restore
public static string ToReadableTime(this DateTime value)
{
var ts = new TimeSpan(DateTime.UtcNow.Ticks - value.Ticks);
double delta = ts.TotalSeconds;
if (delta < 60)
{
return ts.Seconds == 1 ? "one second ago" : ts.Seconds + " seconds ago";
}
if (delta < 120)
{
@Andrey2G
Andrey2G / DelayedAutostart.ps1
Created March 15, 2017 20:19
Powershell: Services: support Automatic (Delayed Start)
#https://msdn.microsoft.com/powershell/reference/5.1/microsoft.powershell.management/Set-Service
#There is no option Delayed autostart in StartupType
#possible solutions:
#1. start sc
$Service="My service"
sc.exe Config $Service Start= Delayed-Auto
#2. set corresponded property in regedit
#see https://blogs.technet.microsoft.com/askperf/2008/02/02/ws2008-startup-processes-and-delayed-automatic-start/
Set-ItemProperty -Path "Registry::HKLM\System\CurrentControlSet\Services\$Service" -Name "DelayedAutostart" -Value 1 -Type DWORD
@Andrey2G
Andrey2G / executeRedisCommandInChunks.lua
Last active February 20, 2018 00:35
Redis, LUA, execute Redis command in chunks
-- to avoid the problem with unpack ("too many results to unpack")
-- we can increase LUAI_MAXCSTACK in luaconf.h https://www.lua.org/source/5.1/luaconf.h.html
-- or execute the command with using table.unpack (https://www.lua.org/manual/5.1/manual.html#pdf-table.unpack) in chunks by specific length
-- table.merge - separated function to merge two tables
-- size of args should be >4000 (chunk length)
local executeRedisCommandInChunks = function (command, key, args)
local results = {}
local chunkResult = {}
local args_len = #args
-- chunk length (any positive value less then 8000)