Skip to content

Instantly share code, notes, and snippets.

View agungsugiarto's full-sized avatar
:octocat:
On fire

Agung Sugiarto agungsugiarto

:octocat:
On fire
View GitHub Profile
@agungsugiarto
agungsugiarto / events-codeigniter4.md
Last active March 17, 2024 04:53
How to trigger and listen to events with class-based methods in a cool way in CodeIgniter 4

Defining Events

Create class event App\Events\TestEvent::class

<?php

namespace App\Events;

class TestEvent
@agungsugiarto
agungsugiarto / codeigniter3-cors.md
Last active April 14, 2024 15:00
Dealing with CORS in CodeIgniter 3

1. Add a config file named cors.php in the application/config directory.

<?php

defined('BASEPATH') or exit('No direct script access allowed');

$config = [
    /*
 |--------------------------------------------------------------------------
@agungsugiarto
agungsugiarto / BPSController.php
Created September 23, 2022 13:13
Scrap Kode Relasi BPS dengan Kemendagri
<?php
namespace App\Http\Controllers;
use GuzzleHttp\Pool;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\RequestException;
@agungsugiarto
agungsugiarto / script.cmd
Created August 29, 2022 08:12
Rename legacy view codeigniter to laravel blade extention
Get-ChildItem *.php -Recurse | Rename-Item -NewName { $_.Name -replace '.php','.blade.php' }
@agungsugiarto
agungsugiarto / Routes.php
Created August 5, 2021 04:08
CodeIgniter4 better route list
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014-2019 British Columbia Institute of Technology
@agungsugiarto
agungsugiarto / Common.php
Last active September 13, 2020 09:30
Helper factory to easy create database seeder for CodeIgniter4.
if (! function_exists('factory')) {
/**
* Create a factory seeder.
*
* @param Model|object|string $model Instance or name of the model
* @param int|null $count Create factory
* @param array|null $formatters Difine faker factory
* @param array|null $overrides Overriding data to pass to Fabricator::setOverrides()
* @return object|array
*/
@agungsugiarto
agungsugiarto / jwt-expiration.md
Created August 17, 2020 07:00 — forked from soulmachine/jwt-expiration.md
How to deal with JWT expiration?

First of all, please note that token expiration and revoking are two different things.

  1. Expiration only happens for web apps, not for native mobile apps, because native apps never expire.
  2. Revoking only happens when (1) uses click the logout button on the website or native Apps;(2) users reset their passwords; (3) users revoke their tokens explicitly in the administration panel.

1. How to hadle JWT expiration

A JWT token that never expires is dangerous if the token is stolen then someone can always access the user's data.

Quoted from JWT RFC:

@agungsugiarto
agungsugiarto / DB.php
Last active April 13, 2023 14:42
Easy connection to connect database for CodeIgniter 4 application, this class like facade pattern to easy call method with static.
<?php
namespace App\Facades;
use Config\Database;
/**
* @method static void initialize()
* @method static void close()
* @method static mixed persistentConnect()
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
/**
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
@agungsugiarto
agungsugiarto / Voice-Controlled-IoT.md
Created April 17, 2018 13:57 — forked from xmfcx/Voice-Controlled-IoT.md
OK Google, Arduino Uno, ESP8266, Blynk, IFTTT, Google Assistant Integration Tutorial

OK Google, Arduino Uno, ESP8266, Blynk, IFTTT, Google Assistant Integration Tutorial

This is a tutorial to realize following video: https://www.youtube.com/watch?v=PBiOGvJRPqg

Requirements:

  • Android phone Marsmallow or higher or Apple phone (for google assistant)
  • IFTTT app
  • Blynk app
  • Arduino UNO
  • ESP8266 Wifi module