Skip to content

Instantly share code, notes, and snippets.

View Syakhisk's full-sized avatar
💻
most likely on my laptop at the moment

Syakhisk Al-Azmi Syakhisk

💻
most likely on my laptop at the moment
View GitHub Profile
@Syakhisk
Syakhisk / mock-axios.js
Created June 12, 2023 07:57 — forked from cowboy/mock-axios.js
axios mocking via interceptors
import axios from 'axios'
let mockingEnabled = false
const mocks = {}
export function addMock(url, data) {
mocks[url] = data
}
@Syakhisk
Syakhisk / index.js
Last active April 4, 2023 04:31
Stream youtube from express using ytdl
const ytdl = require("ytdl-core");
const express = require("express");
const app = express();
app.get("/", (_req, res) => {
res.sendFile(__dirname + "/index.html");
});
// Handler for '/info/:id' endpoint
app.get("/info/:id", async (req, res) => {
@Syakhisk
Syakhisk / AnimateInOut.jsx
Last active December 3, 2022 12:32
Animation Component with Gsap
//source: https://tweenpages.vercel.app/docs#componentlevel-animation
import React, { useRef, useContext } from "react"
import { gsap } from "gsap"
import { Box } from "theme-ui"
import useIsomorphicLayoutEffect from "./useIsomorphicLayoutEffect"
import { TransitionContext } from "../context/TransitionContext"
const AnimateInOut = ({
children,
@Syakhisk
Syakhisk / Link.jsx
Last active December 3, 2022 12:01
Next Link
@Syakhisk
Syakhisk / debounce.js
Created November 19, 2022 09:37
Debounce javascript function
/*
Will run after timeout (function call will be delayed),
if the function is called again BEFORE the timeout,
then the timeout reset, eg:
CLICK...100ms....CLICK.......500ms.......
^set 1st timeout ^will reset the timeout
.........................................^function called
*/
function debounce(fn, timeout = 500) {
let timer = null
gsap.utils.toArray('.stb_line_single').forEach((line, i) => {
const speed = 200 // (in pixels per second)
const links = line.querySelectorAll("a"),
tl = verticalLoop(links, i ? -speed : speed)
links.forEach(link => {
link.addEventListener("mouseenter", () => gsap.to(tl, {timeScale: 0, overwrite: true}));
link.addEventListener("mouseleave", () => gsap.to(tl, {timeScale: 1, overwrite: true}));
@Syakhisk
Syakhisk / gsap-horizontal-infinite-scroll.js
Created July 26, 2022 08:06
Infinite horizontal scroll gsap
// source: https://codepen.io/GreenSock/pen/jOBBVjr
gsap.utils.toArray('.stb_line_single').forEach((line, i) => {
const links = line.querySelectorAll("a"),
tl = horizontalLoop(links, {
repeat: -1,
speed: 1 + i * 0.5,
reversed: i ? true : false,
paddingRight: parseFloat(gsap.getProperty(links[0], "marginRight", "px")) // otherwise first element would be right up against the last when it loops. In this layout, the spacing is done with marginRight.
});
links.forEach(link => {
@Syakhisk
Syakhisk / avoid-100vw-overflow.css
Created July 24, 2022 14:33
Avoid 100vw width triggers overflow-x
/*
https://stackoverflow.com/a/23367686/7200504
scrollbars will be included in the vw so the horizontal scroll will be added to allow you to see under the vertical scroll.
*/
.box {
width: 100vw;
height: 100vh;
max-width:100%; /* added */
}
# source: https://superuser.com/a/1035782
# this repo is fairly fast in indo
sudo dnf config-manager --add-repo https://codingflyboy.mm.fcix.net/fedora/linux/releases/36/Everything/x86_64/os/