Skip to content

Instantly share code, notes, and snippets.

View rafirh's full-sized avatar
🎯
Focusing

Muhammad Rafi Rahman Habibi rafirh

🎯
Focusing
View GitHub Profile
const int smokeSensorPin = A0;
const int buzzerPin = 9;
const int currentLevel = 0;
void setup() {
Serial.println("Running ...");
pinMode(buzzerPin, OUTPUT);
pinMode(smokeSensorPin, INPUT);
Serial.begin(9600);
@rafirh
rafirh / Auth.ts
Created July 17, 2023 03:00
- AuthException.ts in App/Exceptions
import { GuardsList } from '@ioc:Adonis/Addons/Auth'
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import AuthException from 'App/Exceptions/AuthException'
/**
* Auth middleware is meant to restrict un-authenticated access to a given route
* or a group of routes.
*
* You must register this middleware inside `start/kernel.ts` file under the list
* of named middleware.
@rafirh
rafirh / Auth.ts
Created July 17, 2023 03:00
-> AuthException.ts in App/Exceptions
import { GuardsList } from '@ioc:Adonis/Addons/Auth'
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import AuthException from 'App/Exceptions/AuthException'
/**
* Auth middleware is meant to restrict un-authenticated access to a given route
* or a group of routes.
*
* You must register this middleware inside `start/kernel.ts` file under the list
* of named middleware.
@rafirh
rafirh / Auth.ts
Last active July 17, 2023 03:07
AuthException.ts in App/Exceptions | Auth.ts in App/Middleware | kernel.ts in start
import { GuardsList } from '@ioc:Adonis/Addons/Auth'
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import AuthException from 'App/Exceptions/AuthException'
/**
* Auth middleware is meant to restrict un-authenticated access to a given route
* or a group of routes.
*
* You must register this middleware inside `start/kernel.ts` file under the list
* of named middleware.
@rafirh
rafirh / ecosystem.config.js
Created July 17, 2023 07:24
Ecosytem Config Example
module.exports = {
apps: [{
name: 'app-name',
script: 'build/server.js',
autorestart: true,
watch: false,
max_memory_restart: '2G',
env_development: {
COMMON_VARIABLE: 'true',
PORT: 3000,
@rafirh
rafirh / server-name.com.conf
Created July 17, 2023 08:34
NGINx Conf Example
server {
server_name <app-domain>;
access_log /var/log/nginx/<app-name>.access.log;
error_log /var/log/nginx/<app-name>.error.log;
location / {
include proxy_params;
proxy_pass http://0.0.0.0:<app-port>;
proxy_set_header Host $host;
proxy_set_header X-Forwared-Proto $scheme;
@rafirh
rafirh / Role.ts
Created July 17, 2023 08:42
Role.ts (App/Middleware) | kernel.ts (start)
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import AuthException from 'App/Exceptions/AuthException'
import AccountService from 'App/Services/User/AccountService'
export default class Role {
service = new AccountService()
public async handle({ auth }: HttpContextContract, next: () => Promise<void>, rule) {
const roles = rule
if (roles.length == 0) {
await next()
@rafirh
rafirh / create_role.sh
Last active July 18, 2023 03:58
PosgreSQL Command
CREATE USER <username> EITH ENCRYPTED PASSWORD '<password>';
node ace make:module <Namespace> <ModelName> --endpoint <EndpointName> --soft-delete
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import AuthException from 'App/Exceptions/AuthException'
import dbConfig from 'Config/database'
import Env from '@ioc:Adonis/Core/Env'
import Database from '@ioc:Adonis/Lucid/Database';
export default class SwitchDatabase {
public async handle({ request }: HttpContextContract, next: () => Promise<void>) {
const storeCode = request.header('code-store');