Skip to content

Instantly share code, notes, and snippets.

@lorepirri
lorepirri / radioDropdownMenu.html
Created April 20, 2017 17:39
Simple snippet of a dropdown menu which acts as a radio button: its label gets updated with the selected value
<!-- show all/online/offline dropdown -->
<div class="btn-group btn-right">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Show All <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="#">Show All</a></li>
<li><a href="#">Online</a></li>
<li><a href="#">Offline</a></li>
</ul>
// how to get the index of the max/min element in an array
let scores = [2, 0, -1, 7, 1];
console.clear();
let scoreIndex = scores.reduce(
(iMax, x, i, arr) => x > arr[iMax] ? i : iMax, 0);
console.log('calc max index', scoreIndex);
@lorepirri
lorepirri / js-es6-block-level-scope.js
Created July 18, 2017 20:14
In Javascript scopes are defined at function level, if declared with var, on the other side es6 let/const define scope at a block level (e.g. in an if-block, or for loop)
console.clear();
if (true) {
let insideJoke = 174; // let used -> block's scope
const anotherInsideJoke = 100; // const used -> block's scope
var thisIsACommonJoke = 42 // var used -> scope to outer scope (global)
}
console.log('thisIsACommonJoke', thisIsACommonJoke); // ok, global scope
console.log('insideJoke', insideJoke); // error: out of scope
@lorepirri
lorepirri / functions.php
Last active May 24, 2020 12:35
How to add a menu in the footer of OnePress WordPress Theme via child theme
<?php
/**
* OnePress Child Theme Functions
*
*/
/**
* Enqueue child theme style
*/
add_action( 'wp_enqueue_scripts', 'onepress_child_enqueue_styles', 15 );