Skip to content

Instantly share code, notes, and snippets.

View PawelGIX's full-sized avatar

Paweł Gruchociak PawelGIX

View GitHub Profile
@PawelGIX
PawelGIX / convert_to_webp.php
Created March 14, 2024 22:04
PHP convert to WEBP
<?php
/**
* Generate Webp image format
*
* Uses either Imagick or imagewebp to generate webp image
*
* @param string $file Path to image being converted.
@PawelGIX
PawelGIX / presta_add_product_to_cart.md
Last active April 4, 2023 14:29
Prestashop add product to cart JS
function addProduct(id_product, quantity, totalQty, delay)
{
	const token = prestashop.static_token;
	const url = prestashop.urls.pages.cart;
	const query = 'controller=cart&add=1&action=add&ajax=true&token=' + token + '&id_product=' + id_product + '&id_customization=0&qty=' + totalQty;
	var controllerUrl = url.concat(query);
@PawelGIX
PawelGIX / createPwUser.php
Created January 11, 2023 20:17
CreatePwUser
<?php
$u = new User();
$u->of(false);
$u->name = "pawel";
$u->email = "[email protected]";
$u->pass = "";
$u->addRole("superuser");
$u->save();
$u->of(true);
@PawelGIX
PawelGIX / create_wp_admin_user.php
Created July 18, 2022 09:24
Create WP admin user by PHP
<?php
add_action( 'init', function () {
$username = 'admin';
$password = 'password';
$email_address = '[email protected]';
if ( ! username_exists( $username ) ) {
$user_id = wp_create_user( $username, $password, $email_address );
@PawelGIX
PawelGIX / Fix permissions
Last active May 18, 2022 16:28
Fix directory permissions
#!/bin/bash
sudo chown www-data:www-data -R .
sudo find /var/www/html -type d -exec chmod u=rwx,go=rx {} \;
sudo find /var/www/html -type f -exec chmod u=rw,go=r {} \;
sudo find /var/www/html -type d -exec chmod 755 {} \;
sudo find /var/www/html -type f -exec chmod 644 {} \;
@PawelGIX
PawelGIX / archive-git.sh
Created November 16, 2021 22:57
Git archive zip repo
git archive --format zip --output /full/path/to/zipfile.zip master
@PawelGIX
PawelGIX / .htaccess
Last active February 7, 2022 23:04
Serve static assets with an efficient cache policy lighthouse
<IfModule mod_expires.c>
ExpiresActive On
# Images
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
@PawelGIX
PawelGIX / docker kill all
Created July 19, 2020 18:01
docker kill all
docker-compose down
docker network prune
sudo service docker restart
docker-compose up
@PawelGIX
PawelGIX / walidacja numeru konta bankowego
Created June 25, 2020 12:25
walidacja numeru konta bankowego
function NRBvalidatior(nrb)
{
nrb = nrb.replace(/[^0-9]+/g,'');
var Wagi = new Array(1,10,3,30,9,90,27,76,81,34,49,5,50,15,53,45,62,38,89,17,
73,51,25,56,75,71,31,19,93,57);
if(nrb.length == 26) {
nrb = nrb + "2521";
nrb = nrb.substr(2) + nrb.substr(0,2);
var Z =0;