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 = {}",
"",
@DWboutin
DWboutin / directUploadToS3.js
Created March 31, 2019 22:33
Direct image url to S3 wiht axios and nodejs
import AWS from 'aws-sdk';
import stream from 'stream'
import axios from 'axios';
export default async (url, filename, callback) => {
const s3 = new AWS.S3({ params: { Bucket: process.env.STATIC_MAPS_BUCKET }});
let contentType = 'application/octet-stream'
let promise = null
const uploadStream = () => {
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 / web.config
Created January 14, 2014 21:41
web.config GZIP compression Add the configuration shown below in the in web.config file. This configuration setup enable gzip compression on static and on dynamic content.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
<dynamicTypes>
<add mimeType="text/*" enabled="true"/>
<add mimeType="message/*" enabled="true"/>
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="*/*" enabled="false"/>
@DWboutin
DWboutin / functions.php
Created August 18, 2014 14:06
Woocommerce get regular and sale price
<?php
function the_product_price($product){
//get the sale price of the product whether it be simple, grouped or variable
$sale_price = '<span class="new">'.get_post_meta( get_the_ID(), '_price', true).'</span>';
//get the regular price of the product, but of a simple product
$regular_price = get_post_meta( get_the_ID(), '_regular_price', true);
//oh, the product is variable to $sale_price is empty? Lets get a variation price
@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