Skip to content

Instantly share code, notes, and snippets.

View reginpv's full-sized avatar
🏠
Working from home

Gin reginpv

🏠
Working from home
  • Bulacan, Philippines
View GitHub Profile
@reginpv
reginpv / .htaccess
Created December 20, 2018 18:51
Force forwarding slash to uri via .htaccess
# My usecase would be deploying static site generated by Next.js into a shared hosting where generated files are in /out dir
RewriteEngine On
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
@reginpv
reginpv / swipe.js
Created November 18, 2018 22:37
Swipe left and right detection via Javascript
// Originally by: https://gist.github.com/SleepWalker/da5636b1abcbaff48c4d
let touchstartX = 0;
let touchstartY = 0;
let touchendX = 0;
let touchendY = 0;
const gestureZone = document.getElementById('gestureZone');
gestureZone.addEventListener('touchstart', function(event) {
@reginpv
reginpv / Meta.js
Created November 14, 2018 12:38
Next JS Meta information, Facebook meta tags, Twitter cards - React Component
import Head from 'next/head';
const defaults = {
title: ``,
description: ``,
image: ``,
url: ``
}
export default (props)=>(
@reginpv
reginpv / is-in-viewport.js
Created November 6, 2018 18:50
Check if element is in Viewport
isInViewport(el) {
const scroll = window.scrollY || window.pageYOffset
const boundsTop = el.getBoundingClientRect().top + scroll
const viewport = {
top: scroll,
bottom: scroll + window.innerHeight,
}
const bounds = {
top: boundsTop,
bottom: boundsTop + el.clientHeight,
@reginpv
reginpv / best-practice-web-form-layout.txt
Created October 10, 2018 10:43
Best practice web form layout (design and layout, rules to follow for better result)
Tip 1: Multi-step forms
Any forms longer than a few questions are broken up into separate steps so you don’t deter contacts from filling them out.
Tip 2: Only ask for the essentials
Your forms don’t include any fields that you don’t need.
Tip 3: Single file questions
There are no questions side-by-side.
Tip 4: Keep it simple
@reginpv
reginpv / .htaccess
Last active October 9, 2018 19:37
HTACCESS Starter pack (common .htaccess setup)
RewriteEngine On
# Force ssl
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Point everything to /build - e.g. if you want to serve React's build in the root
RewriteRule ^$ /build/ [L]
# Map http://www.site.com/x to /build/x unless there is a x in the web root.
@reginpv
reginpv / index.html
Last active October 8, 2018 21:02
Getting correct height on iOS mobile devices
<div class="element">
Target Element to 100VH
</div>
@reginpv
reginpv / style.css
Last active October 8, 2018 17:43
How to detect mobile landscape via CSS
/**
* Detecting mobile landscape orientation / screen
* 812 iphone x height/width
*/
@media screen and (max-width: 812px) and (orientation:landscape) {
// css rules here
}
@reginpv
reginpv / style.css
Last active October 8, 2018 10:07
Overflow not smooth on iOS Safari
/**
* When you want a class or element to be 100vh or 100% but needs to scroll when needed
* Works ok on Chrome but on iOS Safari returns undesired result of scrolling / slow and not smooth
*/
.element {
overflow-y: scroll; /* has to be scroll, not auto */
-webkit-overflow-scrolling: touch;
}
@reginpv
reginpv / temp.liquid
Created August 25, 2018 06:58
How to check/detect "home page" programmtically in Shopify?
{% if template == 'index' %}
{% comment %}
Is HOME PAGE
{% endcomment %}
{% endif %}