Skip to content

Instantly share code, notes, and snippets.

View nmfzone's full-sized avatar
🍿
I'm hungry

Nabil Muhammad Firdaus nmfzone

🍿
I'm hungry
View GitHub Profile
@nmfzone
nmfzone / Readme.md
Last active February 15, 2021 02:16
Extending Laravel Illuminate\Routing\Router
  1. Extend the Illuminate\Routing\Router to the (for example) App\Illuminate\Routing\Router.
  2. Add method setMiddleware and setMiddlewareGroups to your App\Illuminate\Routing\Router
<?php

namespace App\Illuminate\Routing;

use Illuminate\Routing\Router as BaseRouter;
@nmfzone
nmfzone / TestCommand.php
Created February 6, 2021 19:07
Start http server before Laravel Test
<?php
namespace App\Console\Commands;
use Dotenv\Dotenv;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use RuntimeException;
use Symfony\Component\Process\Exception\ProcessSignaledException;
@nmfzone
nmfzone / index.php
Last active January 19, 2021 00:33
Get Start Date and End Date every weeks in a month with Carbon
<?php
public function getWeeks(int $month, int $year = null): array {
$year = is_null($year) ? Carbon::now()->year : $year;
$date = Carbon::createFromFormat('Y-m', $year . '-' . $month)
->firstOfMonth();
$oDate = $date->copy();
$data = [];
@nmfzone
nmfzone / .phpcs.xml
Last active July 29, 2022 15:42
Intellij IDEA Laravel Configuration
<?xml version="1.0"?>
<ruleset name="Laravel Code Standard" namespace="Laravel\CS\Standard">
<description>Code Standard used for Laravel App</description>
<file>./app</file>
<file>./routes</file>
<exclude-pattern>./bootstrap/*</exclude-pattern>
<exclude-pattern>./config/*</exclude-pattern>
<exclude-pattern>./database/*</exclude-pattern>
@nmfzone
nmfzone / celery-beat-appcom.conf
Last active October 27, 2020 06:34
Django Production Simple Configuration using Supervisor + Gunicorn + Celery + Flower + Pyenv Virtualenv
########## DO NOT INCLUDE THIS ##########
# File Location: /etc/supervisor/conf.d/celery-beat-appcom.conf
#########################################
[program:celery_beat_appcom]
process_name=%(program_name)s
command=/home/johndoe/django-app/celery-beat/run-appcom-celery-beat.sh
startsecs=10
autostart=true
autorestart=true
@nmfzone
nmfzone / letsencrypt.conf
Last active October 27, 2020 06:27
NginX Config for Django + Flower + Letsencrypt
location ^~ /.well-known/acme-challenge/ {
default_type "text/plain";
root /var/www/letsencrypt; # make sure you create this directory
}
@nmfzone
nmfzone / migratefresh.py
Created February 29, 2020 19:33
Django migrate:fresh command
from django.core.management import call_command
from django.core.management.base import BaseCommand
from django.db import connection
class Command(BaseCommand):
help = 'Delete all tables and run all migrations'
def add_arguments(self, parser):
parser.add_argument('--seed', nargs='*', help='Run the DB seeders.')
@nmfzone
nmfzone / Menu.vue
Last active April 13, 2021 14:23
Dropdown Menu using VueJs + TailwindCss
<template>
<ul class="menu">
<vmenu-item
v-for="item in data"
:li-class="liClass"
:li-class-root="liClassRoot"
:link-class="linkClass"
:child-link-class="childLinkClass"
:key="item.id"
:data="item" />
@nmfzone
nmfzone / patch.py
Last active February 4, 2020 03:43
Monkey Patch: Override method without extending class in Python (e.g. Patch method, Override core method)
def override_method(cls, after=True):
def decorator(func):
new_parent_method_name = '_' + func.__name__ + '_parent'
setattr(cls, new_parent_method_name, getattr(cls, func.__name__))
@wraps(func)
def wrapper(self, *args, **kwargs):
if after:
parent_result = getattr(self, new_parent_method_name)(*args, **kwargs)
return func(self, parent_result, *args, **kwargs)
@nmfzone
nmfzone / __init__.py
Last active December 21, 2019 00:29
PositiveBigAutoFileld & PositiveBigIntegerField. Auto Increment Big Integer in Django (mysql)
from django.db.models import fields
__all__ = [
'PositiveBigAutoField', 'PositiveBigIntegerField',
]
class PositiveBigAutoField(fields.AutoField):
def db_type(self, connection):
if 'mysql' in connection.__class__.__module__: