Skip to content

Instantly share code, notes, and snippets.

Avatar
🌍
xaviesteve.com

Xavi Esteve luckyshot

🌍
xaviesteve.com
View GitHub Profile
@luckyshot
luckyshot / magic-copy.js
Last active May 22, 2020
JavaScript - Add/Append custom text on copy to clipboard
View magic-copy.js
/**
* Magic Copy
* This little script will append some text to the clipboard when a user copies text from the website
*
* WARNING: This feature is an anti-pattern and a bad usability practice in 99% of cases, use only in
* those situations where it can really benefit the user to have a link to the full resource
*/
document.addEventListener('copy', (event) => {
if (document.getSelection().toString().length < 10){ return; }
const pagelink = `\n${document.location.href}`;
@luckyshot
luckyshot / date.js
Last active Jan 15, 2020
JavaScript date output examples
View date.js
// Given a Date object
var d = new Date();
// Full date and time
// Wed Jan 15 2020 17:31:39 GMT+0100 (Central European Standard Time)
var output = d;
// Timestamp
var output = d.getTime()
@luckyshot
luckyshot / 01-laravel-cashier-setup.md
Last active Feb 23, 2021
Laravel Speed Coding Notes and Command Reference
View 01-laravel-cashier-setup.md

Create the MySQL database in: utf8mb4 unicode 520 ci

Virtual Host setup

sudo code /usr/local/etc/httpd/extra/httpd-vhosts.conf (WSL: sudo nano /etc/apache2/sites-available/000-default.conf)

sudo code /etc/hosts

sudo apachectl -k restart (WSL: sudo service apache2 restart)

@luckyshot
luckyshot / apache-commands.sh
Last active Mar 17, 2021
Apache Commands OSX (Local environment)
View apache-commands.sh
# OSX / Linux
sudo apache2ctl -S (tests config)
sudo apachectl -k restart
sudo code /usr/local/etc/httpd/httpd.conf
sudo code /usr/local/etc/httpd/extra/httpd-vhosts.conf
sudo code /etc/hosts
code /usr/local/etc/php/7.2/php.ini
ErrorLog "/usr/local/var/log/httpd/error_log"
@luckyshot
luckyshot / median-average.sql
Last active May 28, 2019
Computing Average/Median value ignoring outliers/extremes (MySQL)
View median-average.sql
-- Exclude outliers while trying to get the average
SELECT AVG(price) FROM transactions WHERE ABS(price - (SELECT AVG(price) FROM transactions) < 3*(SELECT stddev(price) from transactions));
@luckyshot
luckyshot / generate-backups.php
Created Jan 22, 2019
Quick & Simple MySQL database backups using PHP & Gmail
View generate-backups.php
<?php
/* Database Backup to email by Xavi Esteve */
// ======================================
// ======== MODIFY SETTINGS HERE ========
// ======================================
$config = [
// MySQL
'db_host' => 'localhost',
'db_user' => null, // default, used if nothing declared in 'databases'
@luckyshot
luckyshot / paperclips-bot.js
Last active Jan 7, 2019
Universal Paperclips Auto-bot code
View paperclips-bot.js
/**
clearInterval(t);var t = setInterval(function(){run()}, 100);
*/
var run = function(){
// Make paperclip
// Clicks the 'Make paperclip' button, useful at the very beginning of the game
var wire = parseInt(document.querySelector('#wire').innerText);
if (wire > 0){
for (let index = 0; index < 100; index++) {
@luckyshot
luckyshot / readingmode.js
Last active Jun 19, 2020
Bookmarklet: Readability (remove all styling from a website, optimize for reading and scroll to article). Also available as a Chrome Extension: https://chrome.google.com/webstore/detail/readingmode-lightest/peoapnglceoafojobbkpohnojniabmkd
View readingmode.js
javascript:
/*! ReadingMode © Xavi Esteve */
(function(d) {
var el = d.getElementsByTagName("*");
var htmlDiv = d.createElement("div");
var readingModeMenu = d.createElement("div");
var title = d.title;
var rmSettings = {};
/* Remove all event listeners */
@luckyshot
luckyshot / queryselector.js
Created Apr 9, 2018
QuerySelector short-hand
View queryselector.js
$ = function(sel, ctx){return (ctx || document).querySelector(sel)}
$$ = function(sel, ctx){return (ctx || document).querySelectorAll(sel)}
@luckyshot
luckyshot / js-notify.js
Created Feb 23, 2018
Tiny jQuery Notify (notification bubble/alert) in <1KB
View js-notify.js
/*! Tiny jQuery Notify by Xavi Esteve © 2018 MIT */
/*
{
text: string
type: success, error, warning, danger... any CSS class you want to add
}
notify({text: 'Hello world!', type: 'success' });
*/
var timers = [];