A Javascript Handbook as Quick Reference

Check the Handbook I’m talking about Here without further reading below.

As a response to the ongoing hype and trend of JS stack all over the world, recently I thought to have a quick and refreshed overview of this awesome language. I am loving the way ES6 is taking Javascript to a great level by introducing awesome features in it. Node.js is another reason I am focusing on this language lately to learn developing back-end and API centric application in a robust, scalable and asynchronous way. I love the concept of Event Driven, Single Threaded, Non-Blocking I/O based model that Node.js provides to the app developer.

So, last week I ended up writing a Hand Crafted Note of some major Javascript topics with examples taken from different sources, just to have a quick overview. I also put this note in a public GitHub repository and published it using GitHub pages (powered by Jekyll) for the readers and contributors. Check out the Handbook Here and feel free to fork and update the page by creating pull requests to the main repository. I always hope to learn from the community 🙂

Note: I will also share my high level (not the deep/detail) learning of Javascript in near future as an open source course for my native community under my initiative named HowToCode.com.bd on This Link

Have a great day!!! 🙂

ভিপিএস (VPS) কেনা, ব্যাসিক কনফিগারেশন, ল্যাম্প ইন্সটলেশন, ডোমেইন ম্যাপিং

ভূমিকা

VPS (Virtual Private Server) হচ্ছে একধরনের ভার্চুয়াল মেশিন বা ভার্চুয়াল কম্পিউটারও বলতে পারেন, যেটা একটা সার্ভিস হিসেবে কেনা যায় বিভিন্ন ক্লাউড সার্ভার প্রোভাইডারদের কাছ থেকে। এই ভার্চুয়াল মেশিন গুলোরও RAM আছে, হার্ডডিস্ক আছে, সিপিইউ আছে এবং সর্বোপরি একটা অপারেটিং সিস্টেম এর উপর চলে। মজার ব্যাপার হচ্ছে এরকম একটা মেশিনের বাস্তব কোন অস্তিত্ব নাই ঠিকই কিন্তু বাস্তব একটা ফিজিক্যাল মেশিনের মতই গঠন ও আচরণ। কিভাবে এই ভার্চুয়াল ইনফ্রাস্ট্রাকচার তৈরি ও মেইন্টেইনড হয় সেটা আজকে আমাদের আলোচনার মুল বিষয় নয়। বরং এরকম একটা ভার্চুয়াল সার্ভার মেশিনকে আমরা কিভাবে ওয়েব সার্ভার হিসেবে তৈরি করব সেখান থেকে কিভাবে ওয়েব কন্টেন্ট প্রোভাইড করবো সেটাই মুখ্য বিষয়।

কিনে ফেলি একটা ভার্চুয়াল প্রাইভেট সার্ভার

বিভিন্ন সার্ভার প্রোভাইডার তাদের মেশিনগুলোকে বিভিন্ন নামে ডাকে। যেমন অ্যামাজন এর ভাষায় এগুলো হচ্ছে ইন্সট্যান্স, Rackspace এর ভাষায় এগুলো ক্লাউড সার্ভার, DigitalOcean এর ভাষায় ড্রপলেট, ইত্যাদি। আমরা আজকের টিউটোরিয়ালের জন্য DigitalOcean এর কাছ থেকে একটি মিনিমাম কনফিগারেশনের সার্ভার কিনবো যেটাতে ৬৪ বিটের উবুন্টু ১৪.০৪ ইন্সটল করা থাকবে এবং আস্তে আস্তে এটা কফিগার করবো ওয়েব সার্ভার হিসেবে।
এই লিঙ্ক থেকে একটি সার্ভার কিনে ফেলতে পারেন (এটি আমার রেফারেল লিঙ্ক। এটা ব্যবহার করে সাইন আপ করলে $10 ক্রেডিট/ব্যালেন্স পাবেন, না করলে নাই) । প্রথমে অ্যাকাউন্ট ডিটেইল দিতে হবে এবং পরে ভ্যালিড পেমেন্ট মেথড অ্যাড করতে হবে। যদিও এরা এক মাস শেষ হলে পেমেন্ট মেথড থেকে বিল চার্জ করবে তার আগে না। আপনি চাইলে সার্ভার মাঝে মাঝে শাটডাউন করে রাখতে পারেন। সেই সময় গুলোতে বিল কাউন্ট হবে না।
Continue reading ভিপিএস (VPS) কেনা, ব্যাসিক কনফিগারেশন, ল্যাম্প ইন্সটলেশন, ডোমেইন ম্যাপিং

