Skip to content

Instantly share code, notes, and snippets.

@tommylinks
tommylinks / vercel.json
Created August 30, 2023 07:22
Vercel subdir deployment config
{
"rewrites": [
{ "source": "/options/:path*", "destination": "https://example.vercel.app/:path*" },
{ "source": "/options/", "destination": "https://example.vercel.app/" },
{ "source": "/(.*)", "destination": "/" }
]
}
@tommylinks
tommylinks / gist:4dc022d52a435b8de63c99fe9b4a4e4c
Created January 5, 2023 11:50
Get array of indexes from length
Array.from({ length: NUMBER}, (_, index) => index + 1)
@tommylinks
tommylinks / gist:3f4fc9654dd84d1b0ca831059241fd59
Created April 13, 2021 14:35
Input type text only numbers allowed (React hooks)
const inputRegex = RegExp(`^\\d*(?:\\\\[.])?\\d*$`)
const escapeRegExp = (string) => {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') // $& means the whole matched string
}
const handleChange = (e) => {
const string = e.target.value
if(inputRegex.test(escapeRegExp(string))) {
setInputTest(string)
var gulp = require('gulp');
var sass = require('gulp-sass');
var connectPHP = require('gulp-connect-php');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var sourcemaps = require('gulp-sourcemaps');
var paths = {
html: ['./**/*.php'],
js: ['./js/*.js']
export default function ({ req, redirect }) {
console.log('starting')
if (req) {
if (req.headers['user-agent'].match(/Insights/gmi) || req.headers['user-agent'].match(/Lighthouse/gmi)) {
console.log('lighthouse detected')
redirect('/page.html')
}
}
}
@tommylinks
tommylinks / Sort array by firstname (alphabetically) in Javascript
Created January 28, 2020 14:31
Sort array by firstname (alphabetically) in Javascript
const users = ["c", "a", "b"]
users.sort((a, b) => a.localeCompare(b)) // ["a", "b", "c"]
//scripts for package.json
// "scripts": {
// "start": "webpack-dev-server --mode development --open",
// "build": "webpack --mode production"
// },
const path = require('path')
const HTMLPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
updateCounter (slick) {
currentSlide = slick.currentSlide + 1
slideCount = slick.slideCount
$('.slider-counter').text(this.currentSlide + '/' + this.slideCount)
}
$('.info-slider').on('init', (e, slick) => {
updateCounter(slick)
})
$('.info-slider').on('afterChange', (e, slick) => {
updateCounter(slick)
// 1
const num = 42
// let result
//
// if (num > 20) {
// result = 'More than 20'
// } else {
// result = 'Less than 20'
// }
<style>
div#comparison {
position: relative;
width: 60vw;
height: 60vw;
max-width: 600px;
max-height: 600px;
overflow: hidden; }
div#comparison figure {
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/photoshop-face-before.jpg);