Skip to content

Instantly share code, notes, and snippets.

View slava-konashkov's full-sized avatar
🏠
Working from home

Viacheslav Konashkov slava-konashkov

🏠
Working from home
View GitHub Profile
@slava-konashkov
slava-konashkov / random.sql
Last active March 30, 2023 10:52
Anonymizing and masking sensitive data in SQL
-- Random Int
SELECT FLOOR(RAND() * 100);
-- Random float
select FLOOR(RAND() * 1000 ) + round(rand() * 0.49 + 0.01, 2);
-- Random Srting
SELECT MD5(RAND());
SELECT TO_BASE64(UNHEX(HEX(MD5(RAND()))));
@slava-konashkov
slava-konashkov / gist:3e1292caa321c1d4be7bd8c537143930
Created April 29, 2022 09:33 — forked from PeterJuel/gist:2634518
PHP: Import huge SQL file to MySQL
$mysqli = new mysqli('localhost', '#username', '#password', '#database');
$handle = fopen('sqldump.sql', 'rb');
if ($handle) {
while (!feof($handle)) {
// This assumes you don't have a row that is > 1MB (1000000)
// which is unlikely given the size of your DB
// Note that it has a DIRECT effect on your scripts memory
// usage.
$buffer = stream_get_line($handle, 1000000, ";\n");
@slava-konashkov
slava-konashkov / ext.txt
Created January 7, 2022 16:34 — forked from chronon/ext.txt
List of docker-php-ext-install extension names
Possible values for ext-name:
bcmath
bz2
calendar
ctype
curl
dba
dom
enchant
@slava-konashkov
slava-konashkov / latency.txt
Created December 8, 2021 06:33 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@slava-konashkov
slava-konashkov / gist:9f213d196f3c68ccbd6c5d879f4d4734
Last active July 26, 2021 18:12
PHP regex Apache access log
$regex = '/^(?P<IP>\S+)
\ (?P<ident>\S)
\ (?P<auth_user>.*?) # Spaces are allowed here, can be empty.
\ (?P<date>\[[^]]+\])
\ "(?P<http_start_line>.+ .+)" # At least one space: HTTP 0.9
\ (?P<status_code>[0-9]+) # Status code is _always_ an integer
\ (?P<response_size>(?:[0-9]+|-)) # Response size can be -
\ "(?P<referrer>.*)" # Referrer can contains everything: its just a header
\ "(?P<user_agent>.*)"$/xU';
@slava-konashkov
slava-konashkov / self-signed-ssl-mongo.sh
Created May 11, 2021 14:28 — forked from exAspArk/self-signed-ssl-mongo.sh
Self-signed SSL Certificate with OpenSSL on MacOS | MongoDB
openssl genrsa -out CAroot.key 2048
openssl req -new -key CAroot.key -out CAroot.csr # CN should be different from the certificates below
openssl req -x509 -days 1825 -key CAroot.key -in CAroot.csr -out CAroot.crt
cat CAroot.crt CAroot.key > CAroot.pem
openssl genrsa -out mongod.key 2048
openssl req -new -key mongod.key -out mongod.csr
openssl x509 -req -days 1825 -in mongod.csr -CA CAroot.pem -CAkey CAroot.key -CAcreateserial -out mongod.crt
cat mongod.crt mongod.key > mongod.pem
Update IPs on Mac
Create a file com.ips.docker_127005_alias.plist
com.ips.docker_127005_alias.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
@slava-konashkov
slava-konashkov / zsh make targets only
Created March 9, 2021 08:06
Prevent completion of files for 'make' command in zsh shell.
You can ask zsh to only display targets tag for the make command completion with
zstyle ':completion:*:*:make:*' tag-order 'targets'
Add above code somewhere after the line
autoload -U compinit && compinit
@slava-konashkov
slava-konashkov / iTerm keymap
Last active February 24, 2021 17:13
iTerm keymap
Preferences > Keys (or Preferences > Profiles > Keys)
Click the plus
move forward one word:
option+right
send escape sequence
f
move back one word:
option+left
@slava-konashkov
slava-konashkov / quiz.java
Created October 28, 2020 18:58 — forked from yegor256/quiz.java
quiz.java
/**
* Please review the class below and suggest improvements. How would
* you refactor this class if it would be in a real-life project?
* There are many problems here, both high-level design mistakes,
* and low-level implementation bugs. We're interested to see high-level
* problems first, since they are most critical. The more mistakes
* you can spot, the better programmer you are.
*/
/**