Skip to content

Instantly share code, notes, and snippets.

View DWboutin's full-sized avatar
🎯
Focusing

Mike Boutin DWboutin

🎯
Focusing
  • Quebec city
View GitHub Profile
@DWboutin
DWboutin / typescript.json
Created March 26, 2024 14:23
My VSCode snippets
{
"Redux-toolkit slice": {
"prefix": "reduxSlice",
"body": [
"import { createSlice } from '@reduxjs/toolkit'",
"",
"export type InitialState = {}",
"",
"const initialState: InitialState = {}",
"",
html, body {
background-color: #f2cd37;
}
.container {
width: 1000px;
margin: 0 auto;
}
.logo {
@DWboutin
DWboutin / useDetectAppleDevice.ts
Created July 19, 2023 20:52
Detect apple device in React.js
import { useEffect } from "react"
export function useDetectAppleDevice() {
const isMac = /(Mac|iPhone|iPod|iPad)/i.test(navigator.userAgent)
useEffect(() => {
if (isMac) {
document.documentElement.classList.add("apple-device")
}
}, [isMac])
@DWboutin
DWboutin / usePrevious.ts
Created March 22, 2023 14:17
usePrevious react hook
import { useEffect, useRef } from 'react'
function usePrevious<T>(value: T): T {
const ref = useRef(value)
useEffect(() => {
ref.current = value
}, [value])
return ref.current
@DWboutin
DWboutin / mockCurrentDate.js
Created March 21, 2023 17:34
Mock date with Jest
jest
.useFakeTimers({ now: currentDate, advanceTimers: true })
.setSystemTime(currentDate)
@DWboutin
DWboutin / ChildrenReversable.tsx
Created March 2, 2023 23:25
Reverse children order with React.js
import { Children, FunctionComponent, ReactNode } from "react";
export interface Props {
children: ReactNode;
reverse: boolean;
}
const ChildrenReversable: FunctionComponent<Props> = ({ children, reverse }) => {
const componentChildren = !reverse
? children
@DWboutin
DWboutin / Apollo-server.ts
Created November 8, 2022 15:28
Apollo-server base file for tutorial
import { ApolloServer } from '@apollo/server'
import { startStandaloneServer } from '@apollo/server/standalone'
// The GraphQL schema
const typeDefs = `#graphql
type Query {
hello: String
}
`
@DWboutin
DWboutin / jestMockFsTyypescript.ts
Created October 17, 2022 15:58
Typescript Jest mock FS correctly
jest.mock('fs')
import fs from 'fs'
const mockedFs = fs as jest.Mocked<typeof fs>
describe('fetch', () => {
describe('file exists', () => {
beforeEach(() => {
mockedFs.existsSync.mockImplementation(() => true)
@DWboutin
DWboutin / merged.yml
Created October 14, 2022 17:04
GH Actions when pull request is merged in main
name: Merged
on:
pull_request:
branches: [main]
types:
- closed
jobs:
is_merged: