Skip to content

Instantly share code, notes, and snippets.

-- Create materialized view to store all price list prices as MD5 hash
CREATE MATERIALIZED VIEW prices AS select price_list_id, MD5(array_agg(pp.quantity::text || pp.unit_code || pp.value::text || pp.currency ORDER BY pp.quantity, pp.unit_code, pp.value::text, pp.currency)::text) as pmd5 FROM oro_price_product pp GROUP BY price_list_id;
-- Add index for md5 to improve performance
CREATE INDEX pmd5_idx ON prices(pmd5);
-- SELECT base price list, number of duplicated price lists and concatenated ids of duplicates
select p1.price_list_id, COUNT(p2.price_list_id), array_agg(p2.price_list_id ORDER BY p2.price_list_id) from prices p1 INNER JOIN prices p2 on p1.pmd5 = p2.pmd5 AND p1.price_list_id <> p2.price_list_id WHERE p1.price_list_id = (SELECT MIN(price_list_id) FROM prices WHERE p1.pmd5 = pmd5) GROUP BY p1.price_list_id ORDER BY p1.price_list_id;
-- SELECT overall number of unique price lists
SELECT COUNT(DISTINCT pmd5) from prices;
-- DROP VIEW
DROP MATERIALIZED VIEW prices;
phpspy -p 25109 -b 40960 | /usr/local/src/phpspy/stackcollapse-phpspy.pl | /usr/local/src/phpspy/vendor/flamegraph.pl > flame.svg
@x86demon
x86demon / gist:0de22a61f75c26da8807039502c65228
Created February 6, 2020 16:24
ES7 increase max shards
curl -XPUT localhost:9200/_cluster/settings -H 'Content-type: application/json' --data-binary $'{"transient":{"cluster.max_shards_per_node":20000}}'
@x86demon
x86demon / block_sip_spammers.sh
Created May 15, 2020 14:21
Block asterisk password brute force in Asus RT-n66u
#!/bin/sh
IPS=$(cat /opt/var/log/asterisk/messages | grep -oE "failed for '([^:]*)" | grep -oE '[0-9]+\.[0-9]+\.[0-9+]+\.[0-9]+' | sort | uniq)
[ -z "$IPS" ] && exit 0
for ip in ${IPS}
do
echo "Blocking IP: ${ip}"
iptables -I INPUT -s ${ip} -j DROP
echo "iptables -I INPUT -s ${ip} -j DROP" >> /jffs/scripts/firewall-start
@x86demon
x86demon / telegram_send.py
Created May 15, 2020 14:23
Send message to telegram from cli (for Asus rt-n66u)
import requests
import sys
def telegram_bot_sendtext(bot_message):
bot_token = '***'
bot_chatID = '***'
api_url = 'https://api.telegram.org/bot' + bot_token + '/sendMessage'
data = {'chat_id': bot_chatID, 'text': bot_message}
<?php
namespace Oro\Bundle\PricingBundle\Async;
use Doctrine\DBAL\Exception\RetryableException;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
use Oro\Bundle\PricingBundle\Builder\ProductPriceBuilder;
use Oro\Bundle\PricingBundle\Entity\PriceList;
use Oro\Bundle\PricingBundle\Entity\Repository\PriceListRepository;
@x86demon
x86demon / console.sql
Created March 3, 2021 15:41
MQ topic and body
SELECT properties::jsonb->'oro.message_queue.client.topic_name' as topic, body FROM oro_message_queue;
#!/bin/sh
SCRIPT=`basename "$0"`
MASTER_NPM_PATH="/opt/node/v20/bin"
NPM_PATH_51="/opt/node/v18/bin"
NPM_PATH_50="/opt/node/v16/bin"
OLD_NPM_PATH="/opt/node/v14/bin"
SCRIPT_BIN="${OLD_NPM_PATH}/${SCRIPT}"
@x86demon
x86demon / remove_git_branches.sh
Created October 21, 2022 09:32
Remove local detached branches
#!/bin/sh
# https://stackoverflow.com/questions/13064613/how-to-prune-local-tracking-branches-that-do-not-exist-on-remote-anymore
git fetch -p ; git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -D
@x86demon
x86demon / php
Last active January 30, 2023 11:55
Automatic PHP version selector based on composer.json for Gentoo
#!/bin/sh
if [[ -f .php-version ]]
then
PHP_VERSION=$(<.php-version)
else
PHP_VERSION=''
if [[ -f composer.json ]]
then
PHP_VERSION=$(cat composer.json | egrep -o '"php"\s*:\s*"[^0-9]*[7-8]\.[0-9]+' | egrep -o '[5-8]\.[0-9]+')