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 / Hide Div When Clicked Outside It
Created March 4, 2020 11:14 — forked from slavapas/Hide Div When Clicked Outside It
Hide Div When Clicked Outside It
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Vanilla Javascript DropDown Menu Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="menu-dropdown">Menu &#9660;</div>
@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 / chrome.py
Created December 31, 2019 12:17
Selenium Chrome Remote WebDriver
from django.core.cache import cache
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
browser_url = cache.get('user_%d.browser_url' % user_id)
is_browser_queued = cache.get('user_%d.browser_queued' % user_id)
if browser_url:
capabilities = DesiredCapabilities.CHROME.copy()
@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__:
@nmfzone
nmfzone / migraterefresh.py
Last active February 29, 2020 19:32
Django migrate:refresh command
from django.apps import apps
from django.apps.config import AppConfig
from django.conf import settings
from django.core.management import call_command
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = 'Reset and re-run all migrations'
@nmfzone
nmfzone / factories.py
Last active December 20, 2019 06:16
Django Database Seeder
import factory
from django.contrib.auth import get_user_model
from django.contrib.auth.hashers import make_password
User = get_user_model()
class UserFactory(factory.django.DjangoModelFactory):
class Meta:
model = User
@nmfzone
nmfzone / .gitignore
Created November 8, 2019 07:14 — forked from infyloop/.gitignore
Full stack BDD testing with Behave+Mechanize+Django
*.pyc
bin/
include/
lib/
@nmfzone
nmfzone / GatewayGuard.php
Last active February 4, 2020 11:53
Example Implementation SSO, CAS like, and SLO in Laravel. Custom Auth Guards for SSO.
<?php
class GatewayGuard implements Guard
{
/**
* Retrieve the access token if exists.
*
* @return string|null
*/
protected function retrieveAccessToken()