Magento Cards/Knowledge, Developer reference, Code Snippets, and netz98 magerun CLI tools

Some of the useful Magento tools and references:

Magento Code Snippets

This GitHub page gives you a lot of very useful Magento Code Snippets

https://gist.github.com/arosenhagen/2397824

 

netz98 magerun CLI tools

The swiss army knife for Magento developers, sysadmins and devops. The tool provides a huge set of well tested command line commands which save hours of work time. All commands are extendable by a module API. http://magerun.net/

on GitHub: https://github.com/netz98/n98-magerun

Magento cards

A simple knowledge base for Magento development including code snippets, tips and tricks, commands, configurations and many more other topics.

https://makandracards.com/magento

Magento for Developers: Part 4—Magento Layouts, Blocks and Templates

The official dev guide for Magento 1.x

http://devdocs.magento.com/guides/m1x/magefordev/mage-for-dev-4.html

 

Reading: Object Oriented Programming with JavaScript

Interesting reading, how to do Javascript OO

As we already know, JavaScript is an object oriented language. In this article we will see JavaScript example to inheritance and subtype polymorphism.
For solid base, I really recommend to read first about JavaScript Prototype.

Follow below link to read:

"Object Oriented Programming with JavaScript"

 

PHP function to make slug – SEO friendly URL string conversion from title or excerpt

The following is the function that converts string into SEO friendly URL slug
function slugify($text)
{ 
  // replace non letter or digits by -
  $text = preg_replace('~[^\\pL\d]+~u', '-', $text);

  // trim
  $text = trim($text, '-');

  // transliterate
  $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);

  // lowercase
  $text = strtolower($text);

  // remove unwanted characters
  $text = preg_replace('~[^-\w]+~', '', $text);

  if (empty($text))
  {
    return 'n-a';
  }

  return $text;
}

Instant response for OctoberCMS Flash messages combined with Romanov.Flashmessage plugin (no page reload)

$validation = Validator::make($data, $rules);
 if ($validation->fails()) {
     throw new ValidationException($validation);
 }
 try {
     $user = Auth::authenticate([
         'login' => array_get($data, 'login'),
         'password' => array_get($data, 'password')
     ], true);
 }
 catch (Exception $ex) {
     if (preg_match('/user was not found with the given cred/i',$ex->getMessage())) {
     $flash_message = 'A registered user was not found with that email';
 }
 elseif (preg_match('/hashed credential "password" did not match/i',$ex->getMessage())) {
     $flash_message = 'The password supplied for that user is incorrect';
 }
 }
 if ($flash_message) {
     return ['msgs' => [ 'danger' => $flash_message ], 'options' => [], 'settings' => [] ];
 }

 

This will replace the error message " user was found to match all plain text credentials however hashed credential "password" did not match." that comes by default with Laravel.

 

Source:

https://gist.github.com/kdallas/17e07f9b50b066a13bdd#file-account-php-L138

OctoberCMS debugging – DUMP() debug function for templating and Debugbar plugin

This is a very handy function for debugging the template.

reference: https://octobercms.com/docs/markup/function-dump

Usage:

{{ dump(user) }}
{{ dump(user, categories) }}
{{ dump() }}

It'll show you the variable type and its content, eg. if you have an object variable it'll show you the member functions or if you have a collection variable, it'll show you the keys and value types.

The following screenshot indicates the front-end output of an array variable:
octoberCMS dump function debug output screenshot for template front end

Here is another useful OctoberCMS plugin that'll help debugging as it could show much more information in the backend.

OctoberCMS DebugBar plugin

OctoberCMS debugbar plugin on GitHub: https://github.com/Flynsarmy/oc-debugbar-plugin

on OctoberCMS plugins page: https://octobercms.com/plugin/bedard-debugbar

A laravel validation rules – Check user age with laravel validation rules

Here is the example code for checking the age of an user.

Validator::extend('olderThan', function($attribute, $value, $parameters)
{
    $minAge = ( ! empty($parameters)) ? (int) $parameters[0] : 13;
    return (new DateTime)->diff(new DateTime($value))->y >= $minAge;

    // or the same using Carbon:
    // return Carbon\Carbon::now()->diff(new Carbon\Carbon($value))->y >= $minAge;
});

