Skip to content

Instantly share code, notes, and snippets.

@gaspas
gaspas / testing.html
Created September 21, 2023 09:52 — forked from rowanmanning/testing.html
HTML template for testing CSS
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>CSS Testing</title>
</head>
<body id="top">
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
# encoding: utf-8
# @author Filipe Rocha <[email protected]>
# Describe Portugal's Administrative Areas
class DistritoConcelho
# @return [Array] list of [concelho, [distritos]]
def self.list
[
['Aveiro', ['Águeda', 'Albergaria-a-Velha', 'Anadia', 'Arouca', 'Aveiro', 'Castelo de Paiva', 'Espinho', 'Estarreja', 'Santa Maria da Feira', 'Ílhavo', 'Mealhada', 'Murtosa', 'Oliveira de Azeméis', 'Oliveira do Bairro', 'Ovar', 'São João da Madeira', 'Sever do Vouga', 'Vagos', 'Vale de Cambra']],
['Beja', ['Aljustrel', 'Almodôvar', 'Alvito', 'Barrancos', 'Beja', 'Castro Verde', 'Cuba', 'Ferreira do Alentejo', 'Mértola', 'Moura', 'Odemira', 'Ourique', 'Serpa', 'Vidigueira']],
@gaspas
gaspas / inview.js
Last active June 1, 2023 18:49
Intersection Observer API -- detecting visibility of an element
const the_animation = document.querySelectorAll('.animation')
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('scroll-animation')
} else {
entry.target.classList.remove('scroll-animation')
}
@gaspas
gaspas / styles.css
Created May 9, 2023 14:46
Some styles for default tags, ul, ol, blockquote
p,
ul,
ol,
blockquote,
div {
margin-top: 0;
margin-bottom: 20px;
}
ul ul,
@gaspas
gaspas / rewrite_rules.php
Last active March 22, 2023 08:54
Changing All Rewrite Rules
<?
/**
* Example of Changing All Rewrite Rules
* https://wordpress.stackexchange.com/questions/263624/add-rewrite-rules-prefix-everything
*
* @param array $rewrite_rules The compiled array of rewrite rules.
* @return array The compiled array of rewrite rules (altered).
*/
function wpse_263624_rewrite_rules_example( $rewrite_rules ) {
@gaspas
gaspas / wysiwyg-custom-color-swatch.php
Created January 13, 2023 03:07
Wysiwyg in WordPress custom Color Swatch Library
<?php
/*************************************************************/
/* custom color swatches in Wysiwyg */
/***********************************************************/
function my_mce4_options($init) {
$custom_colors = '
"36454f", "Gray",
<?php echo date_i18n("d M Y", strtotime(get_field('inicio'))); ?>
<script async="async" src='https://platform-api.sharethis.com/js/sharethis.js?ver=1.0.3#product=custom-share-buttons'></script>
<div class="share">
<div class="label">
Partilhar:
</div>
<div class="socials">
<span class="st-custom-button social-link social-link--share" data-network="sharethis"></span>
<span class="st-custom-button social-link social-link--whatsapp" data-network="whatsapp"></span>
@gaspas
gaspas / enqueue.php
Created September 29, 2022 07:28 — forked from ricardobrg/enqueue.php
Enqueue scripts in WordPress with defer or async
<?php
// This code is based in Mathew Horne blog post: https://matthewhorne.me/defer-async-wordpress-scripts/
//function to add async attribute
function add_async_attribute($tag, $handle) {
$scripts_to_async = array('my-js-handle-async', 'another-handle-async');
//check if this script is in the array
if (in_array($handle, $scripts_to_async)){
//return with async
return str_replace(' src', ' async="async" src', $tag);
@gaspas
gaspas / update-cart-total.php
Last active May 9, 2023 14:00
Update woo cart
<?
add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
?>