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 / 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"
@sokil
sokil / rsa.md
Created November 23, 2018 14:57
openssl rsa key generate

generate private

openssl genrsa -des3 -out private.pem 512

remove passphrase

openssl rsa -in private.pem -out private.pem

generate public

openssl rsa -in private.pem -outform PEM -pubout -out public.pem

@sokil
sokil / mysqlLostConnection.md
Last active November 5, 2024 20:11
Mysql Server Has Gove Away
  • Error Code: 2013. Lost connection to MySQL server during query
  • Error Code: 2006. MySQL server has gone away
  • Error Code: 2003. Lost connection to backend server

Set global timeout:

mysql> SET GLOBAL wait_timeout=10;