Skip to content

Instantly share code, notes, and snippets.

View garmjs's full-sized avatar
🏍️
Lover

Armend Gashi garmjs

🏍️
Lover
  • Prishtine
View GitHub Profile
@garmjs
garmjs / type-utils.ts
Created April 27, 2023 21:50
Type Utils for TypeScript from totaltypescript.com
export type Expect<T extends true> = T;
export type ExpectTrue<T extends true> = T;
export type ExpectFalse<T extends false> = T;
export type IsTrue<T extends true> = T;
export type IsFalse<T extends false> = T;
export type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <
T,
>() => T extends Y ? 1 : 2
? true
@garmjs
garmjs / scrollPrevent.js
Created April 21, 2020 23:19
Modal Prevent scroll/remember scroll position on Safari Mobile
useEffect(() => {
if (isActive) {
document.querySelector("body").classList.add("prevent-scroll")
// When the modal is shown, we want a fixed body
const scrollY = document.documentElement.style.getPropertyValue(
"--scroll-y"
)
const body = document.body
body.style.position = "fixed"
body.style.top = `-${scrollY}`
@garmjs
garmjs / clientOnly.js
Last active April 20, 2020 16:43
Gatsby client only | This is helpful if the component you where trying to use doesn't support SSR
import React from "react"
function ClientOnly({ children, ...delegated }) {
const [hasMounted, setHasMounted] = React.useState(false)
React.useEffect(() => {
setHasMounted(true)
}, [])
if (!hasMounted) {
return null
}
@garmjs
garmjs / gatsby.js
Created March 30, 2020 20:54
Gatsby client side only
import React from "react"
function ClientOnly({ children, ...delegated }) {
const [hasMounted, setHasMounted] = React.useState(false)
React.useEffect(() => {
setHasMounted(true)
}, [])
if (!hasMounted) {
return null
}
@garmjs
garmjs / machine.js
Last active July 29, 2022 17:17
Generated by XState Viz: https://xstate.js.org/viz
const loginMachine = Machine({
id: "loginMachine",
initial: "idle",
context: {
loading: false,
data: null
},
states: {
idle: {
on: {
@garmjs
garmjs / graphql.ts
Created November 5, 2019 10:04 — forked from mfellner/graphql.ts
Using Apollo Server in Next.js 9 with API route in pages/api/graphql.ts
import { ApolloServer, gql } from 'apollo-server-micro';
const typeDefs = gql`
type Query {
sayHello: String
}
`;
const resolvers = {
Query: {
@garmjs
garmjs / gist:f1eafd23fe1232ad31dc79974e847bff
Last active November 15, 2019 22:32 — forked from CristinaSolana/gist:1885435
Keeping a fork up to date

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream

git branch --set-upstream-to=upstream/master master

@garmjs
garmjs / useMeasure.js
Created July 3, 2019 11:41 — forked from stolinski/useMeasure.js
useMeasure - taken from React Spring example
import { useRef, useState, useEffect } from 'react'
import ResizeObserver from 'resize-observer-polyfill'
export default function useMeasure() {
const ref = useRef()
const [bounds, set] = useState({ left: 0, top: 0, width: 0, height: 0 })
const [ro] = useState(() => new ResizeObserver(([entry]) => set(entry.contentRect)))
useEffect(() => (ro.observe(ref.current), ro.disconnect), [])
return [{ ref }, bounds]
}
@garmjs
garmjs / just.js
Created January 6, 2019 20:16
Make working scrollMagic and GSAP on Gatsby
// put this on gatsby-node.js file
exports.onCreateWebpackConfig = ({
stage,
rules,
loaders,
plugins,
actions,
}) => {
actions.setWebpackConfig({
resolve: {
@garmjs
garmjs / vscode-sql-template-literal.js
Last active June 18, 2018 18:44
Syntax hilighting of tagged template literals in our JavaScript code
function sql(strings, ...others) {
let out = [strings[0]];
for (let i = 0; i < others.length; i++) {
out.push(others[i], strings[i + 1]);
}
return out.join("");
}
// Example URL: https://marketplace.visualstudio.com/items?itemName=forbeslindesay.vscode-sql-template-literal