Skip to content

Instantly share code, notes, and snippets.

@dmlogv
dmlogv / Straight Tree.ipynb
Created June 27, 2019 11:50
Symmetric tree using `pyplot`
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dmlogv
dmlogv / sp_nolock_log.sql
Created June 27, 2019 12:31
SQL Server Logging inside transactions
CREATE PROCEDURE [logging].[sp_log](
@msg NVARCHAR(MAX) = NULL
, @cnt BIGINT = NULL
, @proc NVARCHAR(256) = NULL
)
AS
BEGIN
/*
<summary>
Microsoft SQL Server NoLock logging
javascript: void((function(){
var rulers = document.getElementsByClassName('js-pro.logvinenko.js.ruler');
if (rulers.length > 0) {
document.removeEventListener('mousemove', moveRuler);
var ruler = rulers[0];
document.body.style.cursor = ruler.getAttribute('data-cursor');
document.body.removeChild(ruler);
ruler = null;
} else {
var ruler = document.createElement('div');
@dmlogv
dmlogv / measure_time.py
Created July 2, 2019 05:44
Measure a function execution time
import logging
logging.basicConfig(level=logging.INFO)
def measure_time(func):
def wrapper(*args, **kwargs):
f = datetime.datetime.fromtimestamp
@dmlogv
dmlogv / sql-parser.regex
Created July 24, 2019 06:14
RegEx T-SQL Parser for extracting sources and destinations from the INSERT statement
(insert (?: \s (?:bulk|into))?) \s
(?(?=openquery) (?:
(openquery) \s \(
(\S+?) \, \s \' .+? \'\)
)
| (\S+)
)
.+?
select
@dmlogv
dmlogv / export_airflow_connection.py
Last active July 14, 2020 10:43
Export Airflow connections
#!/usr/bin/env python3
"""Export Apache Airflow connections
Run under `airflow` user (or another user owns an `airflow` DB) inside its home directory. Like a:
[dm-logv@airflow ~]$ sudo -u airflow /bin/bash
[airflow@airflow dm-logv]$ cd ~
[airflow@airflow ~]$ chmod +x export_airflow_connections.py
[airflow@airflow ~]$ ./export_airflow_connections.py > secrets.py
@dmlogv
dmlogv / list_users.sh
Created June 18, 2020 11:32
List ClickHouse users.xml users
echo "du /yandex/users" | xmllint --shell /etc/clickhouse-server/users.xml | grep -e '^ \w' | tr -d ' ' | sort
@dmlogv
dmlogv / download-vimeo-video.js
Created June 28, 2020 11:11
Download private embed Vimeo video
// Ctrl+Shift+C to open Chrome Console.
// Choose an IFrame of the Vimeo Video with a comment `player.vimeo.com`
// in the drop-down list `top`.
// Run a script:
var videos = [];
$$('script')[3].textContent.match(/\{[^{]+?mp4[^}]+?\}/g).forEach(
x => { o = JSON.parse(x);
videos.push(o);});
videos.sort((a, b) => a.quality.localeCompare(b.quality)).forEach(
@dmlogv
dmlogv / collect_habr_toc.js
Created July 27, 2020 15:39
Collect Habr (or any other Markdown) table of contest
$$('h2,h3').forEach(el => {
if (el.hasAttribute('id')) {
console.log(`- [${el.innerText}](#${el.id})`);
}
})