Skip to content

Instantly share code, notes, and snippets.

View 0x49D1's full-sized avatar
💭
💾

Dmitry Pursanov 0x49D1

💭
💾
View GitHub Profile
@0x49D1
0x49D1 / run_gunicorn_with_logs_sample.bat
Created January 18, 2019 06:21
Sample of running python flask service with gunicorn. Logs added.
gunicorn --bind 0.0.0.0:5001 --access-logfile /var/log/gunicorn/access.log --error-logfile /var/log/gunicorn/error.log --capture-output --reload wsgi:app &
@0x49D1
0x49D1 / euler2.py
Created January 25, 2019 06:36
Python sample of project Euler problem 2 solution
import time
def even_sum_fib(sum_limit):
current = previous = 1
sum = 0
while(sum < sum_limit):
if current % 2 == 0:
sum += current
previous, current = current, current + previous
return sum
@0x49D1
0x49D1 / mysql_catch_transaction_exception_block.sql
Last active August 2, 2019 08:03
MySQL catch exception and log it into another table for example.
# CREATE PROCEDURE AND OTHER DECLARE STATEMENTS HERE
# ....
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE, @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
ROLLBACK;
SET @full_error = CONCAT('ERR:', @errno, '(', @sqlstate, '):', @text);
@0x49D1
0x49D1 / count_str.sql
Created September 11, 2019 06:29
MySQL number of times string contains another string (count char appearance)
CREATE FUNCTION COUNT_STR(haystack TEXT, needle VARCHAR(32))
RETURNS INTEGER DETERMINISTIC
BEGIN
RETURN ROUND((CHAR_LENGTH(haystack) - CHAR_LENGTH(REPLACE(haystack, needle, ""))) / CHAR_LENGTH(needle));
END;
# Example: SELECT COUNT_STR('{"a":"test","fdfs":"test","more":"tests","b":"a"}',',"'); returns 3
@0x49D1
0x49D1 / syslog_wsl_windows10_problem.md
Created November 15, 2019 12:03
rsyslog restart problem in WSL. No syslog logs in /var/log
@0x49D1
0x49D1 / ignore_xunit_test_with_detached_debugger.cs
Created February 3, 2020 07:26
Ignore xUnit test when running tests not in DEBUG mode.
/// <summary>
/// Credits to https://lostechies.com/jimmybogard/2013/06/20/run-tests-explicitly-in-xunit-net/
/// </summary>
public class RunnableInDebugOnlyAttribute : FactAttribute
{
public RunnableInDebugOnlyAttribute()
{
if (!Debugger.IsAttached)
{
Skip = "Only running in interactive mode.";
@0x49D1
0x49D1 / mysqldump_schema_backup_example.sh
Last active March 23, 2021 12:11
Remote database server backup of all databases (all schemes) with mysqldump example with comments. And restore command with retained comments in procedures (for example).)
#!/bin/bash
# For example: https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html
# --no-data Do not dump table contents
# --triggers Do add triggers too
# --host Dump data from the MySQL server on the given host. The default host is localhost.
# --port For TCP/IP connections, the port number to use.
# --all-databases Dump all tables in all databases.
# -u The user name of the MySQL account to use for connecting to the server.
# --verbose Verbose mode. Print more information about what the program does.
@0x49D1
0x49D1 / git_last_tags.sh
Last active April 3, 2020 10:05
Create Git Alias for Last Tags
#!/bin/sh
# List all aliases
git config --get-regexp alias
# Add last tags alias sample
git config --global alias.lasttags "log --graph --all --decorate --oneline --simplify-by-decoration -5"
@0x49D1
0x49D1 / update_git_repos.sh
Last active April 13, 2020 09:00
Script to update and publish (pull&push) all git repositories in sub-directories at once.
#!/bin/bash
eval $(keychain --eval id_github_rsa) # in case you use keychain to store keys. https://linux.die.net/man/1/keychain
find . -maxdepth 1 -type d -exec sh -c '(cd {} && echo $PWD && git pull && git push)' ';'
@0x49D1
0x49D1 / deploy_angular_example.sh
Created June 15, 2020 11:48
Deploy angular app using SCP with automatic password without interaction
ng build --prod && sshpass -f ~/test_pass scp -r ./dist/project/* REMOTE_USER@REMOTE_SERVER:/var/www/html
# Where:
# test_pass is the file, containing the password for remote server access
# the project will be deployed to /var/www/html