Skip to content

Instantly share code, notes, and snippets.

@Richard1320
Richard1320 / AxiosErrorParse.ts
Created November 9, 2019 21:13
Axios errors in catch of try catch block
import {AxiosError} from "axios";
export function AxiosErrorParse(err: AxiosError) {
// Error
if (err.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
return {success: false, error: err.response.data.message};
} else if (err.request) {
// The request was made but no response was received
@Richard1320
Richard1320 / isInViewport.js
Created May 3, 2019 23:57
Check if element is in viewport
$.fn.isInViewport = function() {
var win = $(window);
var viewport = {
top: win.scrollTop(),
left: win.scrollLeft(),
};
viewport.right = viewport.left + win.width();
viewport.bottom = viewport.top + win.height();
@Richard1320
Richard1320 / gist:755ef0d2bc04cf6786bcad6ac3ad44b5
Last active March 18, 2019 23:09
Cloudways force https htaccess
# ENSURE HTTPS EVERYWHERE
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@Richard1320
Richard1320 / fileExists.js
Created December 25, 2018 23:48
Check if file exists
function fileExists(url, callback) {
var http = new XMLHttpRequest();
http.open('HEAD', url);
http.onreadystatechange = function() {
if (this.readyState === this.DONE) {
if (this.status !== 404) {
callback();
}
}
};
@Richard1320
Richard1320 / mixins.scss
Last active July 12, 2018 23:38
Real Hover that excludes touch trigger
@mixin realhover() {
html.can-hover &:hover {
@content;
}
}
ul li {
@include realhover {
ul {
display:block;
}
@Richard1320
Richard1320 / trigger-reverse-animations.js
Last active August 8, 2018 22:24
Trigger Reverse Animations
var animateOut = function() {
var animateElements = $('.animated');
var clickLinks = $( 'a[href*="' + window.location.hostname + '"], a[href^="/"]');
var body = $('body');
var classList = [
'bounce','flash','pulse','rubberBand',
'shake','headShake','swing','tada',
'wobble','jello','bounceIn','bounceInDown',
'bounceInLeft','bounceInRight','bounceInUp','bounceOut',
'bounceOutDown','bounceOutLeft','bounceOutRight','bounceOutUp',
@Richard1320
Richard1320 / loop.php
Last active March 9, 2018 18:42
Loop Chunk Wrapper
<div class="block__wrapper__list">
<?php
$count = 1;
$chunk = 5;
while ( $query->have_posts() ) {
if ($count % $chunk == 1) {
?>
<div class="block__wrapper__list__chunk">
@Richard1320
Richard1320 / accordion.html
Last active May 28, 2019 18:02
Accordions
<div class="accordion">
<div class="accordion__header">Title</div>
<div class="accordion__content">Body Copy</div>
</div><!-- accordion wrapper -->