Skip to content

Instantly share code, notes, and snippets.

View kpodemski's full-sized avatar
🏠
Working from home

Krystian Podemski kpodemski

🏠
Working from home
View GitHub Profile
#!/bin/bash
FILES_TO_COMMIT=`git status -s | cut -c4-`
if [[ ! -z $FILES_TO_COMMIT ]]; then
for file in $FILES_TO_COMMIT; do
if [[ "$file" == *.php ]]; then
./vendor/bin/php-cs-fixer fix "$file"
fi
done
@kpodemski
kpodemski / combos.php
Created February 4, 2021 11:56 — forked from farinspace/combos.php
Recursive functions, I can never find exactly what I need in a pinch
<?php
function combos($data, &$all = array(), $group = array(), $val = null, $i = 0) {
if (isset($val)) {
array_push($group, $val);
}
if ($i >= count($data)) {
array_push($all, $group);
} else {
foreach ($data[$i] as $v) {
@kpodemski
kpodemski / extrafieldinwhitelist.php
Created August 28, 2020 11:25
PrestaShop - add your own variable to whitelist
<?php
class ExtraFieldInWhitelist extends Module
{
public function __construct()
{
$this->name = 'extrafieldinwhitelist';
$this->tab = 'front_office_features';
$this->version = '1';
$this->author = 'Krystian Podemski';
@kpodemski
kpodemski / blocklink.php
Last active December 23, 2016 14:08
Example of PrestaShop module override, place this file in override/modules/blocklink/
@kpodemski
kpodemski / Hook.php
Created September 5, 2016 00:29
Probably the solution for a ship2pay aeuc problem
<?php
class Hook extends HookCore
{
/*
* module: shiptopay
* date: 2015-11-09 21:58:42
* version: 2.0
*/
public static function getHookModuleExecList($hook_name = null)
{
@kpodemski
kpodemski / Dispatcher.php
Created September 2, 2016 22:08
Override for Dispatcher.php to allow override ModuleFrontController
<?php
/**
Using:
/override/modules/bankwire/controllers/front/payment.php
class BankwirePaymentModuleFrontControllerOverride extends BankwirePaymentModuleFrontController
*/
if (!defined('_PS_VERSION_'))
exit;
class Dispatcher extends DispatcherCore {
@kpodemski
kpodemski / Tools.php
Created July 8, 2016 12:51
Handling guests user in Token::getToken() in PrestaShop
<?php
public static function getToken($page = true, Context $context = null)
{
if (!$context) {
$context = Context::getContext();
}
if (!Validate::isLoadedObject($context->customer)) {
$unique = $context->cookie->id_guest;
} else {
$unique = $context->customer->id.$context->customer->passwd;
@kpodemski
kpodemski / resize_image.php
Created January 29, 2016 11:02 — forked from janzikan/resize_image.php
PHP: Resize image - preserve ratio of width and height
/**
* Resize image - preserve ratio of width and height.
* @param string $sourceImage path to source JPEG image
* @param string $targetImage path to final JPEG image file
* @param int $maxWidth maximum width of final image (value 0 - width is optional)
* @param int $maxHeight maximum height of final image (value 0 - height is optional)
* @param int $quality quality of final image (0-100)
* @return bool
*/
function resizeImage($sourceImage, $targetImage, $maxWidth, $maxHeight, $quality = 80)
@kpodemski
kpodemski / retina.js
Last active August 29, 2015 14:04
Retina hack-test as bookmarklet
javascript:(function(e,t){function n(e){e+="";var t=e.charAt(0).toUpperCase();return t+e.substr(1)}function u(){var t=i();var r=document.body.style;var u;var a;if(e.devicePixelRatio>1){u=o;e.devicePixelRatio=1}else{u=s;e.devicePixelRatio=2}for(var f in u){a=t?t+n(f):f;r[a]=u[f]}}var r="Webkit Moz Khtml O ms Icab".split(" ");var i=function(){var e="";var t="Transform";var n=document.body.style;for(var i=0,s=r.length;i<s;i++){if(n[r[i]+t]!==void 0){return r[i]}}return e};var s={transform:"scale(2)",transformOrigin:"0 0","overflow-x":"visible!important"};var o={transform:"",transformOrigin:"","overflow-x":"hidden"};if(!this.setInterval){return"Can't copy paste this. https://bugzilla.mozilla.org/show_bug.cgi?id=527530"}var a=setInterval(function(){if(document.body){clearInterval(a);u()}},10)})(window,location)
@kpodemski
kpodemski / Address.php
Created June 5, 2014 11:44
ValidateController example for PrestaShop
<?php
class Address extends AddressCore
{
public function validateController($htmlentities = true)
{
$errors = parent::validateController($htmlentities);
if(Tools::getValue('company', 0))