Skip to content

Instantly share code, notes, and snippets.

View mlshvdv's full-sized avatar
🏠
Working from home

Dmitriy Malyshev mlshvdv

🏠
Working from home
  • World
View GitHub Profile
@mlshvdv
mlshvdv / build-sox.sh
Created April 25, 2019 13:15
Build SoX binary on Ubuntu/Debian script
#!/bin/bash
sudo apt install build-essential cmake g++
sudo apt install qtbase5-dev qttools5-dev qttools5-dev-tools libqt5svg5-dev libgcrypt20-dev libargon2-0-dev libqrencode-dev zlib1g-dev
sudo apt install libxi-dev libxtst-dev libqt5x11extras5-dev libyubikey-dev libykpers-1-dev libsodium-dev libcurl4-openssl-dev libogg-dev
mkdir src && cd src
# now grab sox and its dependencies
mkdir -p deps
@mlshvdv
mlshvdv / copy-from-one-server-to-another-by-ssh.md
Last active March 15, 2019 10:54
Copy from one server to another by ssh

Original: https://serverfault.com/a/208715

Instead of using tar to write to your local disk, you can write directly to the remote server over the network using ssh.

server1$ tar -zc ./path | ssh server2 "cat > ~/file.tar.gz"

Any string that follows your "ssh" command will be run on the remote server instead of the interactive logon. You can pipe input/output to and from those remote commands through SSH as if they were local. Putting the command in quotes avoids any confusion, especially when using redirection.

Or, you can extract the tar file on the other server directly:

@mlshvdv
mlshvdv / drop-tables.sql
Created November 13, 2018 21:51
Drop all PostgreSQL tables by one query
DO $$
DECLARE
r record;
BEGIN
FOR r IN SELECT quote_ident(tablename) AS tablename, quote_ident(schemaname) AS schemaname FROM pg_tables WHERE schemaname = 'public'
LOOP
RAISE INFO 'Dropping table %.%', r.schemaname, r.tablename;
EXECUTE format('DROP TABLE IF EXISTS %I.%I CASCADE', r.schemaname, r.tablename);
END LOOP;
END$$;
@mlshvdv
mlshvdv / hashtag-extractor.php
Last active October 8, 2018 07:21
Regexp to extract a hashtag with emoji support PCRE (php)
<?php
$string = '
#abc123_
#машина
#anytest😀
#какой_тотекст😁
#😂
#🤣
#😃
@mlshvdv
mlshvdv / install-rabbitmq.sh
Created September 20, 2018 19:07
Script to install RabbitMQ server on Vagrant / Ubuntu (16.04) Sept 2018
#!/bin/bash
# You can replace "xenial" to another distribution:
# bionic (Ubuntu 18.04), artful, trusty, sid, buster, stretch, jessie, xenial (Ubuntu 16.04), yakkety, zesty
echo "deb https://dl.bintray.com/rabbitmq/debian xenial main erlang" | sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list > /dev/null
wget -O - 'https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc' | sudo apt-key add -
sudo apt-get update
sudo apt-get install rabbitmq-server -y
sudo service rabbitmq-server start
@mlshvdv
mlshvdv / tar-exclude
Created December 11, 2014 13:09
Create tar without excluded objects
tar -zvcf archive.tar /path/to/site --exclude "/path/to/site/system" --exclude "/path/to/site/tmp"
@mlshvdv
mlshvdv / anti-flood.js
Created May 20, 2014 13:12
Javascript anti-flood system
var score = 0;
var penalty = 100; // Penalty can be fine-tuned.
var lastact = new Date();
function talk() {
/* The smaller the distance, more time has to pass in order
* to negate the score penalty cause{d,s}.
*/
score -= (new Date() - lastact) * 0.55;
@mlshvdv
mlshvdv / wilson-score-range.js
Created May 2, 2014 16:15
Wilson score formula with range
/**
* Wilson score formula with range
*
* @param {number} sum Objects sum
* @param {number} total Total objects
* @param {object} range Objects (votes) range: [0, 1] or [0, n]
* @param {number} z Confidence level
*/
function wilsonScoreRange(sum, total, range, z) {
// http://amix.dk/blog/post/19588
# Firstly edit my.cnf:
# > nano my.cnf
#
# max_allowed_packet = 2600M
# net_buffer_length = 2600M
# Or by cmd:
#
# mysql> set global max_allowed_packet=1000000000;
# mysql> set global net_buffer_length=1000000;
@mlshvdv
mlshvdv / js-copy-object.js
Created March 25, 2014 10:16
Copy javascript object without reference
var obj = {
a: 25,
b: 50,
c: 75,
x: function() {
alert(this.a);
}
};
var A = Object.create(obj);
var B = Object.create(obj);