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 / useDetectAppleDevice.ts
Created July 19, 2023 20:52
Detect apple device in React.js
View useDetectAppleDevice.ts
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
View usePrevious.ts
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
View mockCurrentDate.js
jest
.useFakeTimers({ now: currentDate, advanceTimers: true })
.setSystemTime(currentDate)
@DWboutin
DWboutin / ChildrenReversable.tsx
Created March 2, 2023 23:25
Reverse children order with React.js
View ChildrenReversable.tsx
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
View Apollo-server.ts
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
View jestMockFsTyypescript.ts
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
View merged.yml
name: Merged
on:
pull_request:
branches: [main]
types:
- closed
jobs:
is_merged:
View conversion.html
<!DOCTYPE html">
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<title>Exercice Sommatif 2</title>
</head>
<body>
@DWboutin
DWboutin / automatic-join-queue.js
Last active May 5, 2020 16:14
Turnip.exchange automatic join queue
View automatic-join-queue.js
var int = setInterval(function() {
var yourName = "Polle"
var button = document.querySelector('#app > div.view.bg-background.bg-center.col-start-2 > div.grid.gap-2 > div > button')
if(button.disabled === false) {
clearInterval(int)
button.click()
window.focus()
setTimeout(function() {