laravel4 Eloquent ORM Model, Blade View & Simple Controller

So far we have completed four blog posts for the series on development of thisdayinbangladesh, a simple laravel4 live application. Those are following:

1. Creating virtual host
2. Installing laravel4
3. laravel4 migrations & seeding
4. laravel4 routing

In this post we will learn, how we can have Object Relational Mapping for our data model using Eloquent ORM that is built in with laravel4. Also we will render our view using Blade templating system. Finally we will create few very simple controllers that will do our basic tasks.

Model:

Laravel ships with a superb ORM: Eloquent. If you have used the Ruby on Rails framework, you will find Eloquent familiar, as it follows the ActiveRecord ORM style of database interaction.

At this current stage (state before merging with any other branch on github) of our application we need such a relationship among our database tables (days, facts, types, fact_type) so that;

i. A Day has many Facts: That means there would be a relation from “days” table to “facts” table that is One to Many. N. B. Currently “days” table contains 366 days in separate rows.
ii. A Fact belongs to a Day: That means in a certain case, one Or more Fact(s) will belong to a single Day. That is a reverse of One to Many relation from “facts” table to “days” table.
iii. A Type has many Facts & a Fact has many Types: For example a fact type named “politics” could have several facts for a certain day. On the other hand a fact titled “Independence day of Bangladesh” could have several types like “politics”, “good”, “revolutionary” etc. So, there would be a Many To Many relationship between “types” table & “facts” table.

Lets create our first Model called “Day.php” for our “days” table inside “app/models” directory with the following code.

Continue reading laravel4 Eloquent ORM Model, Blade View & Simple Controller

laravel4 Routing to Controller Classes

So far we have completed three blog posts to the development of thisdayinbangladesh.com laravel4 live project. First one was about creating virtual host for local development environment, second one was about installing basic laravel4 & the third one was about migrations & seeding database.
In this lesson we will cover the routing mechanisms of laravel4 that will be/was necessary for our mentioned project.
Most of the routes for our application will be defined in the “app/routes.php” file. The simplest Laravel routes consist of a URI and a Closure callback. Just like,

means if you hit the root URL of your application then it will return the ‘Hello World’ & no task any more.
Laravel allows you to not only route to Closures, but also to controller classes, and even allows the creation of resource controllers. For our application we will also register several routes to/for our various controller classes like a basic controller, a RESTful controller & also to a Resource controller.
The following code block is all the routes we will/have used for our app,

Continue reading laravel4 Routing to Controller Classes

Top 10 magento trouble shooting after transferring to a new server

1. Make sure there is nothing in the cache directory in new location of magento:
Execute the following command from inside magento root directory,

2. Set proper folder permissions:
Enter the following commands one by one,

Also make sure all folder permissions are set to 755 and file permissions to 644

3. Site is loading till the header part only, No other content below it:
Install GD Library

4. Admin panel not working after logging in:
Install CURL extension

5. SEO friendly URL not working:
Install/enable rewrite module on Apache,

6. Ajax [Add to Cart] pop up not showing on product detail page:
Turn [Merge Javascript] option to, “No” from magento admin panel.

7. Admin panel showing message for miss configuration of server:
A. Checkout whether .htaccess is being considered properly or not, also make sure any apache module specific command that is in that file is working. Check whether those modules are installed/enabled in the server.
B. Add/Update virtual host OR apache configuration file to allow over ridding by putting this line

8. Crontab is working but price rules are resetting:
Empty the [cron_schedule] table from the database to remove all dead locked and garbaged schedules. Don’t worry, this table will populate data again according to new cron schedules.

9. Changed main domain OR site address?:
Access the table [core_config_data] and edit two fields [web/unsecure/base_url] [web/secure/base_url] under the [path] column to the new domain/web address.

10. Want to reset admin password?:
Run the query from inside new server after connecting to mySQL,

Change NEWPASS, NE, ADMINUSERNAME to your wish.

Laravel4 Migrations and Seeding

So far we have created the virtual host for our laravel4 application named “thisdayinbangladesh.dev” and also set up the basic laravel4 installation. Now in this lesson we will create the migrations and seeders needed for our application.

