Skip to content

Instantly share code, notes, and snippets.

View mtfelian's full-sized avatar

Artemii Shepelev mtfelian

View GitHub Profile
@mtfelian
mtfelian / graceful_process_close_windows.go
Last active March 5, 2018 14:03
Windows graceful process shutdown (WM_CLOSE / Ctrl-Break)
package main
import (
"fmt"
"os/exec"
"syscall"
"time"
"unsafe"
)
@mtfelian
mtfelian / count_open_files.sh
Created May 25, 2020 10:55
Displays top10 processes by count of open files
cd /proc
for pid in [0-9]*
do
echo "PID = $pid with $(ls /proc/$pid/fd/ | wc -l) file descriptors"
done | sort -rn -k5 | head | while read -r _ _ pid _ fdcount _
do
command=$(ps -o cmd -p "$pid" -hc)
printf "pid = %5d with %4d fds: %s\n" "$pid" "$fdcount" "$command"
done
@mtfelian
mtfelian / method1.go
Last active June 3, 2020 08:05
How to fill and pass C struct from Go
options := &C.GDALGridLinearOptions{dfRadius: C.double(-1.0), dfNoDataValue: C.double(0.0)}
C.someCall(unsafe.Pointer(options))
@mtfelian
mtfelian / client-main.go
Last active June 25, 2022 09:33
Jaeger 1.6 Golang distributed tracing example (minimalistic)
package main
import (
"context"
"fmt"
"io"
"net/http"
"os"
"time"
@mtfelian
mtfelian / run-postgis.ps1
Last active January 10, 2023 15:58
PS script to recreate DB Postgis container on Windows Docker Desktop, wait for DB init completes and create databases
docker ps -q | % { docker stop $_ }
docker container prune -f
$containerName = "postgis"
docker run -d --name $containerName -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=postgres postgis/postgis:13-3.2
$maxWaitTime = 15000 # milliseconds
$checkInterval = 500
$startTime = Get-Date
$dbnames = @(
@mtfelian
mtfelian / stop_containers.ps1
Created January 12, 2023 09:56
PS script to stop all containers except the given list
$containersToKeep = @("postgis")
$runningContainers = docker ps -q
foreach ($container in $runningContainers) {
$containerName = (docker inspect --format "{{.Name}}" $container).TrimStart('/')
if ($containersToKeep -contains $containerName) {
continue
}
Write-Host "Stopping container $container ($containerName)"
docker stop $container
Write-Host "Removing container $container ($containerName)"
@mtfelian
mtfelian / delete-git-branches.ps1
Created July 17, 2023 08:41
delete_local_git_branches_not_on_origin
function Remove-DeletedGitBranches
{
param
(
[Parameter()]
[Switch]
$Force
)
$null = (git fetch --all --prune);