Skip to content

Instantly share code, notes, and snippets.

@yang-wei
yang-wei / README.md
Last active Jan 23, 2021
SOLID Principles of Object Oriented and Agile Design
View README.md
@yang-wei
yang-wei / README.md
Last active Jan 24, 2021
Talking about Isolation in ACID
View README.md

Playing with MySQL

Read Committed

  • prevent dirty write

    • row level locks
  • prevent dirty read

    • row level locks could be use but not performant
    • write new value and remember old value at the same time. return old value while transaction is not done
@yang-wei
yang-wei / README.md
Last active Jan 13, 2021
How to check file descriptors on Linux
View README.md

system wide

> cat /proc/sys/fs/file-max
13032310

> cat /proc/sys/fs/file-nr
25696   0       13032310
@yang-wei
yang-wei / RedisClusterWithLettuce.scala
Last active Nov 18, 2020
lettuce Cannot retrieve initial cluster partitions from initial URIs from elasticache configuration endpoint
View RedisClusterWithLettuce.scala
trait RedisCluster {
def connect: Throwable \/ StatefulRedisClusterConnection[String, String]
}
class RedisClusterWithLettuce(host: String, port: Int) extends RedisCluster {
private val client = RedisClusterWithLettuce.build(host, port)
def connect: Throwable \/ StatefulRedisClusterConnection[String, String] = {
\/.fromTryCatchNonFatal {
@yang-wei
yang-wei / README
Last active Nov 8, 2020
io.netty.channel.ConnectTimeoutException: connection timed out
View README
```
❯ redis-cli -c -h localhost -p 6379
localhost:6379> cluster nodes
2f7fd4b118aec5f0d0b10a16006815098ae89e9c 192.168.48.2:6379@16379 myself,master - 0 1604830164000 1 connected 0-5460
10f1bbb2e194af0fd389253742f1cdd312dc0556 192.168.48.2:6384@16384 slave f53b0c7e1fffee2b20e7c8886075f545c50f1e9b 0 1604830165755 6 connected
ef35b6133ec1be37e8989ac4c9b3ebecf75cd612 192.168.48.2:6383@16383 slave dbb28f3dd2fa0462e7bac0ee3aef1ef9a59a1ba3 0 1604830167000 5 connected
dbb28f3dd2fa0462e7bac0ee3aef1ef9a59a1ba3 192.168.48.2:6380@16380 master - 0 1604830166271 2 connected 5461-10922
f53b0c7e1fffee2b20e7c8886075f545c50f1e9b 192.168.48.2:6381@16381 master - 0 1604830167299 3 connected 10923-16383
eeb51c67dbf497953c1fe30b7ffb7aaeabe0dc27 192.168.48.2:6382@16382 slave 2f7fd4b118aec5f0d0b10a16006815098ae89e9c 0 1604830166000 4 connected
```
@yang-wei
yang-wei / README.md
Last active Aug 8, 2018
PHP extension ext-memcached * is missing from your system
View README.md
➜  admin git:(master) phpbrew --version
phpbrew - 1.23.1
cliframework core: 2.5.4
➜  admin git:(master) php -v
PHP 5.6.30 (cli) (built: Aug  7 2018 17:48:36)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
➜  admin git:(master) which php
/Users/l-wei/.phpbrew/php/php-5.6.30/bin/php
View README.md
go run server.go

curl

curl -v -H 'Content-Type: multipart/form-data' -F "uploadfile=@./sample_video.mp4" -k http://localhost:8080/upload
@yang-wei
yang-wei / README.md
Last active Jan 2, 2018
thoughts on Vietnam
View README.md
  • Vietnam people honks and beeps a lot on the road. FYI https://saigoneer.com/saigon-culture/2172-a-guide-to-honking-in-vietnam
  • Sounds like they are angry while most of the time they just talk normally
  • Riding a motorbike is relatively safe. Speed are slow and they are good at communicating(honks and beeps) on the road
  • use tissues (mostly provided) to clean spoon and fork before having food on food stall
  • "pho" heaven
  • A lot of vegetables are served for a bowl of "pho"
  • Vietnamese (the language) is so so so difficult, especially the pronunciation part. Mandarin has 4 tones while Vietnamese has 6 tones !!! (Will never laugh at their accent when speaking other languages)
  • It's called Saigon(former name) instead Ho Chi Minh City by local
  • Vietnamese love picnic with friends, family. You can see a lot of picnic group on riverside of Saigon everyday
  • Motorbike can be romantic
@yang-wei
yang-wei / chunkify.php
Created Mar 18, 2017
Chukify - PHP utils to break function with large array parameter into multiple calls and combine the result
View chunkify.php
<?php
class Helper {
/**
* Break up process for function with first large array parameter into multiple time and merge
* Can be useful when thing are slow querying database or requesting api with large size of array at once
*/
public static function chunkify(callable $fn, array $fnFirstParam = [], $chunkSize=1000, ...$fnRestParams) {
$result = [];
foreach (array_chunk($fnFirstParam, $chunkSize) as $chunk) {
@yang-wei
yang-wei / DatePeriodHelper.php
Created Dec 3, 2016
DateTime range overlapped ?
View DatePeriodHelper.php
<?php
use DatePeriod;
class DatePeriodHelper
{
/**
* @param DatePeriod $datePeriod1
* @param DatePeriod $datePeriod2