Usage:

$rules = ['dob' => 'olderThan']; // checks for 13 years as a default age
$rules = ['dob' => 'olderThan:15']; // checks for 15 years etc

Source:

http://stackoverflow.com/questions/23081654/check-age-with-laravel-validation-rules

Formatting Timestamps in Laravel and OctoberCMS

If you create a table with timestamp() via a migration, you'll actually get a timestamp that is matching the one created by date('Y-m-d H:i:s').

So in order to get the output correctly displayed with your local time format, or you'd like to format it and have an input to the database, then you'll need to format it before the output:

Created on: {{ date('F d, Y', strtotime($list->created_at)) }}

For formatting the input, eg. format a DOB datetime input:

$data = post();

$data['dob'] = date('Y-m-d H:i:s', post('dob'));

reference:  http://www.easylaravelbook.com/blog/2015/02/11/formatting-timestamps-in-laravel/

Drupal Redis setup Predis and Module

Here is the short introduction of installing Redis for Drupal

Install Redis

sudo apt-get install redis-server php5-redis

Install Redis Drupal module

https://www.drupal.org/project/redis

Make sure Predis library is downloaded and should be installed in sites/all/libraries/predis

Edit site settings.php

$conf['redis_client_interface'] = 'Predis';
$conf['redis_client_host'] = '127.0.0.1';
$conf['lock_inc'] = 'sites/all/modules/contrib/redis/redis.lock.inc';
$conf['cache_backends'][] = 'sites/all/modules/contrib/redis/redis.autoload.inc';
$conf['cache_default_class'] = 'Redis_Cache';

Reference:

https://www.drupal.org/project/redis

http://www.darrenmothersele.com/blog/2014/02/25/drupal-redis/

Conference Paper Review System – Software Engineering Project – PHP / MySQL / OOP

This example demonstrates my PHP / MySQL programming capability of building web based applications with object-oriented software design.

This is a team project, and my role was software designer and programmer.

Project Demo URL

http://paper-review.w3c-lab.com/

LOC

Around 4500 lines of code including PHP, HTML, CSS and JavaScript codes

Time spent

2 and a half months, including the early software requirement and design stages as well as the testing stage.

Main programming package

PHP / MySQL / JavaScript

Skills demonstrated

jQuery AJAX, Bootstrap model, PHP OOP,  Project Management, Software Engineering

Features

HTML5 based mobile compatible application

Other Package/Framework used

Bootstrap / jQuery

Screenshots

01

07

04

03

02

Documents and misc (click to download)

Path Finder – SIT302 Team Project – 2015 iAwards Nomination

This is the proof that I'm an award-winning IT pro!   😀

Project introduction

PathFinder is a peer-to-peer web-based guide featuring video tutorials, an online interactive map, timetables to assist in your scheduling and an incredible game experience – all in the palm of your hand. Our development team, in conjunction with the IT staff, have taken the complexity out of finding information by designing a simple, yet engaging experience for all IT students.

Project Intro Video

 

Project site URL

http://project-survival.w3c-lab.com/

Technology Used
  • Highly customized WordPress theme
  • Over 30+ WordPress plugins
  • Flash for interactive map
  • Adobe Premiere CC
  • Adobe After Effects CC
  • YouTube for video hosting
  • HTML5 for interactive game
My role and contributions

I was the team leader (of a 7-member team), system analyst and web developer.

My major tasks and contributions for the project were:

  • Task planning and allocation
  • Meeting arrangement for both the team and stakeholders and supervisors
  • Initial project analysis report
  • Developed the base of the system
  • Web hosting management / WP Installation and configuration / Theme customization
  • Over 300+ pages of documentation produced

Sample of project Gantt chart

Achievement
2015 iAwards Nomination (Team) - iAwards Link (new window)

The iAwards honours companies at the cutting edge of technology innovation and recognises the achievements of home-grown Australian innovators.

2015 Deakin University School of IT Project Award (Personal Award)

Achieved the highest mark overall for SIT302 Project

2015 Deakin University School of IT Project Award