Skip to content

Instantly share code, notes, and snippets.

View w-jerome's full-sized avatar
💻
coding…

Jérôme Wohlschlegel w-jerome

💻
coding…
View GitHub Profile
@w-jerome
w-jerome / copy.js
Created May 17, 2018 11:44
JavaScript — Copying an array
const names = [ 'Jon', 'Jacob', 'Jeff' ]
const copy1 = names.slice()
const copy2 = [].concat(names)
const copy3 = Object.values(names)
const copy4 = [...names]
const copy5 = Array.of(...names)
const copy6 = JSON.parse(JSON.stringify(names))
const copy7 = names.map(i => i)
const copy8 = Object.assign([], names)
@w-jerome
w-jerome / .htaccess
Last active August 31, 2022 00:34
HTACCESS - Tips
# Doc: https://www.askapache.com/htaccess/ssl-example-usage-in-htaccess/#rewrite-http-to-https-no-mod_ssl
RewriteEngine on
# REMOVE TRAILING SLASH
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]+)/(.*)/$ /$1/$2 [L,R=301]
# END REMOVE TRAILING SLASH
# https and www for OVH
@w-jerome
w-jerome / nodejs-uninstall.bash
Created May 3, 2018 16:35
Mac - Uninstall nodejs from OSX Yosemite
# https://gist.github.com/TonyMtz/
# first:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
# To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
# go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
@w-jerome
w-jerome / debounce.js
Last active March 27, 2019 08:42
Javascript — debounce event
function debounce(func, wait, immediate) {
var timeout;
return () => {
var context = this, args = arguments;
var later = () => {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
@w-jerome
w-jerome / listen-text.js
Last active April 13, 2018 12:53
Javascript — Listen text
var text = document.querySelector('.post-content').textContent
var speech = new SpeechSynthesisUtterance();
speech.text = text;
speech.volume = 1;
speech.rate = 1;
speech.pitch = 1;
// Start speak
window.speechSynthesis.speak(speech);
@w-jerome
w-jerome / php.ini
Last active April 13, 2018 12:53
PHP — XDebug
;/Library/Application Support/appsolute/MAMP PRO/conf/php5.6.30.ini
[xdebug]
zend_extension="/Applications/MAMP/bin/php/php5.6.30/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.overload_var_dump=1
xdebug.var_display_max_children=1024
@w-jerome
w-jerome / cursor-position-in-element.html
Last active March 27, 2019 08:42
Javascript — Cursor position in element
<!doctype html>
<html>
<head>
<style>
html {
background: #aaf;
}
body {
margin: 0;
}
@w-jerome
w-jerome / scroll-progression.js
Last active March 27, 2019 08:41
Javascript — Get scroll position
//<div class="scrollometer"></div>
window.onscroll = function() {
// document.body.scrollTop ou document.documentElement.scrollTop va retourner
// le nombre de pixel de scroll effectués depuis le haut de la page.
const scrollFromTop = document.body.scrollTop || document.documentElement.scrollTop;
// Le calcul suivant nous permet de connaitre la hauteur en pixel du noeud
// principal du document HTML, c'est à dire le noeud racine moins la hauteur
// en pixel de la partie affichable actuellement. En gros, le résultat est la
@w-jerome
w-jerome / woocommerce-supported-countries.php
Last active April 13, 2018 12:51
WooCommerce — Get array of supported countries
<?php
if (class_exists('WC_Countries') {
$countries = new WC_Countries();
$countries = $countries->__get('countries');
var_dump($countries); // [code] => name
}
@w-jerome
w-jerome / detect-browser.js
Last active March 27, 2019 08:41
Javascript and PHP — Detect Browser
var browser = (navigator.userAgent.indexOf("Chrome") > -1) ? 'chrome' : (navigator.userAgent.indexOf("Safari") > -1) ? 'safari' : (navigator.userAgent.indexOf("Opera") > -1) ? 'opera' : (navigator.userAgent.indexOf("Firefox") > -1) ? 'firefox' : (navigator.userAgent.indexOf("MSIE") > -1 || navigator.userAgent.indexOf("Trident") > -1) ? 'ie' : 'unknow';