Skip to content

Instantly share code, notes, and snippets.

Alban Jubert juban

Block or report user

Report or block juban

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@juban
juban / iOSPNGNormalizer.php
Last active Apr 28, 2019
PHP iOS PNG normalizer. This PHP class can be used to convert an iOS compressed PNG (CgBI format files) back to the standard format. Requires PHP 5.4 or greater. Credit goes to Axel E. Brzostowski for the original Python version of this script: http://www.axelbrz.com.ar/?mod=iphone-png-images-normalizer
View iOSPNGNormalizer.php
<?php
class iOSPNGNormalizer
{
public static function fix($filename, $destfilename = null)
{
try {
$handle = fopen($filename, "rb");
$oldPNG = fread($handle, filesize($filename));
fclose($handle);
@juban
juban / EFastDbAuthManager.php
Last active Jan 4, 2016
This class inherit from and is an enhancement for CDbAuthManager class from Yii Framework 1.1 which lower the number of database queries.
View EFastDbAuthManager.php
<?php
/**
* EFastDbAuthManager class file
*
* This class inherit from and is an enhancement for CDbAuthManager class which lower the number of database queries.
* The main difference with the original class is that the authorization data are loaded once for all in a very a similar way to CPhpAuthManager.
* In short terms, this is a kind of mix between CDbAuthManager and CPhpAuthManager classes to get the best of both worlds.
* The class can also be used to cache the authorization data to achieve an even faster loading.
*
@juban
juban / yii2-quick-array-add-property.php
Created Dec 12, 2015
Yii2 - Quickly add a property to an array using ArrayHelper::getColumn
View yii2-quick-array-add-property.php
<?php
require(__DIR__ . '/vendor/autoload.php');
use yii\helpers\ArrayHelper;
use yii\helpers\VarDumper;
$fooArray = [
['name' => 'Han Solo', 'email' => 'han.solo@starwars.com'],
['name' => '', 'email' => 'luc.skywalker@starwars.com'],
@juban
juban / GTT_XML_file_fixer.php
Created Jan 5, 2016
Google Translator Toolkit XML file fixer
View GTT_XML_file_fixer.php
#!/usr/bin/env php
<?php
if(!isset($argv[1]))
die("Please, specify a file to process as argument\n");
$file = $argv[1];
if(!file_exists($file)) {
die("File $file does not exist\n");
}
$pathinfo = pathinfo(realpath($file));
$data = file_get_contents($file);
@juban
juban / yii2-create-activeDataProvider-from-model-relation
Created Dec 4, 2016
Yii2 - Create an ActiveDataProvider from a HasMany model relation
View yii2-create-activeDataProvider-from-model-relation
<?php
$applicationsDataProvider = new \yii\data\ActiveDataProvider([
'query' => $model->getRelation('relationName'),
'pagination' => [
'pageParam' => 'apps_page'
]
]);
?>
@juban
juban / gist:e3f3d6f7555d38829b6bfcaf6fba6a7e
Created Mar 21, 2017
List of installed Elasticsearch plugins
View gist:e3f3d6f7555d38829b6bfcaf6fba6a7e
http://host.name/_nodes?plugin=true
@juban
juban / index.twig
Created Jul 11, 2017
Craft CMS - Redirect to first available child entity in a structure or channel section
View index.twig
{% set entry = craft.entries.slug('homepage').first() %}
{% redirect entry.workshopPages[0].url %}
@juban
juban / index.twig
Last active Sep 6, 2019
Paginate any array within Craft CMS templates
View index.twig
{% set someArrayToPaginate = [
{someProperty:"One"},
{someProperty:"Two"},
{someProperty:"Three"},
{someProperty:"Four"},
{someProperty:"Five"},
{someProperty:"Six"},
{someProperty:"Seven"},
{someProperty:"Eight"},
{someProperty:"Nine"},
@juban
juban / index.php
Created Jul 8, 2019
Test Craft CMS version
View index.php
$schemaVersion = Craft::$app->getInstalledSchemaVersion();
if (version_compare($schemaVersion, '3.2.0', '>=')) {
// Do something specific to Craft CMS 3.2 and upper
}
@juban
juban / app.php
Last active Jul 16, 2019
Redis configuration for Craft CMS
View app.php
<?php
/**
* Yii Application Config
*
* Edit this file at your own risk!
*
* The array returned by this file will get merged with
* vendor/craftcms/cms/src/config/app/main.php and [web|console].php, when
* Craft's bootstrap script is defining the configuration for the entire
* application.
You can’t perform that action at this time.