Skip to content

Instantly share code, notes, and snippets.

View azophy's full-sized avatar
🏠
Working from home

Abdurrahman Shofy Adianto azophy

🏠
Working from home
View GitHub Profile
@azophy
azophy / embed.html
Created December 19, 2023 07:37
PoC sharing localstorage antar iframe
<!-- MVP.css quickstart template: https://github.com/andybrewer/mvp/ -->
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="icon" href="https://via.placeholder.com/70x70">
<link rel="stylesheet" href="https://unpkg.com/mvp.css">
<meta charset="utf-8">
@azophy
azophy / index.html
Last active December 19, 2023 05:45
Proof of Concept: draggable placeholder over PDF
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Demo drag & drop over PDF</title>
<script src="https://unpkg.com/interactjs/dist/interact.min.js"></script>
</head>
<body>
<main style="margin:auto;padding:1rem;min-width:600px;max-width:1000px;background:grey">
<h1>test pdf pdf</h1>
@azophy
azophy / howto.md
Last active September 29, 2023 09:24
How to update multiple row based on list of key-val pairs (in MySQL, MariaDB, & PostgreSQL)

How to update multiple row based on list of key-val pairs (in MySQL, MariaDB, & PostgreSQL)

I've encoutered the needs for this technique multiple times. Mostly when the data is generated from other applications, and my only access to the database is via web-based SQL interface such as Adminer or PHPMyAdmin. It seems that currently there are no comprehensive article outlining how to achieve this. So I'll just write my findings here.

Mysql 5.x

as this version doesn't support VALUES clause yet, our only choice is to use the ugly CASE-WHEN syntax:

@azophy
azophy / laravel_as_proxy_tutorial.md
Last active February 19, 2023 15:18
Using laravel as proxy

Using Laravel as Proxy/API Gateway

Last week at my dayjob, I was exploring options for implementing a proxy endpoint for one our external service. One of the stack used in our application is Laravel, so naturally I investigated how to implement a proxy endpoint using it. Turns out its pretty simple a Laravel already included most of the stuff required to built it. This approach should be suitable for many simple use case to avoid overhead of adding new dedicated proxy service such as a full blown API gateway like Traefik or Kong, or if you need custom logic which may be hard to achieve using on-the-shelf solutions.

why

When building application using microservice/service oriented architecture, its common to require connection to external services. This services may be some vendor API such as email provider, payment gateway, or simply internal service that one way or another happen to be in a different networks. Some common use cases:

  • limit access to credential. by usi
@azophy
azophy / benchmark_query.php
Last active January 2, 2023 04:45
Simple PHP Script to benchmark SQL queries against multiple inputs
<?php
/*
PHP PDO is mostly based on tutorials in https://phpdelusions.net/pdo.
*/
// connection configs
$DB_TYPE = getenv('DB_TYPE');
$DB_HOST = getenv('DB_HOST');
$DB_USER = getenv('DB_USER');
$DB_PASS = getenv('DB_PASS');
@azophy
azophy / Dockerfile
Created August 30, 2022 04:22
Minimalist Dockerization for PHP project (Laravel, CodeIgniter, Symphony, etc).
# this base image already contains webserver & php runtime
FROM php:8.1-apache
# setup composer & php extension installer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
# install your PHP extension here
RUN install-php-extensions zip pdo_pgsql
@azophy
azophy / howto.md
Created August 23, 2022 04:52
Setting Redis as Laravel session driver

What need to be configured:

  • config/database.php:
    • redis_url -> could also be setup using env var REDIS_URL
  • config/session.php:
    • driver -> set to redis. or use env var SESSION_DRIVER
  • connection -> set to default. or use env var SESSION_CONNECTION
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;
class AuthController extends Controller
@azophy
azophy / keycloak-setup.sh
Last active August 11, 2022 21:06
Keycloak setup script
#!/bin.sh
# keycloak-setup.sh
# Adapted from : https://keycloak.ch/keycloak-tutorials/tutorial-1-installing-and-running-keycloak/
# basic variables. edit as needed
KCADM="/opt/keycloak/bin/kcadm.sh"
REALM_NAME=test_realm
CLIENT_ID=test_client
USER_NAME=username
USER_PASSWORD=password
@azophy
azophy / docker-compose.yml
Last active August 11, 2022 20:59
Keycloak-Laravel Tutorial
# docker-compose.yml
services:
keycloak:
image: quay.io/keycloak/keycloak:17.0
ports:
- 8080:8080
command: start-dev
volumes:
- .:/app