Saturday, May 30, 2026

Set Cookie dan Remove Cookie dengan php vanilla.js

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button type="button" onclick="abc()">SetCookie</button><br/>
    <button type="button" onclick="def()">RemoveCookie</button><br/>
    <?php
        if (isset($_COOKIE['username'])) {
            echo "Username: " . $_COOKIE['username']."<br>";
            $decoded = base64_decode($_COOKIE['username']);
            if($decoded){
                echo $decoded;
            }else{
                echo "gagal";
            }
        } else {
            echo "Cookie tidak ditemukan";
        }
    ?>
</body>
<script>
    function abc(){
        const bbb = 'aqresdtcghxi@gmail.com';
        const ccc = btoa(bbb);
        if(document.cookie = `username=${ccc}`){
            alert('cookie set');
           window.location.reload();
        }else{
            alert('cookie not set');
            window.location.reload();
        }

    }
    function def(){
       document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
       alert('cookie remove');
       window.location.reload();
    }
</script>
</html>

Thursday, April 23, 2026

Chaos Game dan Fraktal dengan PHP

 <?php


$width = 500;
$height = 500;
$image = imagecreatetruecolor($width, $height);

$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);

imagefill($image, 0, 0, $white);

$points = [
    [250, 20],   // atas
    [20, 480],   // kiri bawah
    [480, 480]   // kanan bawah
];

$x = rand(0, $width);
$y = rand(0, $height);

for ($i = 0; $i < 50000; $i++) {

    $randIndex = rand(0, 2);
    $target = $points[$randIndex];

    $x = ($x + $target[0]) / 2;
    $y = ($y + $target[1]) / 2;

    imagesetpixel($image, $x, $y, $black);
}

header("Content-Type: image/png");
imagepng($image);
imagedestroy($image);
?>

Thursday, April 16, 2026

OJO TILE Untuk Mencari Jalan Terpendek (Maps Google Simple cash)

<?php

$grid = [
    ['S', '.', '.', '#', '.'],
    ['#', '#', '.', '#', '.'],
    ['.', '.', '.', '.', '.'],
    ['.', '#', '#', '#', '.'],
    ['.', '.', '.', 'G', '.'],
];

$rows = count($grid);
$cols = count($grid[0]);

$start = [0,0];
$goal = [4,3];

$directions = [
    [1,0], [-1,0], [0,1], [0,-1]
];

// queue untuk BFS
$queue = [];
$queue[] = [$start[0], $start[1], 0]; // row, col, langkah

$visited = [];
$visited[$start[0]][$start[1]] = true;

while (!empty($queue)) {
    [$r, $c, $dist] = array_shift($queue);

    if ($r == $goal[0] && $c == $goal[1]) {
        echo "Jarak terpendek: $dist\n";
        break;
    }

    foreach ($directions as $d) {
        $nr = $r + $d[0];
        $nc = $c + $d[1];

        if ($nr >= 0 && $nr < $rows && $nc >= 0 && $nc < $cols) {
            if (!isset($visited[$nr][$nc]) && $grid[$nr][$nc] != '#') {
                $visited[$nr][$nc] = true;
                $queue[] = [$nr, $nc, $dist + 1];
            }
        }
    }
}

?> 

Saturday, February 7, 2026

Menggunakan Axios dengan vanilla.js


<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Ambil Data API</title>
</head>
<body>
    <h1>Data Mahasiswa</h1>
    <ul id="hasil"></ul>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        let hasil = '';
        axios({
            method:'get',
            url:'https://jsonplaceholder.typicode.com/todos/1',
            responseType: 'json'
        })
        .then((response)=> {
            const users = response.data;
            for(let i = 0; i < users.length; i++){
                hasil += `<li>Username: ${users[i].username}</li>`
            }
            document.getElementById('hasil').innerHTML = hasil;
        });
    </script>
</body>
</html>

Saturday, January 24, 2026

PERCENT_RANK & DENSE_RANK di Mysql / Posgres

 SELECT

c.customer_id,

o.amount,

PERCENT_RANK() OVER (ORDER BY o.amount) AS percent_rank,

DENSE_RANK() OVER (ORDER BY o.amount DESC) AS dense_rank

FROM orders o

LEFT JOIN customers c

ON c.customer_id = o.customer_id;







