Skip to content

Instantly share code, notes, and snippets.

View full-sized avatar
👀
whoopss

ilhamgusti ilhamgusti

👀
whoopss
View GitHub Profile
@ilhamgusti
ilhamgusti / openapi.yaml
Last active July 1, 2023 12:57
openapi - open meteo
View openapi.yaml
openapi: 3.0.0
info:
title: Open-Meteo APIs
description: 'Open-Meteo offers free weather forecast APIs for open-source developers and non-commercial use. No API key is required.'
version: '1.0'
contact:
name: Open-Meteo
url: https://open-meteo.com
email: info@open-meteo.com
license:
@ilhamgusti
ilhamgusti / poc.js
Created January 13, 2023 06:42
sync player, nobar tanpa restream / re-broadcast video (proof of concept)
View poc.js
// get current existing video element
const video = document.querySelector('video');
// catch seeked event
video.addEventListener('seeked', (event) => {
// TODO: checking position time seek.
// send/broadcast seeking time to websocket
console.log('Video found the playback position it was looking for.');
});
@ilhamgusti
ilhamgusti / hotkey-utilities.js
Created August 6, 2022 00:27
utility to handle hotkeys
View hotkey-utilities.js
export function parseHotkey(hotkey) {
const keys = hotkey
.toLowerCase()
.split('+')
.map((part) => part.trim());
const modifiers = {
alt: keys.includes('alt'),
ctrl: keys.includes('ctrl'),
@ilhamgusti
ilhamgusti / hashchange.js
Created August 2, 2022 18:45
subscribing hash change
View hashchange.js
if ("onhashchange" in window) {
window.onhashchange = function () {
alert(window.location.hash);
}
}
else {
var prevHash = window.location.hash;
window.setInterval(function () {
if (window.location.hash != prevHash) {
prevHash = window.location.hash;
@ilhamgusti
ilhamgusti / index.html
Last active June 14, 2022 14:49
html shortener uhuy
View index.html
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Workers - Link Shortener</title>
</head>
<body>
<h1>Workers Link Shortener</h1>
View browserless_get_holiday_indonesia.js
// Full TypeScript support for both puppeteer and the DOM
export default async ({ page }: { page: Page }) => {
// Full puppeteer API is available
const url = 'https://holidayapi.com/countries/id/2025';
await page.goto(url, {waitUntil: 'networkidle0'});
const data = await page.evaluate(()=>{
const query = (selector, context) => Array.from(context.querySelectorAll(selector));
@ilhamgusti
ilhamgusti / mutableSet.js
Created April 28, 2022 08:11
writing mutable object safely
View mutableSet.js
/**
*
* @param o Object to mutate
* @param ks array of keys, or string of keys
* @param v value to assign
* @param sep custom separator if keys is string. ex: ks:"INIxxADALAHxxKEY", sep is: "xx"
*/
function mutableSet(o, ks, v, sep = '.') {
ks.split && (ks=ks.split(sep));
let i=0, l=ks.length, t=o, x, k;
@ilhamgusti
ilhamgusti / whilePromise.js
Created January 24, 2022 04:47
while promise with condition
View whilePromise.js
export default async function whilePromise(action, condition) {
const result = await action();
if (condition(result)) {
return whilePromise(action, condition);
}
}
@ilhamgusti
ilhamgusti / useDelay.js
Created January 10, 2022 03:40
hooks for delay
View useDelay.js
export function useDelay(time = 1000) {
return React.useCallback(async () => {
return await new Promise((resolve) => {
setTimeout(resolve, time);
});
}, [time]);
}
//usage
export default function App() {
@ilhamgusti
ilhamgusti / useForm.js
Created January 7, 2022 15:43
hooks for handle form input
View useForm.js
import { useState } from "react";
function getInputOnChange(setValue) {
return (val) => {
if (!val) {
setValue(val);
} else if (typeof val === "function") {
setValue(val);
} else if (typeof val === "object" && "nativeEvent" in val) {
const { currentTarget } = val;