“Migrations are a type of version control for your database. They allow a team to modify the database schema and stay up to date on the current schema state. Migrations are typically paired with the Schema Builder to easily manage your application’s scheme.”

“Laravel also includes a simple way to seed your database with test data using seed classes.”

First thing first. Open up the Mac Terminal and enter inside the “thisdayinbangladesh” folder under MAMP’s “htdocs” directory. All of the following commands should be executed from inside the project folder.

Create migration files for all of our currently needed tables:
Execute these commands one by one,

These commands set up the basic migration scripts that we’ll be using to create the database tables

Update the migration files:
Edit “database/migrations/TODAYS_FULL_DATE_create_days_table.php” file and update the “up()” method to include a new column on the “days” table and to remove the “timestamp” column.

Update the “up()” method of “database/migrations/TODAYS_FULL_DATE_create_facts_table.php” file to the following,

Update the “up()” method of “database/migrations/TODAYS_FULL_DATE_create_types_table.php” file to the following,

Update the “up()” method of “database/migrations/TODAYS_FULL_DATE_create_fact_type_table.php” file to the following,

Prepare the Seeder files to add sample data to those tables:
Create a file within the “app/database/seeds” folder that has the same name as the table. So, for our “days” table create a file named “DayTableSeeder.php” inside “seeds” folder containing the following full code,

Here I am inserting some “day-month” patterned days rows in the “days” table using a simple loop. Please, don’t judge my PHP knowledge on this. This is not about showing optimized, minimal, smell free coding.
Also, create other seeder files for those remaining tables into which we want to push some sample data even before launching the app.
Create “FactTableSeeder.php” with following code. Here we are inserting some sample facts that holds the fact’s sample title and sample description just for checking out data retrieval with proper relations later on the next lesson.

Now create the “TypeTableSeeder.php” file with the following code,

And finally create the “FactTypeTableSeeder.php” file with,

As you can see, we are assigning some “facts” to some “types” and making rows in the “fact_type” table pairing “fact_id” with “type_id” as for our sample data.

Update the DatabaseSeeder file:
Update the “run()” method of the “DatabaseSeeder.php” file. That should already be there inside “app/database/seeds” folder with the following code,

Run Migration and Seed:
Execute the following commands one by one.

If the commands executed successfully then you should see those tables along with an extra tables named “migrations” under your “thisdayinbangladesh” database. Also there should be our sample data in each table if the Seeding happens successfully!

Note:
As one “fact” will have multiple “types” and vise versa. You should name the Pivot table (“fact_type” in this case) of the “facts” and “types” table by taking the singular name of the alphabetically first table then the second table with an underscore in the middle.
Also there should be two columns at least, to hold the relation which should be named by taking the singular name of one table with its primary key along with an underscore in the middle. Such as “fact_id”, “type_id”.
But wait, don’t be scared. There is still flexibility while naming those tables and columns for using with Eloquent ORM. You will have to just pass those non-conventional table names or column names as parameters in corresponding methods while creating ORM relations among tables or while creating migrations tables.
We just followed the conventional naming pattern in this lesson to make thing simple and understandable.

What next?:
The next step is to make proper Routing for our application. Which is ready now!

Installing Laravel4 in Mac OSX with MAMP

Re-cap:
In the past and first tutorial of this series we learned how to create a virtual host with MAMP. In this second tutorial, we will install laravel4 PHP framework and will go another step toward developing a full laravel4 application series.

Precautions:

  • Make sure your installed PHP version is greater or equal to 5.3.7
  • Also make sure the MCrypt PHP extension is enabled
  • For pretty URL the mod_rewrite module is enabled on Apache

1. Install Composer Globally:

The following command will just check a few PHP settings and then download composer.phar

You can run these commands to easily access composer from anywhere on your system

2. Create a laravel project named “thisdayinbangladesh” inside our MAMP’s “htdocs” directory:

Going inside the “htdocs” directory

Creating the project there

3. A small permission issue:

Lets enter into our project directory

Change the permission of the storage folder to writable

4. Basic Configuration:

Update line number 29 of the “app/config/app.php” file to

and line 42 to

5. Database configuration:
Though configuring database is not necessary to have a first run but lets complete this step as we will not do any editing on the config files later.

6. Lets have a test run:

Open the URL of your laravel application as we created earlier using virtual host; on the browser. That is http://thisdayinbangladesh.dev/
You should arrive!

