Skip to content

Commit

Permalink
Merge pull request #8 from devgraduan/master
Browse files Browse the repository at this point in the history
Various Update
  • Loading branch information
adibnoh authored Dec 13, 2023
2 parents 2cef03a + d908e29 commit fb4cf6f
Show file tree
Hide file tree
Showing 19 changed files with 452 additions and 4 deletions.
98 changes: 98 additions & 0 deletions Apple/sign_in_with_apple.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# 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.rb` 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

## 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)
12 changes: 11 additions & 1 deletion Brew/cheat_sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,14 @@ example

## Option is removed

[Read more here](https://github.com/Homebrew/homebrew-core/issues/31510)
[Read more here](https://github.com/Homebrew/homebrew-core/issues/31510)

## Issues

### You should find replacements for the following formulae: ilmbase [email protected]

`brew uses --installed ilmbase`

`brew uninstall ilmbase`

[https://apple.stackexchange.com/a/435422](https://apple.stackexchange.com/a/435422)
24 changes: 24 additions & 0 deletions Brew/php.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected] has been disabled because it is a versioned formula!

```
brew tap shivammathur/php
brew install shivammathur/php/[email protected]
brew link [email protected]
```

[https://stackoverflow.com/a/74856087](https://stackoverflow.com/a/74856087)

## References

* [Php Redis](https://github.com/phpredis/phpredis)
Expand Down
45 changes: 45 additions & 0 deletions Caddy/caddy.md
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions Digital Ocean/spaces.md
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions Git/cheat_sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <SHA1> -- 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)
Expand Down
56 changes: 56 additions & 0 deletions Javascript/prettier.md
Original file line number Diff line number Diff line change
@@ -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 .`

9 changes: 9 additions & 0 deletions Javascript/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read Me

## ES6

http://es6-features.org/#Constants

## Build Tools

https://esbuild.github.io/
13 changes: 13 additions & 0 deletions Laravel/Request/handling_invalid_utf8.md
Original file line number Diff line number Diff line change
@@ -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`
12 changes: 12 additions & 0 deletions Laravel/eloquent/pagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,16 @@ $data->each(function ($job) {
$jobs->setCollection($data);


```

or

```php

$paginator->getCollection()->transform(function ($value) {
// Your code here
return $value;
});


```
17 changes: 17 additions & 0 deletions Laravel/issues.md
Original file line number Diff line number Diff line change
@@ -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)

15 changes: 15 additions & 0 deletions Laravel/pint.md
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion Mysql/Init.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
* [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)
Loading

0 comments on commit fb4cf6f

Please sign in to comment.