Combine Magento with Angular – Magento-on-Angular

This project brought Magento together with Angular, however it looked like no longer being developed, the latest release was dated Jun 30, 2015.

https://github.com/Wildhoney/Magento-on-Angular

Moa

Tired of Magento's lack of unit testing? Configuration over convention? Use of Prototype.js? Badly written JavaScript? Untested third-party modules? Likewise! Moa brings Magento into the 21st century.

Playing around WordPress with Laravel Eloquent and MVC

The WordPress code is commonly known as messy and not the best practice, I've found some packages/libraries that can empower WordPress with MVC or at least deacent ORM.

Have fun.

WordPress Corcel

Corcel uses Laravel Eloquent models to manage retrieving content directly from your WordPress database. Once installed you can use the same comfortable syntax you are used to:

// All published posts
$posts = Post::published()->get();
$posts = Post::status('publish')->get();

// A specific post
$post = Post::find(31);

It includes support for posts, post types, taxonomies, pages, categories, and attachments. The one downside is the package is still under development.

Link: https://github.com/jgrossi/corcel

 

WordPlate

WordPlate is a modern WordPress stack which tries to simplify the fuzziness around WordPress development. Using the latest standards from PHP. WordPlate utilizes WordPress as its dependency through Composer.

Link: https://github.com/wordplate/wordplate

 

Themosis - A MVC framework for WordPress developers.

Build custom websites and applications with WordPress.

themosis A MVC framework for WordPress developers. Build custom websites and applications with WordPress.

 

Link: http://framework.themosis.com/

 

Reference: https://laravel-news.com/2016/01/wordpress-and-laravel/

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"

 

Notes for setup vsftpd on Ubuntu server

Reflection of the process, install vsftpd and assign the user group/folder

Need to properly add the user and the user group as well as user’s directory

User directory chown and chmod need to be correct

Properly setup the passive forward and passive ports

The firewall issue

The certificate and key issue (in the example it’s the same PEM file...)

Possible routine for the FTP

  1. Install server
  2. Add user
  3. Change user password
  4. Change user directory
  5. Change user group
  6. Change directory ownership
  7. Set passive mode
    pasv_enable=Yes
    pasv_max_port=10091
    pasv_min_port=10091
  8. Set firewall to open 21 and 10091
  9. Generate the certificate and key, .conf correct setup
  10. FTP set to require explicit FTP over TLS

 

Use TLS / SSL to secure the connection

http://wiki.vpslink.com/Configuring_vsftpd_for_secure_connections_%28TLS/SSL/SFTP%29#Generate_a_Certificate

[root@vps] openssl req -x509 -nodes -days 365 -newkey rsa:1024 \
-keyout /etc/vsftpd/vsftpd.pem \
-out /etc/vsftpd/vsftpd.pem

To configure vsftpd you edit the file /etc/vsftpd/vsftpd.conf and add the following lines:

ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=NO
force_local_logins_ssl=NO
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
rsa_cert_file=/etc/vsftpd/vsftpd.pem

 

Vsftpd config passive mode

To configure passive mode for vsftpd you need to
set some parameters in vsftpd.conf.

pasv_enable=Yes
pasv_max_port=20100
pasv_min_port=20090

Otherwise it’ll come with directory list error.

 

Ubuntu change user home directory

# You either need to be logged on as root, not recommended, or prefix the command with sudo. The command does not create the folder so you will need to create it first.

cd /home

sudo mkdir peter

sudo chown peter:peter peter

sudo usermod -d /home/peter peter

If want to
move current user directory to new:

sudo usermod  -d new_home_dir  -m  username

 

Linux user group etc.

Linux: Show All Members of a Group

The /etc/group file is a text file that defines the groups on the Linux and Unix based systems. You can simply query this file to find and list all members of a group.

  1. /etc/group file – User group file
  2. members command – List members of a group
  3. lid command – List user’s groups or group’s users

Linux: List all members of a group using /etc/group file

# Use grep command as follows:

$ grep 'grpup-name-here' /etc/group

$ grep 'ftponly' /etc/group

$ grep -i --color 'ftponly' /etc/group

# Sample outputs:

ftponly:x:1001:raj,vivek,archana,sai,sayali

To get just a list of all members of a group called ftponly, type:

awk -F':' '/ftponly/{print $4}' /etc/group

Other ways:

# All users:

$ getent passwd

# All groups:

$ getent group

# All groups with a specific user:

$ getent group | grep username

 

