This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT setval(pg_get_serial_sequence('table_name_here', 'id'), COALESCE((SELECT MAX(id) + 1 FROM table_name_here), 1), false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
location / { | |
try_files $uri $uri.html $uri/ =404; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ngrok http --region=eu -host-header=rewrite https://domain.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent | |
const isWebkit = (): boolean => { | |
const UA = navigator.userAgent | |
return /\b(iPad|iPhone|iPod)\b/.test(UA) && /WebKit/.test(UA) && | |
!/Edge/.test(UA) && !window.MSStream | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Replaces a set number of spaces in text with non-breaking spaces to prevent widows | |
// Example use in React: <div dangerouslySetInnerHTML={{ __html: preventWidows(text) }} /> | |
export function preventWidows(text: string, spaces: number = 3): string { | |
const regx: RegExp = /\s/g | |
const spacesCount: number = (text.match(regx) || []).length | |
const spacesTarget = spacesCount - spaces | |
let i: number = 0 | |
text = text.replace(regx, match => { | |
i++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener('scroll', () => | |
setTimeout(() => { | |
// Load Fullstory, Intercom, Segment, etc | |
}, 1000), | |
{ once: true } | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This component was coded for an interactive book for mobile devices | |
// (ie: for touch interactions) where each page was a 1080p video with the | |
// dominant colour in the video set as it’s background colour. | |
// All pages are part of a slider (Slick carousel). | |
// Each video has a poster image with the first frame of the video as well | |
// as another poster image with the last frame of the video. When the video | |
// ends and / or the page is turned, the poster for the ended video is swapped | |
// for the end frame version and the video sources are removed and the video | |
// reloaded to force the the device to flush the video from memory. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
// NB: This is demo code just to explain the logic | |
const DynamicSVG = (props) => { | |
static defaultProps = { | |
text: 'This is the default text', | |
colour: '#FF0000', | |
image: '/static/images/default.png', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getTimeLeft($startDate) | |
{ | |
$now = new DateTime(); | |
$then = new DateTime($startDate); | |
$timeLeft = 0; | |
// Only calculate time left if $then is still a future date | |
if ($now < $then) { | |
$difference = $now->diff($then); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Author @CreativForm (on GitHub) | |
Source: https://gist.github.com/jonathanstark/dfb30bdfb522318fc819#gistcomment-2189252 | |
*/ | |
function validate_recaptcha($response){ | |
// Verifying the user's response (https://developers.google.com/recaptcha/docs/verify) | |
$verifyURL = 'https://www.google.com/recaptcha/api/siteverify'; | |
// Collect and build POST data | |
$post_data = http_build_query( |
NewerOlder