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 / 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 / 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 / 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 / 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.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 / walk.js
Created July 26, 2016 09:03
Javascript Regex to replace text NOT in html attributes
walk(document.body);
setTimeout(function() {
walk(document.body);
}, 1000);
function walk(node)
{
// Source: http://is.gd/mwZp7E
var child, next;
@mehdichaouch
mehdichaouch / sf2-clear-cache-without-session.sh
Created July 26, 2016 09:05
Symfony2 clear cache without sessions
#!/bin/bash
find ./var/cache/* -not \( -path "./var/cache/sessions" -prune \) -exec rm -rf {} \;
@mehdichaouch
mehdichaouch / encrypt.php
Created November 15, 2016 09:39
Magento - AES encryption
<?php
$product = $this->getProduct();
// return no link in case of zero night
if (is_null($product->getData('nights'))) {
return '#';
}
$language = Mage::getStoreConfig('general/locale/code');
$country = $dcsInfo->getData('country');
@mehdichaouch
mehdichaouch / Qwant_2_Google_-_Bookmarklet.js
Created November 29, 2016 10:19
Bookmarklet to run Qwant search on Google
(function(){s=document.getElementsByClassName('search_bar__form__input');s[0]?window.open('https://google.com/#q='+s[0].value,'_parent'):alert('You are not on Qwant page dude!')})();
@mehdichaouch
mehdichaouch / Jira_Select_issues_-_Bookmarklet.js
Created November 29, 2016 10:22
Bookmarklet to select Jira issues
(function(){var doc=document;var text=doc.getElementsByClassName('issue-table-container')[0];if(doc.body.createTextRange){/* ms */var range=doc.body.createTextRange();range.moveToElementText(text);range.select();}else if(window.getSelection){/* moz, opera, webkit */var selection=window.getSelection();var range=doc.createRange();range.selectNodeContents(text);selection.removeAllRanges();selection.addRange(range);}})();