Skip to content

Instantly share code, notes, and snippets.

@celsowhite
celsowhite / section-checker.js
Created May 28, 2020 19:27
Check section visibility as a user scrolls.
/*-----------------------
Offset
---
Get the offset of an element on the page relative to the document.
-----------------------*/
function offset(el) {
const rect = el.getBoundingClientRect(),
scrollTop = window.pageYOffset || document.documentElement.scrollTop;
return { top: rect.top + scrollTop, bottom: rect.bottom + scrollTop };
@celsowhite
celsowhite / acf-local-fields-to-json.php
Created May 22, 2020 14:13
Convert ACF Fields Registered via PHP to JSON
<?php
/*-----------------------------
Notes
- After running the script then remove the "ID" and "_valid" keys from all fields in the json output. These are extraneous and may cause import errors.
Resource - https://dev-notes.eu/2017/01/convert-acf-fields-registered-by-php-to-importable-json-format/
-----------------------------*/
$groups = acf_get_local_field_groups();
.underline-text {
display: inline-block;
position: relative;
text-decoration: none;
/* This is the key. The lines that this border applies to must be 'inline'. */
display: inline;
background-image: linear-gradient(to bottom, transparent 20%, #00e692 21%);
/* This ensures the line appears at the right vertical position on each line. 1em will correspond exactly to the height of the font. */
background-position: 0 1em;
background-repeat: no-repeat;
@celsowhite
celsowhite / proportional_div.html
Last active January 22, 2019 20:58
Example of a proportionally sized div. Div automatically keeps proportions regardless of container width.
<div class="product_card">
<div class="product_image" style="background-image: url('https://celsowhite.com/static/img/about/me.jpg')">
<!-- Important: Any content in this proportional div must be positioned absolute so it adapts to the container proportions. -->
</div>
<div class="product_info">
<h2>Celso</h2>
</div>
</div>
@celsowhite
celsowhite / rewrites.htaccess
Last active August 17, 2018 14:02
Common rewrites I use in projects.
# Force all www to redirect to non-www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]
# Force all http to redirect to https
RewriteEngine On
RewriteCond %{HTTPS} off
@celsowhite
celsowhite / plain_list_sort.js
Created July 10, 2018 22:36
Plain List Sort
// Sort a plain list of names alphabetically.
const people = `
Mike Dobbs
Peace Walker
Adam Vinson
`;
// Convert the list to an array. Splitting on the new line.
@celsowhite
celsowhite / git_tips.md
Last active February 6, 2019 22:20
Helpful Git Tips

Checkout New Branch from previous commit

git checkout -b branchname <sha1-of-commit or HEAD~3>

Rename Remote URL

Mainly used if a remote repository name has changed.

git remote set-url origin {new-url}

@celsowhite
celsowhite / animate_in_view.js
Last active June 29, 2018 15:17
Function to check when an element is in view.
/*=================================
Animate In View
=================================*/
// Elements
const animatedElements = document.querySelectorAll('.animate_in_view');
// Check position of each element on scroll and animate
@celsowhite
celsowhite / notification_bar.html
Last active October 28, 2021 23:53
Dismissible notifcations. Use local storage to allow users to hide notifications on a site. Notification only appears again if they clear their cookies.
<div class="notification_banner dismissible" id="store_locator_notification">
<p>Notification Content</p>
<div class="notification_dismiss_button" data-dismiss="store_locator_notification">
<i class="fas fa-times"></i>
</div>
</div>
@celsowhite
celsowhite / custom_bullets.scss
Created January 16, 2018 19:08
Custom Bullets
/*==================================
Lists
---
General ul and ol elements within wysiwyg content areas having specific bullet or numbered styling.
The below styles create custom bullets and numbered lists. Bullets can be any image or unicode. Numbers can have a specific font style.
==================================*/
ul, ol {
margin: 0;
padding: 0;