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 / ramfs.md
Last active December 23, 2017 21:03
RAM FS

Bash command

$ mount -t {TYPE} -o size={SIZE} {FSTYPE} {MOUNTPOINT}
Parameter Description
TYPE type of RAM disk to use; either tmpfs or ramfs.
SIZE size to use for the file system. Ramfs does not have a physical limit and is specified as a starting size.
@sokil
sokil / datetime.md
Last active November 5, 2024 16:01
date time and timestamp in MySQL

Difference

MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval. This does not occur for other types such as DATETIME.

if server timezone changed, values of timestamp will be valid, because it stored as UTC, but values of datetime will change.

Timestamp

Timestamp stores values from 1970-01-01 00:00:00 UTC.

@sokil
sokil / redis_hash_bench.php
Last active December 11, 2017 22:41
Redis hash multi set and delete benchmark
<?php
$client = new \Predis\Client(
[
'host' => 'localhost',
'port' => 6380,
'password' => 'pass',
'database' => 1,
],
[
@sokil
sokil / php_float.md
Last active December 5, 2017 11:24
PHP float

From string

Doesn't work:

[$decimal, $fractal] = explode('.', (string)$timestamp);
if ($fractal === null) {
    $fractal = '000000';
}

because:

@sokil
sokil / pcntl_signal.php
Last active November 10, 2017 19:43
pcntl_signal.php
<?php
// Ctrl+C in console
pcntl_signal(SIGINT, [$this, 'handle']);
// Graceful termination by supervisor
pcntl_signal(SIGTERM, [$this, 'handle']);
pcntl_signal(SIGHUP, [$this, 'handle']);
pcntl_signal(SIGUSR1, [$this, 'handle']);
@sokil
sokil / consul.sh
Last active May 9, 2018 20:29
Build consul cluster, register DNS service
#!/bin/sh
# network
docker network create consulnet
# servers
docker run --network="consulnet" -p 8500:8500 --rm --name=consulServer1 consul agent --node=server1 --client=0.0.0.0 --bootstrap --server --ui
docker run --network="consulnet" --rm --name=consulServer2 consul agent --node=server2 --client=0.0.0.0 -join=172.18.0.2 --server
docker run --network="consulnet" --rm --name=consulServer3 consul agent --node=server3 --client=0.0.0.0 -join=172.18.0.2 --server
@sokil
sokil / share_docker_port.sh
Last active May 10, 2018 05:49
share docker ports
# container's localhost shared with docker host
docker run --net="host" sokil/statsd-rest-server:latest --verbose --http-port=9876
# container's localhost not shared with docker host, so requires exposing ports
docker run --net="bridge" -p 9876:9876 sokil/statsd-rest-server:latest --verbose --http-port=9876 --http-host=
@sokil
sokil / udp.sh
Created October 5, 2017 12:50
UDP Server
nc -kluvw 0 localhost 9000
@sokil
sokil / telegramBot.md
Last active June 26, 2022 23:42
Telegram Bot / Send message