Skip to content

Instantly share code, notes, and snippets.

View sashaaro's full-sized avatar

Aleksandr sashaaro

View GitHub Profile
@sashaaro
sashaaro / lock.sql
Last active July 26, 2023 16:39 — forked from moofkit/gist:2146f18953be9053ae372c063d28912b
lock monitor. postgresql
CREATE VIEW lock_monitor AS
SELECT COALESCE(((blockingl.relation)::regclass)::text, blockingl.locktype) AS locked_item,
(now() - blockeda.query_start) AS waiting_duration,
blockeda.pid AS blocked_pid,
blockeda.query AS blocked_query,
blockedl.mode AS blocked_mode,
blockinga.pid AS blocking_pid,
blockinga.query AS blocking_query,
blockingl.mode AS blocking_mode
FROM (((pg_locks blockedl
@sashaaro
sashaaro / workers_pool.go
Last active May 16, 2023 08:47
golang simple workers pool
package utils
type WorkerPool[T any] struct {
workFn func(jobID int, result chan<- T)
result chan T
}
func NewWorkerPool[T any]() WorkerPool[T] {
pool := WorkerPool[T]{}
pool.result = make(chan T)
@sashaaro
sashaaro / .barshrc.sh
Last active March 16, 2023 07:12
asciinema terminal record for ssh session
# .barshrc
if [[ $- =~ i ]] && [[ -z "$ASCIINEMA_REC" ]] && [[ -n "$SSH_TTY" ]]; then
asciinema rec -q "$HOME/$(date +"%FT%T")_$RANDOM.cast"
fi
@sashaaro
sashaaro / dap.lua
Last active March 2, 2023 11:04
nvim-dap + debug golang delve + docker compose
local dap = {
adapters = {
go = {
type = "server",
port = 9004,
}
},
configurations = {
go = {
{
@sashaaro
sashaaro / README.md
Created October 22, 2021 10:56
Golang docker service with debbuger delve and source

How to enable debug go services from my source

If you want change, debug and rebuild go services need build docker-compose/php/go-delve.Dockerfile image and uncomment override go services in config docker-compose/php/docker-compose.yml reload service

./dd.sh upc goapi

Goland -> Run/Debug Configuration -> add new Go Remote -> host=localhost, port=9004 Press the green bug for rebuild and debug services.

@sashaaro
sashaaro / with-async-contenxt.operator.ts
Last active October 1, 2021 12:24
rxjs operator AsyncLocalStorage
import {AsyncLocalStorage} from "async_hooks";
import {MonoTypeOperatorFunction, Observable, Subscription} from "rxjs";
export function withinContext<T, S = any>(storage: AsyncLocalStorage<S>, store: () => S): MonoTypeOperatorFunction<T> {
return function (source: Observable<T>) {
return new Observable((observer) => {
let sub: Subscription;
storage.run(store(),() => {
sub = source.subscribe(observer);
@sashaaro
sashaaro / wkhtmltopdf.php
Last active July 14, 2023 19:09
wkhtmltopdf generate pdf stream without temporary file
<?php
use Symfony\Component\Process\Process;
class DocumentGenerator
{
private function wkhtmltopdf(string $html): string
{
$wkhtmltopdfProcess = new Process('/usr/bin/wkhtmltopdf -q - -');
@sashaaro
sashaaro / git- squash.sh
Last active February 16, 2021 21:20
git squash commits
git reset --hard HEAD~12
git merge --squash HEAD@{1}
git commit
// or
git reset master
git add .
git commit -m "DEV-21 combined commit msg"
git push origin -f my-current-branch
@sashaaro
sashaaro / log.operaotor.ts
Created February 14, 2021 19:02
log rxjs operator
import { OperatorFunction } from 'rxjs';
import { tap } from 'rxjs/operators';
export function log<T>(prefix: string = null): OperatorFunction<T, T> {
return tap(
(data: T) => logIt(prefix, data),
err => logIt(prefix + '[ERROR]', err),
() => {
window.console.group(prefix + '[COMPLETE]')
window.console.groupEnd()
@sashaaro
sashaaro / dev-proxy.js
Last active February 17, 2021 21:20
simple onefile nodejs proxy for backend and frontend
const http = require('http')
const frontendPort = 4200; // typically angular
const backendPort = 3001;
const backendRoutePrefix = '/api'
const server = http.createServer((request, response) => {
console.log('Request: ' + request.url)
const isApi = request.url.startsWith(backendRoutePrefix);