Skip to content

Instantly share code, notes, and snippets.

View nasrulhazim's full-sized avatar
🎯
Focusing

Nasrul Hazim nasrulhazim

🎯
Focusing
View GitHub Profile
@nasrulhazim
nasrulhazim / debug.php
Created December 22, 2021 05:57
A helper to dump sql statement for given query builder in Laravel
​<?php
​use​ ​Illuminate​\​Database​\​Eloquent​\​Builder​;
​if​ (! ​function_exists​(​'dumpSql'​)) {
​    ​function​ ​dumpSql​(​Builder​ ​$​builder​)
​    {
​        ​return​ ​array_reduce​(​$​builder​->​getBindings​(), ​function​ (​$​sql​, ​$​binding​) {
​            ​return​ ​preg_replace​(​'/\?/'​, ​is_numeric​(​$​binding​) ? ​$​binding​ : ​"'"​.​$​binding​.​"'"​, ​$​sql​, ​1​);
@nasrulhazim
nasrulhazim / debug.php
Created September 30, 2021 04:21
A helper to Dump Query Builder SQL Statement with it's Bindings
<?php
use Illuminate\Database\Eloquent\Builder;
if (! function_exists('dumpSql')) {
function dumpSql(Builder $builder)
{
return array_reduce($builder->getBindings(), function ($sql, $binding) {
return preg_replace('/\?/', is_numeric($binding) ? $binding : "'".$binding."'", $sql, 1);
}, $builder->toSql());
@nasrulhazim
nasrulhazim / time_period.php
Created June 20, 2021 03:33
Simple Time Period Helper
<?php
if (! function_exists('time_period')) {
function time_period()
{
// Morning: 6 a.m.-noon
// Afternoon: noon-6 p.m.
// Evening: 6-9 p.m.
$value = (int) date('H');
@nasrulhazim
nasrulhazim / .htaccess
Created June 5, 2021 16:25
Standard .htaccess
# Directory Listing
Options -Indexes
<IfModule mod_security.c>
# Server Information Disclosure
ServerTokens Prod
ServerSignature Off
SecServerSignature " "
</IfModule>
@nasrulhazim
nasrulhazim / UUID.php
Last active February 21, 2021 03:19
Cast UUID for MySQL
<?php
namespace App\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
class UUID implements CastsAttributes
{
/**
* Cast the given value.
@nasrulhazim
nasrulhazim / unit-test.yaml
Created February 11, 2021 17:20
Laravel GitHub Action
name: Unit Test
on:
push:
branches: [ develop ]
pull_request:
branches: [ master, develop ]
jobs:
unit-test:
@nasrulhazim
nasrulhazim / KeyGenerateCommand.php
Created November 29, 2020 22:18
Generate Application Key Command In Lumen
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Console\ConfirmableTrait;
use Illuminate\Encryption\Encrypter;
class KeyGenerateCommand extends Command
{
@nasrulhazim
nasrulhazim / ci.yml
Created November 20, 2020 15:32
GitHub Action - MySQL Service for Laravel with Multiple Databases
name: Unit Test
on:
push:
branches: [develop]
pull_request:
branches: [master, develop]
jobs:
PHPUnit:
@nasrulhazim
nasrulhazim / import-huge-sql.sh
Created October 29, 2020 11:59
Import Large MySQL File
# create prepend sql commands
echo "set autocommit=0;set unique_checks=0;set foreign_key_checks=0;" > prepend.sql
# prepend huge.sql above commands
cat huge.sql >> prepend.sql
# create append sql commands
echo "set autocommit=1;set unique_checks=1;set foreign_key_checks=1;" > append.sql
# prepend huge.sql with append.sql
@nasrulhazim
nasrulhazim / openapi-generator.sh
Created October 29, 2020 02:27
Generate Client SDK using Open API Generator
### References
# https://openapi-generator.tech/docs/generators
# https://openapi-generator.tech/docs/usage#examples
# Generate the PHP SDK for Pet Store API
$ openapi-generator generate -g php -o /path/to/sdk/php -i /path/to/petstore.yaml
# Generate the Java SDK for Pet Store API
$ openapi-generator generate -g java -o /path/to/sdk/java -i /path/to/petstore.yaml