Skip to content

Instantly share code, notes, and snippets.

View luckyshot's full-sized avatar
🌍
xaviesteve.com

Xavi Esteve luckyshot

🌍
xaviesteve.com
View GitHub Profile
@luckyshot
luckyshot / date.js
Last active January 15, 2020 16:51
JavaScript date output examples
// 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 February 23, 2021 19:42
Laravel Speed Coding Notes and Command Reference

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 / median-average.sql
Last active May 28, 2019 14:31
Computing Average/Median value ignoring outliers/extremes (MySQL)
-- 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 January 22, 2019 15:51
Quick & Simple MySQL database backups using PHP & Gmail
<?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 November 4, 2022 18:03
Universal Paperclips Auto-bot code
/**
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 April 4, 2023 05:35
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
javascript:
/*! ReadingMode © Xavi Esteve */
(function (d) {
var el = d.getElementsByTagName("*");
var htmlDiv = d.createElement("div");
var readingModeMenu = d.createElement("div");
var readingModeAlert = d.createElement("div");
var title = d.title;
var rmSettings = {};
@luckyshot
luckyshot / queryselector.js
Created April 9, 2018 09:37
QuerySelector short-hand
$ = function(sel, ctx){return (ctx || document).querySelector(sel)}
$$ = function(sel, ctx){return (ctx || document).querySelectorAll(sel)}
@luckyshot
luckyshot / js-notify.js
Created February 23, 2018 09:10
Tiny jQuery Notify (notification bubble/alert) in <1KB
/*! 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 = [];
@luckyshot
luckyshot / check-disk-space.sh
Created February 21, 2018 13:25
Check Disk Space through SHELL script (cronjob) and send an HTTP request when it reaches the limit
#!/bin/bash
# Check Disk Space and send an HTTP request when it reaches the limit
# Once used space is higher than this limit, the webhook will be triggered (in percentage)
LIMIT='80'
# Stores the percentage of used space
USED=`df . | awk '{print $5}' | sed -ne 2p | cut -d"%" -f1`
# Webhook URL
@luckyshot
luckyshot / multi-language.php
Last active January 26, 2018 00:32
Multi-language system in PHP
<?php
// config.php
$config['language'] = [];
$config['language']['default'] = 'en'; // no file for this language exists, will be just echoed as is
$config['language']['list'] = [
'en' => '🇺🇸 English',
'es' => '🇪🇸 Español',
];