To Do List After Launching a New Linux/Unix Like Server for Development

Commands, tricks & cautions that will be used here have been tested only on a Ubuntu 12.04 VPS. Though, most of the commands should work in other Unix like system without any change.
In this lesson we will see how should a newly launched/opened server be configured for basic security & proper accessibility. Usually you get an IP address & a root password for logging in as root, as soon as you open a new cloud/vps server from rackspace/digitalocean or some others like these.

1. Connecting to the remote system through/using SSH:
SSH(Secure Shell) is a protocol used to securely loggin in to a remote system & also ssh is the tool used in Linux that connect to the remote server over the SSH protocol.

The terminal will show a message and will prompt

Type yes & press enter & then in next prompt enter your root password that was provided by that server provider while opening a VPS. So, now we are logged in to the remote system as root user.

2. Change your root user’s password:
You used the root password that was generated & provided by the server provider & the first thing is to change this password. Enter the following command on the terminal.

It will first ask the current root password & after entering the current password it will ask your desired new password twice for confirmation. Continue reading To Do List After Launching a New Linux/Unix Like Server for Development

Kohana with Twitter bootstrap: Auto Generator Shell Script

Kohana HMVC with Twitter Bootstrap Auto Generator

What it does?

  • It makes a ready to develop web app on Kohana MVC along with Twitter Bootstrap UI framework.
  • First it downloads kohana, twitter bootstrap, jquery etc.
  • Secondly it makes necessary changes on the kohana boostrap and allocates UI assets.
  • Then it creates two types of routes for accessing front end and backend of the developing app.
  • It also makes changes on the default controller class and creates a view for it.
  • Also you can create a set of MVC (model, view, controller) classes/files by using create command.
  • Finally you can open the app in browser using open command.

Installation

  1. I assuem you have downloaded the kohanastrap.sh  file on your home.
  2. Open up the terminal. Change its permission by chmod +x ~/kohanastrap.sh
  3. Make a symlink of it by sudo ln -s ~/kohanastrap.sh /usr/bin/kohanastrap
  4. Type kohanastrap  from inside any directory and talk with it.
  5. I assume, you will enter into yout htdocs OR www directory and type kohanastrap init  and then it will build up a ready to develop web app using twitter bootstrap as template.
  6. If you want to create a set of MVC files/classes such as a Controller, a Model and a View for managing users of your app, then type kohanastrap User  and Done! Check inside your classes, views directory.
  7. Finally run your web app using the command kohanastrap open  and it will open your browser with two additional tabs containing the URLs of front end and backend of your newly created app (If you are in Mac). Otherwise, Open the browser and go to http://localhost/kohana/ OR http://127.0.0.1/kohana/ if you are in other than Mac.

Demo

Download

You can fork/download it from github

Precautions

Make sure wget works in your system. Also make sure your php has cURL, mcrypt, GD enabled and Apache has mod_rewrite  enabled. Those are needed to kohana.

A jQuery Plugin Snippet for Sublime Text 2

Sublime_Text_Logo
You can simply (yes really simply) create a code snippet on Sublime Text 2 for faster code completion by clicking on the Tools -> New Snippet  menu of sublime and by editing the snippet template according to your choice.
You will have to edit/update line number 3 to the code block you want to have while calling the snippet by a shortcode. Uncomment line 6 & define a shortcode typing which you want to generate that code block.  Also uncomment line 8 and define whether you want that snippet to be workable only in a specific scope of scripting.

Finally save the file in /Users/USERNAME/Library/Application\ Support/Sublime\ Text\ 2/Packages/User  (Mac OSX) folder with a name along with .sublime-snippet extension.

Screen Shot 2013-08-29 at 4.26.04 PM

Here I have made a simple snippet which contains a template of a basic JQuery plugin. You can Download this snippet file and paste it inside the folder /Users/USERNAME/Library/Application\ Support/Sublime\ Text\ 2/Packages/User (Mac OSX)

Screen Shot 2013-08-29 at 4.12.36 PMThen you can start writing jquery on any type of file (As I did not define any scope) and the snippet keyword should appear.

Screen Shot 2013-08-29 at 4.14.14 PM

Press tab key by typing jqueryplugin OR enter/return key by selecting that suggestion and it will generate a basic template of a jquery plugin there for you.

Screen Shot 2013-08-29 at 4.14.22 PM