Skip to content

Instantly share code, notes, and snippets.

View sajadghawami's full-sized avatar
⌨️

Sajad Ghawami sajadghawami

⌨️
View GitHub Profile
@simonorzel26
simonorzel26 / getVercelProjectLinks.js
Last active March 20, 2024 10:05
Gets all deployed Vercel project links once user is logged in
@Moelf
Moelf / numpy_is_absurr.md
Last active January 24, 2024 22:29
Numpy is absurd.

Numpy is absurd

HN Discussion

I always gripe about Python not having useful (i.e. performant and with adoption) built-in array type and Numpy doesn't distinguish "vector of vector" from "matrix", but this still surprised me.

in is actually intersect?

It seems that Numpy uses intersect logic to check a in b:

@marvinhagemeister
marvinhagemeister / little-vdom-decompiled.js
Created March 8, 2020 14:13
Jason little-vdom decompiled
/* eslint-disable no-unused-vars */
/* eslint-disable no-else-return */
// JSX constructor, similar to createElement()
export const h = (type, props, ...children) => {
return {
type,
// Props will be an object for components and DOM nodes, but a string for
// text nodes
props,
@SebastianHGonzalez
SebastianHGonzalez / useQueryState.ts
Last active April 1, 2024 09:10
useQueryState - query string synchronized use state hook for next.js
import { useState, useEffect } from "react";
import { useRouter } from "next/router";
type IParam = string;
type IValue = string | string[] | number | number[] | null | undefined;
type IState = { [k: string]: IValue };
type IQuery = IState;
type IRoute = string;
function isEmpty(value: IValue): boolean {
@jaydenseric
jaydenseric / useIsMounted.mjs
Created February 21, 2019 06:22
A React hook that tells if the component is mounted.
import React from 'react'
export const useIsMounted = () => {
const ref = React.useRef(false)
const [, setIsMounted] = React.useState(false)
React.useEffect(() => {
ref.current = true
setIsMounted(true)
return () => (ref.current = false)
}, [])
@IcanDivideBy0
IcanDivideBy0 / useCanvas.js
Last active September 28, 2021 03:14
Simple hook for canvas rendering in react
import React from "react";
// Usage
function App() {
const draw = React.useCallback(gl => {
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.clearDepth(1.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
}, []);
const canvasRef = useCanvas(draw, "webgl2");
@mauricedb
mauricedb / Subject under test
Last active December 7, 2023 14:46
Testing stateful React hooks
import { useState } from 'react';
export function useCounter(initial = 0) {
const [count, setCount] = useState(initial);
return [count, () => setCount(count + 1)];
}
@lfades
lfades / Auth.js
Created October 11, 2018 19:06
Next.js Auth implementation: Apollo Server + Passport + Passport-jwt
/**
* server/dataSources/Auth.js
* Auth implementation, it's not really a dataSource so it doesn't need to be here
*/
const { authenticate, createJwt } = require('../lib/passport');
const { ON_HTTPS } = require('../configs');
const ONE_MINUTE = 1000 * 60;
const ONE_DAY = ONE_MINUTE * 60 * 24;
const ONE_MONTH = ONE_DAY * 30;
@ganapativs
ganapativs / iTerm2 + oh-my-zsh + Pure theme + zsh plugins setup.md
Last active April 26, 2024 02:55
iTerm2 + oh-my-zsh + Pure theme + zsh plugins setup

For example, to override the AppBar (https://material-ui-next.com/api/app-bar/) root class we can do the following:

First method (override Material UI classnames):

1 - Add the property classes in the AppBar component:

    <AppBar classes={{root: 'my-root-class'}}