Skip to content

Instantly share code, notes, and snippets.

View gtempesta's full-sized avatar

Giorgio Tempesta gtempesta

View GitHub Profile
@gtempesta
gtempesta / anchors.html
Last active April 11, 2019 16:29
Offset content for anchor navigation in layouts with fixed headers
<style>
/*
Original idea
https://stackoverflow.com/a/13184714/
*/
.anchor{
display: block;
position: relative;
top: -120px; /* this value can be updated */
visibility: hidden;
@gtempesta
gtempesta / get_parameter.php
Last active April 11, 2019 16:21
Turn URL parameter into hash
<script>
// use the `anchor` parameter to change the hash
var newHash = "<?php echo $_GET['anchor']; ?>";
window.location.hash = newHash;
</script>
@gtempesta
gtempesta / reverse_ga_transaction.js
Last active August 10, 2020 14:45
Reverse Enhanced Ecommerce Transaction in Google Analytics
// Reverse purchase in Google Analytics with Enhanced Ecommerce
// Source: https://support.google.com/analytics/answer/1037443?hl=en
var items = [
{
id: 573, // original ID
price: "57000.00", // original price
quantity: "-2500" // negative quantity
},
@gtempesta
gtempesta / timed_loop.js
Created April 11, 2019 15:38
Timed loop: jump to next iteration only if external conditions are met
// run a loop
// that jumps on the next iteration only after an external condition is met
// -> a poller checks on the condition every 100 ms and the iteration goes on only if certain conditions are met
// inspiration ->
// https://medium.com/@eric.stermer/setinterval-simply-put-is-a-timed-loop-652eb54bd5f8
// the `products` variable is defined elsewhere
@gtempesta
gtempesta / test_script_execution.js
Created April 11, 2019 15:21
Run some code only after a script has been executed
// createdObj is an object created by the script
// setup that should run after the script has been executed
var setup = function(){
console.log('the script is on the page and did execute');
console.log(typeof createdObj, 'does it exist?'); // -> function
};
// attach the script to the page
var script = document.createElement("script");
@gtempesta
gtempesta / hover.js
Last active April 11, 2019 15:15
hover state in iOS
// If you need to have a different appearance on hover in iOS
// you have to simulate it by toggling a class on touchstart/touchend
// and then style the element accordingly
// source: https://stackoverflow.com/a/2891155/
$('.hovered-element').on('touchstart touchend', function () {
$(this).toggleClass('touch-hover');
});
@gtempesta
gtempesta / ForceCSSUpdates.php
Last active February 7, 2019 16:49
Force CSS changes to go live in a child theme in Wordpress
<?php
// Enqueue child theme styles (typically in functions.php)
function update_child_theme_styles() {
// Force CSS changes to go live
wp_enqueue_style( '--child-theme-name--',
get_stylesheet_directory_uri() . '/style.css',
array(),
filemtime( get_stylesheet_directory() . '/style.css' ));
}
@gtempesta
gtempesta / SimpleCircle.swift
Created October 10, 2016 13:30
Easiest way to draw a Circle in swift 3.0
import UIKit
import XCPlayground
import PlaygroundSupport
public class SimpleLine: UIView {
public init() {
super.init(frame: CGRect(x: 0, y: 0, width: 480, height: 320))
backgroundColor = UIColor.white
}
@gtempesta
gtempesta / SimpleRectangle.swift
Last active October 10, 2016 13:31
Easiest way to draw a Rectangle in swift 3.0
import UIKit
import XCPlayground
import PlaygroundSupport
public class SimpleLine: UIView {
public init() {
super.init(frame: CGRect(x: 0, y: 0, width: 480, height: 320))
backgroundColor = UIColor.white
}
@gtempesta
gtempesta / SimpleLine.swift
Last active October 10, 2016 13:31
Easiest way to draw a line in swift 3.0
import UIKit
import XCPlayground
import PlaygroundSupport
public class SimpleLine: UIView {
public init() {
super.init(frame: CGRect(x: 0, y: 0, width: 480, height: 320))
backgroundColor = UIColor.white
}