Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Mike Boutin DWboutin

🎯
Focusing
  • Quebec city
View GitHub Profile
@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() {
View gist:03e60c46ec8b31a83d26fdef76ec7d10
import React from 'react';
import { connect } from 'react-redux';
import { Responsive, WidthProvider } from 'react-grid-layout';
import { changeLayout, changeCurrentBreakpoint, changeWidgetOptions } from '../../actions/dashboard-actions';
import { fetch as fetchLayouts, create as createLayout } from '../../actions/layouts-actions';
import { fetch as fetchChartTypes } from '../../actions/chart-types-actions';
import {
fetch as fetchWidgets,
create as createWidget,
@DWboutin
DWboutin / angular-react-wrapper.ts
Created September 25, 2019 19:16
A minimalist wrapper to integrate React components in Angular with Angular-React
View angular-react-wrapper.ts
import { ReactWrapperComponent } from '@angular-react/core'
import {
ChangeDetectorRef,
Component,
ElementRef,
EventEmitter,
Input,
NgZone,
OnInit,
Output,