Skip to content

Instantly share code, notes, and snippets.

View sokil's full-sized avatar
🇺🇦
sapere aude

sokil

🇺🇦
sapere aude
View GitHub Profile
@sokil
sokil / delete_insert_deadlock.sql
Last active November 28, 2023 13:11
select for update deadlock
## Connection 1
1. begin
3. delete from table where id = 1;
5. insert into table values (1);
## Connection 2
2. begin
@sokil
sokil / LetsEncrypt.sh
Last active May 3, 2020 12:59
LetsEncrypt
# generate cert from another host with validation by dns TXT record
certbot certonly --manual --preferred-challenges dns
@sokil
sokil / test.php
Created May 2, 2020 11:54
PHP Segmentation fault
<?php
class A implements \Countable
{
public function count() { return count($this); }
}
$a = new A();
echo count($a);
@sokil
sokil / textboxOnlyNumbers.js
Last active April 26, 2020 14:15
prevent input of any chars to textbox except numbers
/**
Allowed chars:
8 - backspace
9 - tab
35 - end
36 - home
37 - left arruw
39 - right arrov
46 - del
48 - 0
@sokil
sokil / .bashrc
Last active January 15, 2020 14:04
bashrc
export PS1='[\[\e[1;33m\]\u@\h\[\e[0m\] \[\e[1;32m\]\W\[\e[0m\]]\$ '
@sokil
sokil / sort.php
Last active December 27, 2019 10:33
Sort bool array
<?php
$source = [];
for ($i = 0; $i < 1000000; $i++) {
$source[] = (bool)mt_rand(0,1);
}
###### native
$t = microtime(true);
@sokil
sokil / client.php
Created December 5, 2019 10:33
PSR HTPP Client
<?php
declare(strict_types=1);
namespace HttpClient;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
<?php
$array = [
'aaaa' => [
'k1' => str_repeat('a', 1000),
]
];
switch ($argv[1] ?? 1) {
default:
@sokil
sokil / commands.sh
Created May 9, 2019 15:30
rabbitmqadmin
# delete queue
rabbitmqadmin -c ~/rabbitmq.conf delete queue name=some_queue_name
# delete queue
rabbitmqadmin -c ~/rabbitmq.conf purge queue name=some_queue_name
# show queues
rabbitmqadmin -c ~/rabbitmq.conf list queues name messages messages_ready messages_unacknowledged --sort=messages -N some_group
@sokil
sokil / disk.md
Last active January 9, 2019 22:18
disk.md

Show UUIDs of devices

sokil@hp:/media/sokil/GAMMA$ sudo blkid
/dev/sda1: UUID="f3f5adb7-6dd5-4fd8-8ac8-e437190aacf8" TYPE="ext4" PARTUUID="b579a75a-01"
/dev/sda2: LABEL="DATA" UUID="e7083bc0-8a54-4757-a88f-44bef551cf6f" TYPE="ext4" PARTUUID="b579a75a-02"
/dev/sdb1: LABEL="ALPHA" UUID="94895615-2b49-40a1-a582-425666956a00" TYPE="ext4" PARTUUID="00064a47-01"
/dev/sdb2: LABEL="BETA" UUID="F35B-0EBD" TYPE="vfat" PARTUUID="00064a47-02"
/dev/sdb3: LABEL="GAMMA" UUID="17239C486BA96B6B" TYPE="ntfs" PTTYPE="dos" PARTUUID="00064a47-03"