Skip to content

Instantly share code, notes, and snippets.

View mehdichaouch's full-sized avatar
🤖
Happiness Developer

Mehdi Chaouch mehdichaouch

🤖
Happiness Developer
View GitHub Profile
@mehdichaouch
mehdichaouch / test.php
Created July 26, 2016 09:00
Magento test file, to code anywhere, test and prototype
<?php
/** Configuration **/
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
ini_set('max_execution_time', 24*3600); // 1800 secondes = 30 minutes
ini_set('memory_limit', '4096M');
/** Set $path with the path of your Magento install **/
$path = realpath(dirname(__FILE__) . '/../../');
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
@mehdichaouch
mehdichaouch / listCookies.js
Last active July 26, 2016 09:11
JavaScript to list cookies
function listCookies() {
var theCookies = document.cookie.split(';');
var aString = '';
for (var i = 1 ; i <= theCookies.length; i++) {
aString += i + ' ' + theCookies[i-1] + "\n";
}
return aString;
}
@mehdichaouch
mehdichaouch / test_with_whitelist_ip.php
Last active September 28, 2016 14:00
PHP Snippet to test code only with white-list IP, without disturbing other people
<?php
// @author : https://gist.github.com/mehdichaouch
/** BEGIN DEV ****************************/
try {
$clientIp = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
$teamIp = array(
'10.71.3.17', //mehcha
'YOUR IP',
@mehdichaouch
mehdichaouch / memory_usage.php
Last active January 14, 2025 14:17
PHP Snippet to get human readable memory usage
<?php
function convert($size)
{
$unit=array('b','kb','mb','gb','tb','pb');
return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
}
convert(memory_get_usage());
@mehdichaouch
mehdichaouch / magento-permissions.sh
Last active September 30, 2018 22:31
Script to fix Magento file permissions
#!/bin/bash
###############################
### Magento Permissions
find . -type f -exec chmod 644 {} \; && find . -type d -exec chmod 755 {} \; && chmod o+w var var/.htaccess includes includes/config.php app/etc && chmod 550 pear && sudo find *.sh -type f -exec chmod 755 {} \;
rm -rf var/cache/*
rm -rf var/session/*
@mehdichaouch
mehdichaouch / pre-commit
Last active July 26, 2016 09:14
Script Git hook which run php-cs-fixer on files to commit
#!/bin/bash
# https://gist.github.com/mardix/3623562
while read -r file;
do
if [[ $file = *.php ]];
then
php-cs-fixer fix "$file" --level=psr2
git add "$file"
@mehdichaouch
mehdichaouch / Data.php
Last active July 26, 2016 09:14
PHP Snippet for Magento - Encrypt / Decrypt cookie
<?php
/**
* Mum ! I want complex cookie
*/
class Bonne_Maman_Helper_Data extends Mage_Core_Helper_Abstract
{
private static $secret = 'What is the answer to Life, the Universe, and Everything'; // Can be also a in conf
@mehdichaouch
mehdichaouch / prepare-commit-msg
Last active July 26, 2016 09:15
Script Git hook which prefix BRANCH name in every COMMIT if this one is like MAG-1234 or SUP-1234. Add also the branch description if define a the end of the commit.
#!/bin/sh
BRANCH_NAME=$(git symbolic-ref --short HEAD)
# Set description with : git branch --edit-description $(git symbolic-ref --short HEAD)
BRANCH_DESCRIPTION=$(git config branch."$BRANCH_NAME".description)
STORY_NUMBER=$(echo $BRANCH_NAME | sed -n 's/\(\(MAG\|SUP\)-[0-9]*\).*/\1/p')
if [ -n "$STORY_NUMBER" ]; then
sed -i.back "1s/^/$STORY_NUMBER : \n/" "$1"
@mehdichaouch
mehdichaouch / README.md
Created July 15, 2015 08:20
Toran proxy

Toran Proxy how to!

Disable CSRF

Apply the snippet :

, array(
    'csrf_protection' => false,
)
@mehdichaouch
mehdichaouch / cache-migration.sh
Last active July 26, 2016 09:19
Script to moves caches and logs in project/var/* (like SF3 new structure)
#!/bin/bash
timestamp=`date +"%Y%m%d-%H%M%S"`
current_dir=$(pwd)
script_dir=$(cd "$(dirname "$0")"; pwd)
project_dir="$script_dir/../../"
current_date=$(date +%Y%m%d-%H%M%S)
echo "Moves of caches and log in project/var/* (like SF3 new structure)"