All posts by Junaidi A

Reverse Engineering in Mysql Workbench

Hello,

It’s such a great day in 2016, I pushed myself to focus on developing “something that matters”.  I still have two papers for final exam as I’m currently further study in Bachelor Degree of Software Engineering in one of Public University in Malaysia.

As final year student, I’m required to develop a Final Year Project. I decided to develop a mobile app with PHP as the backend server.

Previously, I use MySql Workbench to draft my database design. I’m using Laravel as the backend server for my mobile app.  After doing the migration in Laravel,  I realize that I should redesign my database.

After all migration files migrated  to MySQL database, I need to write the model relationship in Laravel. A lot of changes in relationship design from my draft database and my current database after migration.

To generate a new design view in MySql Workbench from my current database here is the step in short.

  1. Export to an SQL file for the database from PhpMyAdmin
  2. Open MySQL Workbench, go to menu,
    Database > Reverse Engineer
  3. Import the SQL file and follow instruction on workbench’s wizard
    Reverse Engineer in MySQL Workbench
  4. After completing the wizard, new Workbench view will generate based on your SQL file. The view design is looking good and easy to read as workbench design the arrangement for you.

Laravel Count and GroupBy Field Query

I have been busy developing an e-commerce platform from zero to fulfill this semester project for Web Programming Course.

I need to select 5 the most popular product based on customer order. Customer order is stored in order_details table. To make a that query in laravel, try this:

Based on code snippet above, it will return 5 product_id as the most ordered product.

p/s: my 2016 mission, be a morning person!

Code Snippet: WordPress Nginx Configuration File With SSL Enable

WordPress is running smooth with Nginx. I have a server with DigitalOcean and currently use WordPress with Nginx. Here is the code snippet for Nginx configuration with SSL enable.

To use this code snippet, you are required to have a valid SSL installed on your server. After that replace example.com on the configuration code above with your own domain.

credit

PHPMyAdmin: Drop a Foreign Key

Drop the foreign key relation before drop the index. Have a look at the output of:

SHOW CREATE TABLE table_name

It will show the internal name of the foreign key constraint which is use during the table set up process. Drop this foreign key with:

ALTER TABLE table_name DROP FOREIGN KEY key_name

before we can drop the index on the foreign key field. InnoDB relies on indexes on all key columns in a foreign key constraint.

WordPress Varnish Cache Age 0

Varnish with cache age 0 means that varnish did not serve the content from cache.

To solve this, edit your sudo nano /etc/varnish/default.vcl

paste this in that file.

After that restart varnish service,

sudo service varnish restart

you may check your varnish status here

How to get the original IP address in Apache2 behind Varnish

I’m having Varnish as a frontend and then running Apache through reverse proxy. The Apache logs become full of just a single IP address, the accesses from the Varnish server – usually 127.0.0.1 if you are running both on the same server.

No more GeoIP decisions on the backend or any other feature by remote address.

But we know that Varnish passes along the original client IP address on a HTTP header named X-Forwarded-For to the backend server. It would be awesome if Apache could deal with that,

Fortunately there is already a module that injects the IP on a special header to the HTTP request to Apache: mod_remoteip

  1. Install mod_remoteip
  2. Enable the module
  3. Edit your apache2 configuration file
  4. Add this line at the end of the file
  5. Restart Apache service

You should now get the client’s real IP address instead of varnish IP address.

🙂

[Snippet] WordPress: Hide Post By Author From Admin Post List

There is a situation where we need to hide a post written by user A from user B while both of them has same role as “Editor”.

Let’s say we have two user as follow:

UserA with ID 17 and roles Editor
UserB with ID 9 and roles Editor

We need to hide all post by UserB so UserA cannot see it in WordPress Post List (admin page).

Code snippet below may help you to do this in easily.

Modified as you want 😀

[Snippet] Get All Post From Blogger In JSON Format

The time during this blog post written, Blogger API v3 is still not available to use by public. To use the API, you need to fill in the Google Form and request for an access.

I try to get all of my post from Blogger blog yesterday. I found that we can use JSON request to get all post from a blog in blogger without any restriction.

The following is a code snippet that I use to get all post from my blog in blogger.

As you can see in example above, I’m trying to get 500 recent post from  Blogger Developers Network. Feel free to review and update the code above as what you need. 🙂

Have a nice day!

 

[Snippet] CSS: Add Numbering For Each Row of Table

Using modern CSS, we can generate a set of numbering for each of table row of a table.

Let’s say we have a table in html as follow

To create a  numeric for table row in our first table data column, we will only use a modern CSS as follow

Numeric 1,2,3,… will be added to our first td for each tr. Modified the css code above as you want.

 

 

[Snippet] WordPress: How to use add_meta_box

The add_meta_box() function was introduced in Version 2.5. It allows plugin developers to add meta boxes to the administrative interface.

For example, you want to add a new field for Post such as City. User need to choose City for the post before publish it. We can use add_meta_box to add a new graphical user interface for meta box.

WordPress-Crunchify-Tag-Cloud

You may add this code snippet in your current active theme functions.php file or create a custom plugin.

Modify the code snippet above as what you need.