Skip to content

Instantly share code, notes, and snippets.

Avatar
🌍
xaviesteve.com

Xavi Esteve luckyshot

🌍
xaviesteve.com
View GitHub Profile
@luckyshot
luckyshot / distance.php
Created Sep 9, 2020
PHP distance between two points (flat coordinates 2 XY axis)
View distance.php
<?php
function distance($x1, $y1, $x2, $y2){
return sqrt(
pow(abs($x1 - $x2), 2)
+
pow(abs($y1 - $y2), 2)
);
}
@luckyshot
luckyshot / laravel-sql-query.php
Created Sep 29, 2020
Laravel - SQL query styles (Eloquent, Raw)
View laravel-sql-query.php
<?php
// Eloquent
$users = Users::select('count(*) as user_count, status')
->where('status', '<>', 1)
->groupBy('status')
->get();
@luckyshot
luckyshot / php-benchmark.php
Last active Apr 4, 2021
Simple PHP benchmarking script
View php-benchmark.php
<?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 / abusecheck.php
Last active Apr 4, 2021
Throttle client requests to avoid DoS attack (scroll down for IP-based)
View abusecheck.php
<?php
/**
ABUSE CHECK
Throttle client requests to avoid DoS attack
*/
session_start();
$usage = array(5,5,5,5,10,20,30,40,50,60,120,180,240); // seconds to wait after each request
if (isset($_SESSION['use_last'])) {
$nextin = $_SESSION['use_last']+$usage[$_SESSION['use_count']];
@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 / hacker-news.css
Last active Mar 17, 2021
Hacker News Dark Theme Mode CSS code
View hacker-news.css
/**
* HackerNews better readability
* Use any Browser extension that lets you add CSS code.
* © XaviEsteve.com
* https://gist.github.com/luckyshot/af6687f8ac3b0dc458818753dccbd412/
*/
/* Home */
html, body {
background: #1C1917;
@luckyshot
luckyshot / google-sheets-scripts.md
Last active Mar 8, 2021
Google Sheets - Useful functions and scripts
View google-sheets-scripts.md

Make sure to use the proper parameter separator (, or ;) in your functions depending on your language settings.

Cell functions

If there's an error then leave cell empty:

IFERROR( formula )

If there's an error then set another value:

@luckyshot
luckyshot / colors.scss
Created Mar 2, 2021
Dieter Rams (Braun) - CSS/SCSS Color Palette
View colors.scss
/**
* Colours taken from Dieter Rams legendary production collection for Braun. Made by Chad Ashley.
* Source: http://blog.presentandcorrect.com/rams-palettes
* Demo: https://xaviesteve.com/pro/colorpalettes/
* Try it: https://xaviesteve.com/pro/sass-palette/
* Compiled by Xavi Esteve
*/
// DR06
@luckyshot
luckyshot / bookmarklets.md
Created Feb 26, 2021
Bookmarklets: Useful miscelaneous
View bookmarklets.md

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 / 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)