Skip to content

Instantly share code, notes, and snippets.

View alfonsusac's full-sized avatar
🏠
Working from home

Alfonsus Ardani alfonsusac

🏠
Working from home
View GitHub Profile
@alfonsusac
alfonsusac / use-mouse.ts
Last active March 7, 2024 15:08
React useMouseEventListener -> useMouse -> useMouseDrag
// Usage
export function Model(
props: {
data: NodeData
onDragEnd: (newPos: Pos) => void
}
) {
const [position, setPosition] = useState(props.data.position)
@alfonsusac
alfonsusac / slide-in-transition.tsx
Last active October 26, 2023 06:01
Component Snippet to allow progressing forward and backward with slide-in animation like in iOS.
function Flow() {
const steps = ['new account', 'enter OTP', 'add pfp', 'add bio...' ] // The names doesn't matter, as long as its an array
const [step, setStep] = useState(0)
const handleNextStep = () => {
if(step < steps.length - 1) // limit max steps
setStep(prev => prev + 1)
}
const handlePrevStep = () => {
@alfonsusac
alfonsusac / visitReactNode.tsx
Last active August 30, 2023 09:35
Function to do inorder traversal on ReactNode
/**
* Function to do inorder traversal on ReactNode
*
* Figma: https://www.figma.com/file/o8BlRzxU0XHllNYEcaJZSC/Learn?type=design&node-id=165%3A194&mode=design&t=K17WgqtrFBvJ28gQ-1
* Gist: https://gist.github.com/alfonsusac/01a9562a3883e196af6c7c7addc06b54
*/
async function visitJSX2(
jsx: ReactNode,
cb: (p: {
primitive?: string | number | boolean,
@alfonsusac
alfonsusac / adjacencyMatrixAndList.c
Created August 24, 2022 12:03
Implementation of adjacency matrix and adjacency list with linked list in C
#include <stdlib.h>
// [0]------[3]
// | \
// | [2]
// | /
// [1]
typedef struct node{
int a;
CREATE TRIGGER Trigger_name -> declraing a trigger with Trigger_name
(AFTER) -> when the trigger will be executed
[ INSERT | UPDATE | DELETE ] -> The operation that can be performed
ON [Table_Name] -> which table to do the operation on
AS
[ Trigger_body ] -> the queries to be executed by trigger
CREATE TRIGGER trigger_name ON ms_customers
AFTER INSERT,UPDATE,DELETE
AS BEGIN