Skip to content

Instantly share code, notes, and snippets.

View hungthai1401's full-sized avatar
:octocat:
Available For Hire

Thai Nguyen Hung hungthai1401

:octocat:
Available For Hire
View GitHub Profile
@hungthai1401
hungthai1401 / gist:6ceef818fa41988ce8aa6e1403bb78ae
Created July 3, 2024 09:58 — forked from jaxbot/gist:5748513
Block nginx from serving .git directories
location ~ /\.git {
deny all;
}
# or, all . directories/files in general (including .htaccess, etc)
location ~ /\. {
deny all;
}
@hungthai1401
hungthai1401 / copy_redis_key.sh
Created October 18, 2023 03:37 — forked from ZwodahS/copy_redis_key.sh
copy a redis db key to another place (use MIGRATE COPY for v3.0<= redis)
#!/bin/bash
# source http://stackoverflow.com/questions/23222616/copy-all-keys-from-one-db-to-another-in-redis
#set connection data accordingly
source_host=localhost
source_port=6379
source_db=1
target_host=localhost
target_port=6379
target_db=2
@hungthai1401
hungthai1401 / JsonFileDataProviderIterator.php
Created July 14, 2023 03:46 — forked from jehoshua02/JsonFileDataProviderIterator.php
JsonFileDataProviderIterator class for use with PHPUnit @dataProvider annotation.
<?php
class JsonDataProviderIterator implements Iterator
{
protected $position = 0;
protected $array;
public function __construct($test, $namespace)
{
$path = preg_replace('/.php$/', '.data', $test) . '/' . $namespace;
@hungthai1401
hungthai1401 / AnonymousSerialize.php
Created July 6, 2023 10:31
AnonymousSerialize.php
<?php
trait AnonymousSerialize
{
public function serialize()
{
$properties = [];
foreach(get_object_vars($this) as $name => $value) {
$properties[$name] = $value;
}
@hungthai1401
hungthai1401 / pint.json
Created June 20, 2023 03:54
My Laravel Pint configuration
{
"preset": "laravel",
"rules": {
"align_multiline_comment": true,
"array_syntax": true,
"combine_consecutive_issets": true,
"combine_consecutive_unsets": true,
"concat_space": true,
"declare_parentheses": true,
"declare_strict_types": true,
@hungthai1401
hungthai1401 / guzzle_pool_example.php
Created March 21, 2023 07:59 — forked from wzed/guzzle_pool_example.php
GuzzleHttp\Pool example: identifying responses to concurrent async requests
<?php
/*
* Using a key => value pair with the yield keyword is
* the cleanest method I could find to add identifiers or tags
* to asynchronous concurrent requests in Guzzle,
* so you can identify which response is from which request!
*/
$client = new GuzzleHttp\Client(['base_uri' => 'http://httpbin.org']);
@hungthai1401
hungthai1401 / pint.json
Created February 5, 2023 16:13 — forked from JustSteveKing/pint.json
Laravel Pint configuration
{
"preset": "psr12",
"rules": {
"align_multiline_comment": true,
"array_indentation": true,
"array_syntax": true,
"blank_line_after_namespace": true,
"blank_line_after_opening_tag": true,
"combine_consecutive_issets": true,
"combine_consecutive_unsets": true,
@hungthai1401
hungthai1401 / Experimental Docker structure.md
Created November 4, 2022 07:19 — forked from shinsenter/Experimental Docker structure.md
Docker structure for deploying to multiple environments

Beginning

There are many approaches to implementing a reuse of a common preset for Docker services for multiple environments, such as production and local environments.

This makes it possible to ensure the highest consistency for different environments with the same code-base. Implementing reuse of docker compose options also makes it easier to manage them.

I found on github a project called serversideup/spin. They took an approach using a feature called Docker overrides, to change some properties of common services for different environments.

After reading through their documentation, I realized that there are a few real-life cases where this project can not implement (or is difficult to archive).

@hungthai1401
hungthai1401 / nginx.conf
Created February 26, 2022 07:01 — forked from hlubek/nginx.conf
Nginx reverse proxy with caching for Next.js with imgproxy
# Based on https://steveholgado.com/nginx-for-nextjs/
# - /var/cache/nginx sets a directory to store the cached assets
# - levels=1:2 sets up a two‑level directory hierarchy as file access speed can be reduced when too many files are in a single directory
# - keys_zone=STATIC:10m defines a shared memory zone for cache keys named “STATIC” and with a size limit of 10MB (which should be more than enough unless you have thousands of files)
# - inactive=7d is the time that items will remain cached without being accessed (7 days), after which they will be removed
# - use_temp_path=off tells NGINX to write files directly to the cache directory and avoid unnecessary copying of data to a temporary storage area first
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=STATIC:10m inactive=7d use_temp_path=off;
upstream nextjs_upstream {