Snippet Library

A collection of reusable code fragments, GeoAI configurations, and technical research tips.

search
location_on

Custom Map Icon for Local Business

JavaScript Leaflet Updated Apr 2026

การเพิ่มหมุดแผนที่แบบกำหนดเอง (Custom Icon) บน Leaflet สำหรับแสดงตำแหน่งร้านบนหน้าเว็บไซต์

var cafeIcon = L.icon({
    iconUrl: 'cafe-marker.png',
    iconSize: [38, 38],
    popupAnchor: [0, -15]
});

L.marker([15.244, 104.847], {icon: cafeIcon})
 .addTo(map)
 .bindPopup("<b>I-So-Late Sip and Taste</b><br>Craft Coffee & Spirits.");
timeline

Constant Velocity Trajectory Prediction

Python NumPy Updated Apr 2026

โมเดลทำนายเส้นทางการเคลื่อนที่แบบเส้นตรงเบื้องต้น โดยคำนวณจากตำแหน่งปัจจุบันและความเร็วคงที่

import numpy as np

def predict_trajectory(current_pos, velocity, dt, steps):
    # current_pos: [x, y], velocity: [vx, vy]
    predictions = []
    for i in range(1, steps + 1):
        future_pos = current_pos + velocity * (dt * i)
        predictions.append(future_pos)
    return np.array(predictions)

# Example: 5 steps into the future at 0.1s intervals
path = predict_trajectory(np.array([0, 0]), np.array([5, 2]), 0.1, 5)
cleaning_services

Basic Text Cleaning for RAG Chunking

Python Updated Apr 2026

ฟังก์ชันทำความสะอาดข้อความดิบเพื่อเตรียมข้อมูลสำหรับทำ RAG โดยการตัดช่องว่างส่วนเกินและอักขระพิเศษออก

import re

def clean_text_for_rag(text):
    # Remove extra whitespace and newlines
    text = re.sub(r's+', ' ', text)
    # Remove special characters often found in PDF scrapes
    text = re.sub(r'[^x00-x7F]+', ' ', text)
    return text.strip()

raw_context = "This is a   research papernn section about GeoAI..."
cleaned_context = clean_text_for_rag(raw_context)
view_in_ar

Basic 3D Point Cloud Visualization with Open3D

Python NumPy Updated Apr 2026

การโหลดและแสดงผล Point Cloud (LiDAR) แบบ 3 มิติ โดยใช้ Open3D พร้อมขั้นตอนการลดจำนวนจุดเพื่อให้ประมวลผลได้เร็วขึ้น

import open3d as o3d
import numpy as np

# Load point cloud from file (pcd, ply, xyz)
pcd = o3d.io.read_point_cloud("urban_scene.pcd")

# Downsample for faster rendering
downsampled_pcd = pcd.voxel_down_sample(voxel_size=0.05)

# Visualize with a coordinate frame
o3d.visualization.draw_geometries([downsampled_pcd], 
                                  window_name="LiDAR Scene",
                                  width=800, height=600)
code

Tailwind CSS Glassmorphism Card

CSS Tailwind Updated Apr 2026

ชุดคลาส Tailwind CSS สำหรับสร้างเอฟเฟกต์การ์ดแบบกระจกฝ้า (Glassmorphism) ที่ดูทันสมัย

<div class="bg-white bg-opacity-20 backdrop-blur-lg rounded-xl border border-white border-opacity-30 p-6 shadow-xl">
  <h2 class="text-white font-bold">I-So-Late Specialty</h2>
  <p class="text-white/80">Experience the craft of Ubon Ratchathani.</p>
</div>
storefront

Dynamic Business “Open/Closed” Status

JavaScript Updated Apr 2026

สคริปต์อย่างง่ายสำหรับตรวจสอบเวลาปัจจุบันและแสดงสถานะ "เปิด" หรือ "ปิด" ของร้านตามเวลาที่กำหนด

const now = new Date();
const hour = now.getHours();
const statusElement = document.getElementById('store-status');

// Example: Open from 10:00 to 22:00
if (hour >= 10 && hour < 22) {
    statusElement.innerText = "Open Now";
    statusElement.style.color = "green";
} else {
    statusElement.innerText = "Closed";
    statusElement.style.color = "red";
}
model_training

Freeze CNN Backbone for Transfer Learning

Python Pytorch Updated Apr 2026

โค้ดพื้นฐานสำหรับการ Freeze เลเยอร์ของโมเดล CNN เพื่อทำ Transfer Learning โดยฝึกฝนเฉพาะเลเยอร์สุดท้าย

import torch.nn as nn
from torchvision import models

# Load a pre-trained ResNet model
model = models.resnet50(pretrained=True)

# Freeze all layers in the backbone
for param in model.parameters():
    param.requires_grad = False

# Replace the final layer for your specific task (e.g., 5 classes)
num_ftrs = model.fc.in_features
model.fc = nn.Linear(num_ftrs, 5)
layers

Clip GeoTIFF with Shapefile using GDAL

Python GDAL Updated Apr 2026

ใช้ GDAL Warp ในการตัดข้อมูลราสเตอร์ (เช่น ภาพถ่ายดาวเทียม) ตามขอบเขตของไฟล์ Shapefile

from osgeo import gdal

# Path to input raster and vector mask
input_raster = "input_dem.tif"
mask_shapefile = "boundary.shp"
output_raster = "clipped_output.tif"

# Execute Warp (Clip)
gdal.Warp(output_raster, 
          input_raster, 
          cutlineDSName=mask_shapefile, 
          cropToCutline=True, 
          dstNodata=0)
location_on

Google Maps: Reverse Geocoding

JavaScript Google Maps API Updated Apr 2026

แปลงพิกัดทางภูมิศาสตร์เป็นที่อยู่ที่มนุษย์อ่านออกได้โดยใช้ Google Maps Geocoding API

const geocoder = new google.maps.Geocoder();
const latlng = { lat: 13.7563, lng: 100.5018 };

geocoder.geocode({ location: latlng }, (results, status) => {
    if (status === "OK") {
        if (results[0]) {
            console.log("Address:", results[0].formatted_address);
        } else {
            console.log("No results found");
        }
    } else {
        console.log("Geocoder failed due to: " + status);
    }
});