Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Nasrul Hazim Bin Mohamad nasrulhazim

🎯
Focusing
View GitHub Profile
@nasrulhazim
nasrulhazim / time_period.php
Created Jun 20, 2021
Simple Time Period Helper
View time_period.php
<?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 Jun 5, 2021
Standard .htaccess
View .htaccess
# Directory Listing
Options -Indexes
<IfModule mod_security.c>
# Server Information Disclosure
ServerTokens Prod
ServerSignature Off
SecServerSignature " "
</IfModule>
@nasrulhazim
nasrulhazim / UUID.php
Last active Feb 21, 2021
Cast UUID for MySQL
View UUID.php
<?php
namespace App\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
class UUID implements CastsAttributes
{
/**
* Cast the given value.
@nasrulhazim
nasrulhazim / unit-test.yaml
Created Feb 11, 2021
Laravel GitHub Action
View unit-test.yaml
name: Unit Test
on:
push:
branches: [ develop ]
pull_request:
branches: [ master, develop ]
jobs:
unit-test:
@nasrulhazim
nasrulhazim / KeyGenerateCommand.php
Created Nov 29, 2020
Generate Application Key Command In Lumen
View KeyGenerateCommand.php
<?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 Nov 20, 2020
GitHub Action - MySQL Service for Laravel with Multiple Databases
View ci.yml
name: Unit Test
on:
push:
branches: [develop]
pull_request:
branches: [master, develop]
jobs:
PHPUnit:
@nasrulhazim
nasrulhazim / import-huge-sql.sh
Created Oct 29, 2020
Import Large MySQL File
View import-huge-sql.sh
# 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 Oct 29, 2020
Generate Client SDK using Open API Generator
View openapi-generator.sh
### 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
@nasrulhazim
nasrulhazim / petstore.yaml
Created Oct 29, 2020
Pet Store Open API Specification
View petstore.yaml
swagger: "2.0"
info:
description: "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters."
version: "1.0.0"
title: "Swagger Petstore"
termsOfService: "http://swagger.io/terms/"
contact:
email: "apiteam@swagger.io"
license:
name: "Apache 2.0"
@nasrulhazim
nasrulhazim / MicrosoftTeam.php
Created May 6, 2020
Microsoft Team Transformer from Webhook
View MicrosoftTeam.php
<?php
namespace App\WebhookClient\Transformers;
use App\Contracts\WebhookPayload as Payload;
class MicrosoftTeam
{
public static function transform(Payload $payload): array
{