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 / download.js
Created September 18, 2020 13:28
Download all images from website (JS + PHP)
var buffer = [];
document.querySelectorAll('img').forEach(function(item) {
if (item.src){
buffer.push( item.src );
}
});
console.log('Total items:', buffer.length );
localStorage.buffer = JSON.stringify(buffer);
// Now grab localStorage.buffer and paste it in PHP
@luckyshot
luckyshot / css-mini-grid.css
Last active April 5, 2022 19:09
CSS Mini-grid
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
@luckyshot
luckyshot / bookmarklets.md
Created February 26, 2021 19:03
Bookmarklets: Useful miscelaneous

CaixaBank

Get total fluctuation to paste in Excel:

let total = '';
document.querySelectorAll('.color--gray500.font--size-90.white_space--nowrap').forEach(function(item){total += "\n" + item.innerHTML.replace('+ ', '').replace('.','').replace(',','.');});
console.log(total)
@luckyshot
luckyshot / db.php
Last active August 4, 2021 04:50
PHP/MySQL (PDO Database) method with named parameters
<?php
/*
PHP/MySQL (PDO) method with named parameters
---------------------------------------------
https://gist.github.com/luckyshot/9477105
Last updated: 12 Sep 17
$config = [
@luckyshot
luckyshot / distance.php
Created September 9, 2020 09:56
PHP distance between two points (flat coordinates 2 XY axis)
<?php
function distance($x1, $y1, $x2, $y2){
return sqrt(
pow(abs($x1 - $x2), 2)
+
pow(abs($y1 - $y2), 2)
);
}
@luckyshot
luckyshot / php-benchmark.php
Last active April 4, 2021 14:04
Simple PHP benchmarking script
<?php
$benchmark_time = microtime(1);
$benchmark_string = '';
function benchmark( $string = ''){
global $benchmark_time, $benchmark_string;
$return = sprintf('%f', microtime(1) - $benchmark_time) . 's ' . $benchmark_string;
$benchmark_time = microtime(1);
$benchmark_string = $string;
return $return;
@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 / example.css
Last active January 15, 2021 09:43
TailWindCSS Color Palette as CSS native variables
html {
--colorIndigo50: #EEF2FF;
color: var(--colorIndigo50);
}
@luckyshot
luckyshot / geoip.php
Last active November 13, 2020 17:58
PHP - Geolocalization by IP address
<?php
define('GEOIP_CACHE_TIME', 5184000); // 5184000 = 60 days
/**
* Returns the country of an IP address
* If IP is cached and less than 2 months old, otherwhise requests it to geoplugin.com API
*
* @string $ip The IP address
* @bool $justcountry If you want the full array or just the country
@luckyshot
luckyshot / cookies.js
Last active May 14, 2020 11:01
Cookie JavaScript object methods
/**
* CRUD cookies
* expires is in Days
*/
var _cookieSet = function( name, value, expires, path, domain, secure )
{
var today = new Date(),
expires_date;
today.setTime( today.getTime() );