Understanding the /etc/passwd file

http://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/

Task: See User List

/etc/passwd is only used for local users only. To see list of all users, enter:

$ cat /etc/passwd

To search for a username called tom, enter:

$ grep tom /etc/passwd

/etc/passwd file permission

The permission on the /etc/passwd file should be read only to users (-rw-r–r–) and the owner must be root:

$ ls -l /etc/passwd

Output:

-rw-r--r-- 1 root root 2659 Sep 17 01:46 /etc/passwd

 

Vsftpd install

https://www.digitalocean.com/community/tutorials/how-to-configure-vsftpd-to-use-ssl-tls-on-an-ubuntu-vps

 

Command to list all users with their UID?

http://askubuntu.com/questions/645236/command-to-list-all-users-with-their-uid

Awk way

List all users with a /home folder:

awk -F: '/\/home/ {printf "%s:%s\n",$1,$3}' /etc/passwd

or all users with a UID >= 1000:

awk -F: '($3 >= 1000) {printf "%s:%s\n",$1,$3}' /etc/passwd

a combination

awk -F: '/\/home/ && ($3 >= 1000) {printf "%s:%s\n",$1,$3}' /etc/passwd

or for all entries

awk -F: '{printf "%s:%s\n",$1,$3}' /etc/passwd

 

A command to list all users? And how to add, delete, modify users?

http://askubuntu.com/questions/410244/a-command-to-list-all-users-and-how-to-add-delete-modify-users

To list all users you can use:

cut -d: -f1 /etc/passwd

To add a new user you can use:

sudo adduser
new_username

or:

sudo useradd
new_username

See also: What is the difference between adduser and useradd?

To remove/delete a user, first you can use:

sudo userdel
username

Then you may want to delete the home directory for the deleted user account :

sudo rm -r /home/
username

(Please use with caution the above command!)

To modify the username of a user:

usermod -l
new_username old_username

To change the password for a user:

sudo passwd
username

To change the shell for a user:

sudo chsh
username

To change the details for a user (for example real name):

sudo chfn
username

And, of course, see also: man adduser, man useradd, man userdel... and so on.

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;
}

Remove all the rounded corners in Bootstrap (restore to the default corner)

* {
  border-radius: 0 !important;
}

 

* {
  -webkit-border-radius: 0 !important;
     -moz-border-radius: 0 !important;
          border-radius: 0 !important;
}

variables.less

@border-radius-base:        0px;
@border-radius-large:       0px;
@border-radius-small:       0px;

In bootstrap 4 if you are compiling it you can disable radius alltogether in the _custom.scss file:

$enable-rounded: false;

Source: http://stackoverflow.com/questions/9742166/getting-rid-of-all-the-rounded-corners-in-twitter-bootstrap

CSS Vertical Alignment – Bootstrap Bottom Align within Row

.row {
position: relative;
}
.mainBox {
border: solid thin black;
}

.buttonBox {
position: absolute;
bottom:0;
right:0;
}

Heading

Sub Heading

.buttonBox will make the div with the button align to the bottom of the container

Source: http://jsfiddle.net/6pYhx/3/

 

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

Some of the jQuery / BootStrap Datepicker datetime input

Customizable Dropdown Birthday Picker Plugin with jQuery

This one's with 3 input fields.

http://www.jqueryscript.net/time-clock/Customizable-Dropdown-Birthday-Picker-Plugin-with-jQuery.html

Customizable Dropdown Birthday Picker Plugin with jQuery

Datepicker for Bootstrap

The best part for this one is the start and end date / check in and check out date control

http://www.eyecon.ro/bootstrap-datepicker/

Datepicker for Bootstrap

DateTime Picker Bootstrap - form component to handle date and time data.

http://www.malot.fr/bootstrap-datetimepicker/

DateTime Picker Bootstrap - form component to handle date and time data.

 

Pikaday A refreshing JavaScript Datepicker JS Lib

This is a simple yet fully functional datetime picker

Pikaday A refreshing JavaScript Datepicker

Link: https://github.com/dbushell/Pikaday

PHP date function: http://php.net/manual/en/function.date.php

I've found an issue when the instance is not bound to the filed value, eg. I'd like to preload the field value value="{{ SELF.userDob }}", this will cause the picker not work.

In order to solve this, try to bind the instance to the field value:

change the onSelect line

onSelect: function()

to

picker = new Pikaday({
    onSelect: function(date) {
        field.value = picker.toString();
    }

Then it should work.

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/