Wednesday, January 14, 2026

Barcode Generator Vanilla.js dan HTML

 Barcode Generator

Vanilla.js & Html


<img id="barcode"></img>
<p><button onclick="download()">Download</button></p>

<!-- Load Library -->
<script src="https://cdn.jsdelivr.net/npm/jsbarcode@3.11.5/dist/JsBarcode.all.min.js"></script>

<script>

    window.addEventListener("load", async () => {
        await loadBarcode();
    })

    function loadBarcode() {
        JsBarcode("#barcode", "1234567890", {
            format: "CODE128",
            lineColor: "#000",
            width: 2,
            height: 40,
            displayValue: true
        });
    }

    function download() {
        const image = document.getElementById("barcode");
        const rand = (Math.random() * 134536348674647387);
        const a = document.createElement('a');
        document.body.appendChild(a);
        a.href = image.src;
        a.download = rand + ".png";
        a.click();
        document.body.removeChild(a);
    }
</script>

Friday, January 9, 2026

Create Capture Screen with Van

1.index.html

ml

<!DOCTYPE html>
<html>
<head>
  <title>Screen Select to Base64</title>
  <style>
    body { font-family: Arial; }
    #overlay {
      position: fixed;
      top: 0; left: 0;
      width: 100vw; height: 100vh;
      cursor: crosshair;
      background: rgba(0,0,0,0.2);
      display: none;
    }
    #selection {
      position: absolute;
      border: 2px dashed red;
      background: rgba(255,0,0,0.2);
    }
  </style>
</head>
<body>

<button onclick="startCapture()">Capture Screen</button>
<button onclick="downloadImage()">Download</button>

<video id="video" autoplay style="display:none;"></video>
<canvas id="canvas" style="display:none;"></canvas>

<div id="overlay">
  <div id="selection"></div>
</div>

<script src="screen.js"></script>
</body>
</html>

2. screen.js

const video = document.getElementById('video');
const canvas = document.getElementById('canvas');
const overlay = document.getElementById('overlay');
const selection = document.getElementById('selection');

let startX, startY, endX, endY;
let base64Image = null;

/* 1. Capture Screen */
async function startCapture() {
  const stream = await navigator.mediaDevices.getDisplayMedia({
    video: { cursor: "always" }
  });

  video.srcObject = stream;
  video.onloadedmetadata = () => {
    video.play();
    overlay.style.display = 'block';
  };
}

/* 2. Select Area */
overlay.addEventListener('mousedown', e => {
  startX = e.clientX;
  startY = e.clientY;

  selection.style.left = startX + 'px';
  selection.style.top = startY + 'px';
  selection.style.width = 0;
  selection.style.height = 0;

  overlay.addEventListener('mousemove', onMouseMove);
});

overlay.addEventListener('mouseup', e => {
  endX = e.clientX;
  endY = e.clientY;

  overlay.removeEventListener('mousemove', onMouseMove);
  overlay.style.display = 'none';

  cropImage();
});

function onMouseMove(e) {
  const width = e.clientX - startX;
  const height = e.clientY - startY;

  selection.style.width = Math.abs(width) + 'px';
  selection.style.height = Math.abs(height) + 'px';
  selection.style.left = Math.min(startX, e.clientX) + 'px';
  selection.style.top = Math.min(startY, e.clientY) + 'px';
}

/* 3. Crop to Canvas */
function cropImage() {
  const scaleX = video.videoWidth / window.innerWidth;
  const scaleY = video.videoHeight / window.innerHeight;

  const x = Math.min(startX, endX) * scaleX;
  const y = Math.min(startY, endY) * scaleY;
  const width = Math.abs(endX - startX) * scaleX;
  const height = Math.abs(endY - startY) * scaleY;

  canvas.width = width;
  canvas.height = height;

  const ctx = canvas.getContext('2d');
  ctx.drawImage(video, x, y, width, height, 0, 0, width, height);

  base64Image = canvas.toDataURL('image/png');
  console.log(base64Image);
}

/* 4. Download */
function downloadImage() {
  if (!base64Image) {
    alert("Belum ada gambar!");
    return;
  }

  const a = document.createElement('a');
  a.href = base64Image;
  a.download = 'capture.png';
  a.click();
}


Set Cookie dan Remove Cookie dengan php vanilla.js

< html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport...