From 5c4122d31f24231e33be62dcbbc8f3b497ff9150 Mon Sep 17 00:00:00 2001 From: adib Date: Thu, 12 Jan 2023 15:07:30 +0800 Subject: [PATCH 1/6] wip --- Digital Ocean/spaces.md | 9 +++++++++ Laravel/eloquent/pagination.md | 12 ++++++++++++ Laravel/issues.md | 17 +++++++++++++++++ Rust/readme.md | 13 +++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 Digital Ocean/spaces.md create mode 100644 Laravel/issues.md create mode 100644 Rust/readme.md diff --git a/Digital Ocean/spaces.md b/Digital Ocean/spaces.md new file mode 100644 index 0000000..905a9a0 --- /dev/null +++ b/Digital Ocean/spaces.md @@ -0,0 +1,9 @@ +# Spaces + +## Issues + +### Slow response time for small file + +### High probability slow response to serve video file + +### High probability slow upload for file less than 1mb and large than 500mb \ No newline at end of file diff --git a/Laravel/eloquent/pagination.md b/Laravel/eloquent/pagination.md index 802337c..2897bfc 100644 --- a/Laravel/eloquent/pagination.md +++ b/Laravel/eloquent/pagination.md @@ -16,4 +16,16 @@ $data->each(function ($job) { $jobs->setCollection($data); +``` + +or + +```php + +$paginator->getCollection()->transform(function ($value) { + // Your code here + return $value; +}); + + ``` \ No newline at end of file diff --git a/Laravel/issues.md b/Laravel/issues.md new file mode 100644 index 0000000..555f737 --- /dev/null +++ b/Laravel/issues.md @@ -0,0 +1,17 @@ +# Issues + +## count Slow + +This can be seen when your query is using pagination. + +pagination is slow because it count result for pagination. It will be much worse if inside your query contain whereHas. This is because whereHas is subQuery, and subQuery is slow by nature. + +## whereHas Slow + +need to replace with join instead + +## Mysql Date Slow + +* [MySQL performance problem using indexed datetime column](https://dba.stackexchange.com/questions/73598/mysql-performance-problem-using-indexed-datetime-column) +* [DATE() MONTH() etc. functions slow down query](https://stackoverflow.com/questions/37777883/date-month-etc-functions-slow-down-query/37777987) + diff --git a/Rust/readme.md b/Rust/readme.md new file mode 100644 index 0000000..d98ab7a --- /dev/null +++ b/Rust/readme.md @@ -0,0 +1,13 @@ +# Readme + +## Intro + +https://www.rust-lang.org/ + +## Package Manager + +https://doc.rust-lang.org/cargo/ + +## ORM + +https://diesel.rs/ \ No newline at end of file From 01a9e01fc1500a4c8ca9f2f456a907a7add9ef10 Mon Sep 17 00:00:00 2001 From: adib Date: Wed, 1 Feb 2023 10:36:40 +0800 Subject: [PATCH 2/6] wip note sign in with apple and caddy --- Apple/sign_in_with_apple.md | 78 +++++++++++++++++++++++++++++++++++++ Caddy/caddy.md | 45 +++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 Apple/sign_in_with_apple.md create mode 100644 Caddy/caddy.md diff --git a/Apple/sign_in_with_apple.md b/Apple/sign_in_with_apple.md new file mode 100644 index 0000000..a9ee45b --- /dev/null +++ b/Apple/sign_in_with_apple.md @@ -0,0 +1,78 @@ +# Sign in with Apple + +[What the Heck is Sign In with Apple?](https://developer.okta.com/blog/2019/06/04/what-the-heck-is-sign-in-with-apple) + +## Go to Apple Developer Portal https://developer.apple.com/ + +### Create App ID + +Set Bundler ID - follow apple convention reverse dns styling. For com.example + +Enabled Sign in with Apple capabilities. + +### Create Service ID + +Ensure Sign in with Apple is enabled and configured + +#### Sign in with Apple Configuration + +Choose Primary App ID + +Configure Website URLs - Apple doesn't support localhost + +After finish, you will get `client_id`. Store `client_id` for later use. + +### Private Key + +In Apple Developer dashboard page, go to `Keys`. + +Enable Sign in with Apple + +Configure Sign in with Apple + +After finish, download key and save it safely, you won't be able to redownload this key anymore. Also store `key_id` for later use. + +## Generate Client Secret + +We're using Ruby scripts to generate client secret. + +Install JWT - `gem install jwt` + +Create `client_secret.db` or any name you preferred. + +```rb + +require 'jwt' + +key_file = 'key.txt' +team_id = '' +client_id = '' +key_id = '' + +ecdsa_key = OpenSSL::PKey::EC.new IO.read key_file + +headers = { + 'kid' => key_id +} + +claims = { + 'iss' => team_id, + 'iat' => Time.now.to_i, + 'exp' => Time.now.to_i + 86400*180, + 'aud' => 'https://appleid.apple.com', + 'sub' => client_id, +} + +token = JWT.encode claims, ecdsa_key, 'ES256', headers + +puts token + +``` + +Execute `client_secret.db` - `ruby client_secret.rb` + +## Integrate with Laravel + +https://socialiteproviders.com/Apple/#installation-basic-usage + +https://bannister.me/blog/generating-a-client-secret-for-sign-in-with-apple-on-each-request \ No newline at end of file diff --git a/Caddy/caddy.md b/Caddy/caddy.md new file mode 100644 index 0000000..bf551ee --- /dev/null +++ b/Caddy/caddy.md @@ -0,0 +1,45 @@ +# Caddy + +## Cloudflare + +Ensure SSL/TLS encryption is set to full mode + +## Install + +https://caddyserver.com/docs/install#debian-ubuntu-raspbian + +After installation, run `caddy stop`. This is to ensure there is no port is in use. + +## Caddyfile + +Most of my project is Laravel and it is much easier to use Caddyfile to store all neccessary configuration. + +```Caddyfile + +my-website.com { + # Resolve the root directory for the app + root * /var/www/my-website/public + + # Provide Zstd and Gzip compression + encode zstd gzip + + # Allow caddy to serve static files + file_server + + # Enable PHP-FPM + php_fastcgi unix//run/php/php7.4-fpm.sock +} + +``` + +## References + +https://ohdear.app/news-and-updates/how-we-used-caddy-and-laravels-subdomain-routing-to-serve-our-status-pages + +https://laravel-news.com/unlimited-custom-domains-vapor + +https://caddyserver.com/docs/caddyfile-tutorial + +https://jorgeglz.io/blog/setting-up-laravel-applications-with-caddy-2/ + +https://caddy.community/t/serving-tens-of-thousands-of-domains-over-https-with-caddy/11179 From f4540a394e997aa2a90b5ec387f6ad8fda49749f Mon Sep 17 00:00:00 2001 From: adib Date: Mon, 27 Feb 2023 17:39:54 +0800 Subject: [PATCH 3/6] wip --- Git/cheat_sheet.md | 10 ++++++++++ Javascript/readme.md | 9 +++++++++ Laravel/Request/handling_invalid_utf8.md | 13 +++++++++++++ Mysql/Init.md | 3 ++- Sentry/sentry.md | 5 +++++ Ubuntu/file_directory.md | 6 ++++++ Ubuntu/sed.md | 3 ++- 7 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 Javascript/readme.md create mode 100644 Laravel/Request/handling_invalid_utf8.md create mode 100644 Sentry/sentry.md diff --git a/Git/cheat_sheet.md b/Git/cheat_sheet.md index a56632f..c1b4357 100644 --- a/Git/cheat_sheet.md +++ b/Git/cheat_sheet.md @@ -84,6 +84,16 @@ If you want to temporarily go back to it, fool around, then come back to where y `git checkout 0d1d7fc32` +## Restore file from specific commit + +`git restore -s -- afile` + +eg: + +`git restore -s b8d0a496f5767a949a1baa164228d88700e18a49 -- resources/views/home.blade.php` + +[How to retrieve a single file from a specific revision in Git?](https://stackoverflow.com/a/610315) + ## Reference * [How to checkout remote git tag](https://stackoverflow.com/questions/35979642/how-to-checkout-remote-git-tag) diff --git a/Javascript/readme.md b/Javascript/readme.md new file mode 100644 index 0000000..cb93c3a --- /dev/null +++ b/Javascript/readme.md @@ -0,0 +1,9 @@ +# Read Me + +## ES6 + +http://es6-features.org/#Constants + +## Build Tools + +https://esbuild.github.io/ \ No newline at end of file diff --git a/Laravel/Request/handling_invalid_utf8.md b/Laravel/Request/handling_invalid_utf8.md new file mode 100644 index 0000000..cf1c6bd --- /dev/null +++ b/Laravel/Request/handling_invalid_utf8.md @@ -0,0 +1,13 @@ +# Handling invalid utf8 + +An URL with an invalid UTF-8 parameter would be one where a parameter in the URL's query string contains a character that is not valid UTF-8 encoding. + +Here is an example of an URL with an invalid UTF-8 parameter: + +`http://www.example.com/search?q=invalid%C3%28UTF%29` + +In this example, the %C3%28 and %29 sequences in the query string parameter q are not valid UTF-8 characters, and therefore, the entire parameter is considered invalid UTF-8. When processing URLs with query string parameters, it's important to ensure that all parameters are valid UTF-8 to avoid potential security or compatibility issues. + +Laravel validation may allow utf8 to slip in, this may cause unexpected error when we parsing json or when we're running SQL. To avoid this bug we may fix encoding with this plugin: + +`https://doc.nette.org/en/utils/strings#toc-fixencoding` \ No newline at end of file diff --git a/Mysql/Init.md b/Mysql/Init.md index 02a8957..99203bf 100644 --- a/Mysql/Init.md +++ b/Mysql/Init.md @@ -49,4 +49,5 @@ Mysql usage more than 100% ## Reference * [How To Set Up a Remote Database to Optimize Site Performance with MySQL](https://www.digitalocean.com/community/tutorials/how-to-set-up-a-remote-database-to-optimize-site-performance-with-mysql) -* [How To Create a New User and Grant Permissions in MySQL](https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql) \ No newline at end of file +* [How To Create a New User and Grant Permissions in MySQL](https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql) +* [MySQLTuner-perl](https://github.com/major/MySQLTuner-perl) \ No newline at end of file diff --git a/Sentry/sentry.md b/Sentry/sentry.md new file mode 100644 index 0000000..a2cc927 --- /dev/null +++ b/Sentry/sentry.md @@ -0,0 +1,5 @@ +# Sentry + +## Discord Integration + +https://sentrydiscord.dev/ \ No newline at end of file diff --git a/Ubuntu/file_directory.md b/Ubuntu/file_directory.md index 696767a..cb4c115 100644 --- a/Ubuntu/file_directory.md +++ b/Ubuntu/file_directory.md @@ -82,6 +82,12 @@ remove all files and directory including hidden files in first directory level `ls -l -R | grep ^- | wc -l` +## Delete empty directories + +`find . -empty -type d -delete` + +[How do I delete all empty directories in a directory from the command line?](https://askubuntu.com/a/73711) + ## Reference * [Find number of files in folder and sub folders?](https://askubuntu.com/questions/34099/find-number-of-files-in-folder-and-sub-folders) \ No newline at end of file diff --git a/Ubuntu/sed.md b/Ubuntu/sed.md index 2098e50..b1b4f57 100644 --- a/Ubuntu/sed.md +++ b/Ubuntu/sed.md @@ -67,4 +67,5 @@ It is reconmmended to create a backup file when modifying any file. To keep a ba ## Reference * [Sed - An Introduction and Tutorial by Bruce Barnett](https://www.grymoire.com/Unix/Sed.html#uh-0) -* [https://stackoverflow.com/a/60562182](https://stackoverflow.com/a/60562182) \ No newline at end of file +* [https://stackoverflow.com/a/60562182](https://stackoverflow.com/a/60562182) +* [The Basics of Using the Sed Stream Editor to Manipulate Text in Linux](https://www.digitalocean.com/community/tutorials/the-basics-of-using-the-sed-stream-editor-to-manipulate-text-in-linux) \ No newline at end of file From 412697bda19551b0cb5ebdd11b6bbf29a9751aca Mon Sep 17 00:00:00 2001 From: adib Date: Thu, 20 Apr 2023 15:45:18 +0800 Subject: [PATCH 4/6] add mysql partition note --- Apple/sign_in_with_apple.md | 2 +- Mysql/partition.md | 100 ++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 Mysql/partition.md diff --git a/Apple/sign_in_with_apple.md b/Apple/sign_in_with_apple.md index a9ee45b..c933e29 100644 --- a/Apple/sign_in_with_apple.md +++ b/Apple/sign_in_with_apple.md @@ -38,7 +38,7 @@ We're using Ruby scripts to generate client secret. Install JWT - `gem install jwt` -Create `client_secret.db` or any name you preferred. +Create `client_secret.rb` or any name you preferred. ```rb diff --git a/Mysql/partition.md b/Mysql/partition.md new file mode 100644 index 0000000..517d69e --- /dev/null +++ b/Mysql/partition.md @@ -0,0 +1,100 @@ +# Partition + +We're using range by year partition. + +## Create table with partition + +```sql + +CREATE TABLE employees ( + id INT NOT NULL, + fname VARCHAR(30), + lname VARCHAR(30), + hired DATE NOT NULL DEFAULT '1970-01-01', + separated DATE NOT NULL DEFAULT '9999-12-31', + job_code INT, + store_id INT +) +PARTITION BY RANGE ( YEAR(separated) ) ( + PARTITION p0 VALUES LESS THAN (1991), + PARTITION p1 VALUES LESS THAN (1996), + PARTITION p2 VALUES LESS THAN (2001), + PARTITION p3 VALUES LESS THAN MAXVALUE +); + +``` + +## Alter partition on existing table + +```sql + +alter table employees PARTITION by range ( year(separated)) ( + PARTITION p0 VALUES LESS THAN (1991), + PARTITION p1 VALUES LESS THAN (1996), + PARTITION p2 VALUES LESS THAN (2001), + PARTITION p3 VALUES LESS THAN (2005), + PARTITION pMax VALUES LESS THAN MAXVALUE +) + +``` + +this will overwrite any previous partition + +## Add new partition + +```sql + +ALTER TABLE table_name ADD PARTITION (partition_definition); + +``` + +## Remove partition + +```sql + +ALTER TABLE table_name DROP PARTITION partition_name; + +``` + +## Merge partition + +```sql + +ALTER TABLE table_name COALESCE PARTITION partition_name; + +``` + +## Split partition + +```sql + +ALTER TABLE table_name REORGANIZE PARTITION partition_name INTO (partition_definition, partition_definition, ...); + +``` + +example + +```sql + +ALTER TABLE views REORGANIZE PARTITION future INTO ( + PARTITION year2024 VALUES LESS THAN (2024), + PARTITION future VALUES LESS THAN MAXVALUE +); + +``` + +https://github.com/lucabecchetti/laravel-mysql-partition/issues/1#issuecomment-1208883016 + +## View partition info + +```sql + +SHOW CREATE TABLE table_name; + +``` + +```sql + +SELECT * FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME = 'table_name'; + +``` \ No newline at end of file From 4850357c20fee1352652cd313f2ad49bc3060fda Mon Sep 17 00:00:00 2001 From: adib Date: Thu, 24 Aug 2023 16:37:51 +0800 Subject: [PATCH 5/6] update --- Apple/sign_in_with_apple.md | 22 +++++++++++++++++++++- Brew/cheat_sheet.md | 12 +++++++++++- Brew/php.md | 24 ++++++++++++++++++++++++ Php/composer/init.md | 6 +++++- 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/Apple/sign_in_with_apple.md b/Apple/sign_in_with_apple.md index c933e29..784777f 100644 --- a/Apple/sign_in_with_apple.md +++ b/Apple/sign_in_with_apple.md @@ -75,4 +75,24 @@ Execute `client_secret.db` - `ruby client_secret.rb` https://socialiteproviders.com/Apple/#installation-basic-usage -https://bannister.me/blog/generating-a-client-secret-for-sign-in-with-apple-on-each-request \ No newline at end of file +https://bannister.me/blog/generating-a-client-secret-for-sign-in-with-apple-on-each-request + +## Sending email to private Apple email + +When user sign in to your site using Sign In With Apple. They may choose to hide their email using private Apple email. + +This private Apple email will blocked all unauthorized sender. + +To allow our transactional mail service (such as Mailgun) to send email to our users, we need to add our domain, subdomain and email address into "Sign in with Apple for Email Communication". + +Sign in to Apple Developer page, [https://developer.apple.com](https://developer.apple.com). + +Go to Services, [https://developer.apple.com/account/resources/services/list](https://developer.apple.com/account/resources/services/list). + +In the section "Sign in with Apple for Email Communication", click configure button. + +Inside Configuration page, add domain, subdomain and email address in Email Sources section. + +Reference: + +[https://medium.com/@nmpyt21/mandrill-send-to-apple-private-email-e7514f74d8be](Mandrill Send to Apple Private Email) \ No newline at end of file diff --git a/Brew/cheat_sheet.md b/Brew/cheat_sheet.md index 21785db..b5a8f49 100644 --- a/Brew/cheat_sheet.md +++ b/Brew/cheat_sheet.md @@ -14,4 +14,14 @@ example ## Option is removed -[Read more here](https://github.com/Homebrew/homebrew-core/issues/31510) \ No newline at end of file +[Read more here](https://github.com/Homebrew/homebrew-core/issues/31510) + +## Issues + +### You should find replacements for the following formulae: ilmbase php@7.4 + +`brew uses --installed ilmbase` + +`brew uninstall ilmbase` + +[https://apple.stackexchange.com/a/435422](https://apple.stackexchange.com/a/435422) \ No newline at end of file diff --git a/Brew/php.md b/Brew/php.md index 80ea290..a3647ac 100644 --- a/Brew/php.md +++ b/Brew/php.md @@ -69,6 +69,30 @@ After each upgrade, need to reinstall all Php extension manually and update thei https://stackoverflow.com/a/51584213 +## Common Issues + +### dyld: Library not loaded: /usr/local/opt/icu4c/lib + +[https://stackoverflow.com/a/54873233](https://stackoverflow.com/a/54873233) + +``` +brew upgrade icu4c + +brew upgrade // or upgrade all packages + +brew cleanup +``` + +## Error: php@7.4 has been disabled because it is a versioned formula! + +``` +brew tap shivammathur/php +brew install shivammathur/php/php@7.4 +brew link php@7.4 +``` + +[https://stackoverflow.com/a/74856087](https://stackoverflow.com/a/74856087) + ## References * [Php Redis](https://github.com/phpredis/phpredis) diff --git a/Php/composer/init.md b/Php/composer/init.md index ef1d91f..2dfe0ae 100644 --- a/Php/composer/init.md +++ b/Php/composer/init.md @@ -6,7 +6,11 @@ `composer self-update 1.10.13` -## Upgrade to latest version +## Check Global Composer version + +`composer -V` + +## Upgrade Global Composer to latest version `composer self-update` From 03b88a319c43ffd054eb2be0bec9ceecf79e2973 Mon Sep 17 00:00:00 2001 From: adib Date: Fri, 15 Sep 2023 11:53:23 +0800 Subject: [PATCH 6/6] add note about pint and prettier --- Javascript/prettier.md | 56 ++++++++++++++++++++++++++++++++++++++++++ Laravel/pint.md | 15 +++++++++++ 2 files changed, 71 insertions(+) create mode 100644 Javascript/prettier.md create mode 100644 Laravel/pint.md diff --git a/Javascript/prettier.md b/Javascript/prettier.md new file mode 100644 index 0000000..767f577 --- /dev/null +++ b/Javascript/prettier.md @@ -0,0 +1,56 @@ +# Prettier + +Prettier is a opinionated code style fixer for minimalists. It support html, js, css, json and etc. It doesn't support php. + +## Installation + +`yarn add --dev --exact prettier` + +### Config + +create config file + +`node --eval "fs.writeFileSync('.prettierrc','{}\n')"` + +### Ignore + +We may exclude any folders in our project to prevent Prettier to run on them. + +`nano .prettierignore` + +Prettier ignore node_modules folder by default. + +## Blade Support + +Blade file is not supported by Prettier by default. We need to install additional plugin to allow Prettier to support blade. + +`yarn add --dev @shufo/prettier-plugin-blade` + +then inside Prettier config file, we need to update it: + +`nano .prettierrc` + +```json +{ + "plugins": ["@shufo/prettier-plugin-blade", "prettier-plugin-tailwindcss"], + "overrides": [ + { + "files": ["*.blade.php"], + "options": { + "parser": "blade", + "tabWidth": 1 + } + } + ] +} + +``` + +## Usage + +`yarn prettier --write .` + +If blade plugin is installed, we need to change the command: + +`yarn prettier --write resources/**/*.blade.php .` + diff --git a/Laravel/pint.md b/Laravel/pint.md new file mode 100644 index 0000000..8e5242e --- /dev/null +++ b/Laravel/pint.md @@ -0,0 +1,15 @@ +# Laravel Pint + +Laravel Pint is an opinionated PHP code style fixer for minimalists. Pint is built on top of PHP-CS-Fixer and makes it simple to ensure that your code style stays clean and consistent. + +## Installation + +`composer require laravel/pint --dev` + +## Usage + +`./vendor/bin/pint` - run pint for the whole project + +`./vendor/bin/pint sample.php` - run pint for single php file + +`./vendor/bin/pint -v` - run pint in verbose mode \ No newline at end of file