Skip to content

Instantly share code, notes, and snippets.

View alexmnv's full-sized avatar

Alexandr Motuzov alexmnv

View GitHub Profile
<?php
use Illuminate\Database\PostgresConnection as Connection;
class DBTransaction
{
/**
* Выполнение функкции в транзакции с возможностью указывать точки сохранения.
* - Если функция выполнится без ошибки (Exception), произойдёт полный коммит
* - Если функция выбросит исключение, то произойдёт коммит от начала до последнего вызовы `savepoint()`
@alexmnv
alexmnv / gist:d5570ee29c08b2496f9610d0484f09e4
Created December 27, 2017 07:47
UTM5 log tables rotation (Postgres)
CREATE OR REPLACE FUNCTION log_tables_rotate(v_table_name text)
RETURNS boolean AS
$BODY$
DECLARE
rec record;
rotate record;
last_rotation_end_date int;
rotate_period_time timestamp with time zone;
@alexmnv
alexmnv / redux-saga - custom IO example
Last active March 20, 2022 21:04
redux-saga - runSaga() example with custom IO, using node.js EventEmitter
const { runSaga } = require('redux-saga')
const { takeEvery, select } = require('redux-saga/effects')
const EventEmitter = require('events').EventEmitter
//
// Create Saga IO:
//
const createSagaIO = (emitter, getStateResolve) => ({
// this will be used to resolve take Effects
subscribe: (callback) => {
@alexmnv
alexmnv / postgres_ip_to_int
Created July 10, 2015 08:15
Postgresql, cast inet to bigint (ip to integer)
SELECT (ip - '0.0.0.0'::inet) as ip_integer
@alexmnv
alexmnv / List directories ordered by size
Created July 6, 2015 06:55
List directories ordered by size
du --max-depth=1 / | sort -n -r
rsync /src/ user@host:/dst/ --delete --itemize-changes --recursive --checksum --exclude='exclude.file' --dry-run | grep -vF '<f..T......'
@alexmnv
alexmnv / Silex - Symfony - output CSV as stream
Last active October 3, 2019 08:12
Silex/Symfony - output CSV
function outputCSV(Application $app, array $recs, $filename)
{
$stream = function() use ($recs) {
$output = fopen('php://output', 'w');
foreach ($recs as $rec)
{
fputcsv($output, $rec);
}
fclose($output);
};
@alexmnv
alexmnv / xargs multithreaded nslookup
Created February 26, 2015 06:35
xargs multithreaded nslookup
(echo google.com; echo yandex.ru; echo mail.ru) | xargs -I DOMAIN --max-procs=10 -n 1 nslookup DOMAIN | awk '/^Address: / { print $2 }; /^Name/ { print $2 }'
@alexmnv
alexmnv / telnet http request
Last active August 29, 2015 14:15
Send HTTP request via telnet
echo -e "GET /some-path HTTP/1.0\nHost: 127.0.0.1\n\n" | telnet 127.0.0.1 80