Skip to content

Instantly share code, notes, and snippets.

@sam-ngu
sam-ngu / webpack.mix.js
Last active November 19, 2019 04:04
Laravel Mix + Vuejs Hot reload config
mix.options({
hmrOptions: {
host: 'laravel.dev.local', // site's host name
port: 8080,
}
});
// // fix css files 404 issue
mix.webpackConfig({
// add any webpack dev server config here
@sam-ngu
sam-ngu / laravel-mail-components.blade.php
Created May 21, 2019 00:59
list of laravel mail markdown components
@component('mail::message')
# Introduction
The body of your message.
@component('mail::button', ['url' => ''])
Button Text
@endcomponent
@component('mail::panel')
@sam-ngu
sam-ngu / CollectionHelper.php
Last active September 22, 2023 01:49
Laravel Collection Helper: paginate collection
<?php
namespace App\Helpers\General;
use Illuminate\Container\Container;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Collection;
@sam-ngu
sam-ngu / GenerateSitemap.php
Last active September 22, 2023 01:54
Laravel php artisan generate sitemap command
<?php
namespace App\Console\Commands;
use App\Models\Course;
use Illuminate\Console\Command;
use Spatie\Browsershot\Browsershot;
use Spatie\Crawler\Crawler;
use Spatie\Sitemap\SitemapGenerator;
use Spatie\Sitemap\Tags\Url;
@sam-ngu
sam-ngu / array_merge_preserve.php
Last active October 28, 2019 08:10
PHP: array merge while preserving numeric keys
<?php
/*
Eg. $array1:
array:1 [
3 => array:1 [
"subscription_id" => 27
]
]
@sam-ngu
sam-ngu / arrow_function_comparison1.js
Created November 11, 2019 00:03
JS arrow function demonstration
let clock = {
timerIntervalId: null,
timer: 60, // 60 sec
startTimer: function(){
//
function decrement(){
if(this.timer < 0)
this.stopTimer()
else
this.timer -= 1
@sam-ngu
sam-ngu / promisedemo.js
Last active April 3, 2020 02:57
Demonstration on how Promises work in Javascript
// creating a new promise by instantiating the Promise Class
let somePromise = new Promise(function(resolve, reject){
// the resolve and reject arguments are callback functions to be called.
// resolve: to be called when the promise is successful. We can pass data to it for the subsequent the 'then' method
// reject: to be called when the promise is unsuccessful. Again we can pass data to it for the 'catch' method
try{
// to mimick asynchoronous behaviour,
// trigger the timeout callback in 1 sec
setTimeout(function(){
console.log('hey there 1 sec later.')
@sam-ngu
sam-ngu / asyncpromise.js
Last active April 3, 2020 09:57
Async Demo
// adding the 'async' keyword in front of a function will make it asynchronous.
// JS will automatically turn the output into a Promise
async function sayHello(){
return 'Hello"
}
sayHello().then((response) => {
console.log(response) // expected output: 'Hello'
})
@sam-ngu
sam-ngu / docker-compose.yml
Last active October 10, 2020 05:26
Docker compose example
# we are using the v3.7 syntax to write this docker compose file
version: "3.7"
# define a list
networks:
backend:
# the services section tells docker compose how to run the docker images
# a service can have multiple containers, all based on the same image
services:
@sam-ngu
sam-ngu / laravel_7_mail_markdown_component.blade.php
Last active January 19, 2021 21:48
A quick reference to all Laravel 7 mail markdown components. Source code to https://sam-ngu.medium.com/laravel-7-mail-markdown-components-a1afc18f6efd
@component('mail::message')
# Introduction
The body of your message.
@component('mail::button', ['url' => ''])
Button Text
@endcomponent
@component('mail::panel')