Saturday 25 November 2017

Laravel Migrations Command Lines

I don't trust my memory well so I'll document some migrations command

php artisan make:migration add_paid_to_users --table="users"
This line will create a book table migrations

php artisan make:migration create_books_table --create="books"




use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateBooksTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('books', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('books');
    }
}

This line will add a migration script to add author_id

php artisan make:migration add_author_id_to_book_table --table="books"


use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddAuthorIdToBookTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('books', function (Blueprint $table) {
            $table->integer('author_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('books', function (Blueprint $table) {
            //
        });
    }
}
My Template for creating migrations



use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades;


class DifferentArtisanTypeForMySql extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {

        Schema::create('my_table1', function (Blueprint $table) {
            $table->increments('id');

            $table->string('string_col');
            $table->string('string_col_with_length', 500);


            //create unsigned field which is the same type for field with increment attribute
            $table->unsignedInteger('unsigned_int_index')->index();
            //create string token with unique index
            $table->string('token', 100)->unique();


            $table->enum('enum_field', ['Beauty', 'Business service', 'Childrens products'])->nullable();


            $table->timestamp('timestamp_field')->nullable();
            $table->date('date_field')->nullable();
            $table->boolean('boolean_field')->default(0);

            //will create integer field with 11 in length
            $table->integer('integer_field')->default(0);

            //will create integer field with 10 in length
            $table->integer('unsigned_integer_field')->unsigned();
            
            $table->decimal('decimal_field', 6, 1)->nullable()->default(0);
            $table->tinyInteger('tinyint_field');
            $table->smallInteger('smallinteger_field')->nullable();

            $table->char('char_field', 2)->default('');
            $table->text('text_field');


        });



       // DB::statement('ALTER TABLE campaign_influencer_posts CHANGE COLUMN social_id account_id INT(11) NOT NULL ;');



        // Create table non auto increment field with index field
        Schema::create('my_table2', function ($table) {
            $table->integer('id')->unsigned()->index();
            $table->string('capital', 255)->nullable();
            $table->string('citizenship', 255)->nullable();

            $table->primary('id');
        });


        //Do you want to add a new records right away?
        Schema::create('my_table3', function(Blueprint $table)
        {
            $table->increments('id');
            $table->string('name');
            $table->tinyInteger('active')->index();
        });

        DB::table('my_table3')->insert([
            'name' => 'Instagram',
            'active' => 1
        ]);

        DB::table('my_table3')->insert([
            'name' => 'Facebook',
            'active' => 1
        ]);
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {

        Schema::table('my_table1', function (Blueprint $table) {
            $table->dropColumn('string_col');
        });

       // DB::statement('ALTER TABLE campaign_influencer_posts CHANGE COLUMN account_id social_id INT(11) NOT NULL ;');


        Schema::dropIfExists('my_table1');
        Schema::dropIfExists('my_table2');
        Schema::dropIfExists('my_table3');    
    }

    
    //You might wish to rename some fields
    // but for laravel 5.X 
    // you need to run composer require doctrine/dbal

    public function up()
    {
        Schema::table('demographics', function (Blueprint $table) {
            $table->renameColumn('social_id', 'account_id');
        });

    }
   
}



Template for migration with foreign key


    public function up(): void
    {
        Schema::table('child_table', function (Blueprint $table) {
            $table->integer('foreign_column', false, true)->nullable()->after('column_name');
            $table->foreign('foreign_column')->references('id')->on('parent_table');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('child_table', function (Blueprint $table) {
            $table->dropForeign('foreign_key_here');
            $table->dropColumn('foreign_column');
        });
    }
Here are the list of data type columns that can be added https://laravel.com/docs/5.5/migrations#creating-columns
Share:

Wednesday 8 November 2017

How to get the URL of the current page in C#

Lot of times I checked the URL for doing coding.   To get all the possible values put these codes


Share:

Monday 6 November 2017

Using SQLite in Laravel Applications

 I have been playing with Laravel and MySQL just recently and I have been enjoying using it on one of my recent project.    It's an eCommerce system done with Laravel 5.3 with Paypal and Stripe Payment.  I have implemented a authorize and capture mechanism.   

I've been using MySQL for database which works as expected but my problem is I'm using 3 machines for my development.   I don't want to use any cloud database like AWS MySQL or Google cloud db, because it's a paid one and apparently I'm not online always.   Things like I can work even in train (really hardworking right?) wherein internet is superslow.

Now comes SQLite.   SQLite is an embedded SQL database engine. Unlike most other SQL databases, SQLite does not have a separate server process. SQLite reads and writes directly to ordinary disk files. A complete SQL database with multiple tables, indices, triggers, and views, is contained in a single disk file.  Meaning a portable database which will solve my dillema.


To use SQLite on Laravel

Create a database laravel.sqlite file in the database folder of your laravel project.   You might need to download SQLite browser in http://sqlitebrowser.org/

/your-project/database/laravel.sqlite



Open your database.php file in the config folder of your project and make sure what you see in the image below is the same in your project.





'default' => env('DB_CONNECTION', 'sqlite'),


Go to your .env file and and change your DB_CONNECTION to
'sqlite'. Another thing you have to do is change DB_DATABASE to the path of your laravel.sqlite on your local computer.  You can leave the port, username and password.




DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=D://github/admin-dash/database/laravel.sqlite
DB_USERNAME=root
DB_PASSWORD=
Share:

Sunday 5 November 2017

Laravel Default Env File Content

It is often helpful to have different configuration values based on
the environment where the application is running. For example, you
may wish to use a different cache driver locally than you do on your
production server.

To make this a cinch, Laravel utilizes the DotEnv PHP library by Vance
Lucas. In a fresh Laravel installation, the root directory of your application
will contain a .env.example file. If you install Laravel via Composer, this
file will automatically be renamed to .env. Otherwise, you should rename the
file manually.

Your .env file should not be committed to your application's source control,
since each developer / server using your application could require a different
environment configuration. Furthermore, this would be a security risk in the event
an intruder gain access to your source control repository, since any sensitive
credentials would get exposed.

If you are developing with a team, you may wish to continue including a .env.example
file with your application. By putting place-holder values in the example configuration
file, other developers on your team can clearly see which environment variables are
needed to run your application. You may also create a .env.testing file. This file will
override values from the .env file when running PHPUnit tests or executing Artisan commands
with the --env=testing option.



APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=

.env for Laravel 8

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:9X1TB/g2Rx85u+8z+Dtm4FdSFX01BsOGs3fEJhJlrXU=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

To add paypal or stripe you can check Laravel eCommerce with Paypal and Stripe Payment
Share:

Friday 3 November 2017

Solr Sample Code and Articles

https://lucene.apache.org/solr/4_0_0/tutorial.html
https://github.com/pkainulainen/spring-data-solr-examples
https://www.petrikainulainen.net/programming/solr/spring-data-solr-tutorial-configuration/
http://nerdcenter.de/solr-multicore-installation-configuration/
http://www.params.me/2012/11/sample-solr-14-application-code-in-java.html
https://github.com/paramsethi/solr-setup
http://cmusphinx.sourceforge.net/2012/06/building-a-java-application-with-apache-nutch-and-solr/
http://www.solrtutorial.com/solrj-tutorial.html
https://www.drupal.org/node/484800
https://www.codeenigma.com/host/faq/how-do-i-create-solr-core-my-server
Share:

Monday 11 September 2017

Sending Responsive Email Template using Rails and Postmark

Sending a responsive email template and Need to watch https://www.driftingruby.com/episodes/mail-previews-and-templates Get some template here http://foundation.zurb.com/emails/email-templates.html add this in your gem file

gem 'premailer-rails'
gem 'postmark-rails', '~> 0.15.0'


To make the postmark use environment variables please follow this steps Comment out the default "from:" in ApplicationMailer To create an environment variable

nano ~/.bashrc
and add this line

export POSTMARK_API_TOKEN=b998c489-82e9-46a6-bc43-eb6c8fcc31c4
export POSTMARK_DEFAULT_FROM='postmark_registered_email'
in your secrets.yml

production:
  admin_name: <%= ENV["ADMIN_NAME"] %>
  admin_email: <%= ENV["ADMIN_EMAIL"] %>
  admin_password: <%= ENV["ADMIN_PASSWORD"] %>
  email_provider_username: <%= ENV["SENDGRID_USERNAME"] %>
  email_provider_password: <%= ENV["SENDGRID_PASSWORD"] %>
  domain_name: <%= ENV["DOMAIN_NAME"] %>
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
  site_title: <%= ENV["SITE_TITLE"] %>
  site_description: <%= ENV["SITE_DESCRIPTION"] %>
  postmark_api_token: <%= ENV["POSTMARK_API_TOKEN"] %>
  default_from_email: <%= ENV["POSTMARK_DEFAULT_FROM"] %>

in your application.rb add this lines

 config.action_mailer.delivery_method = :postmark
 config.action_mailer.postmark_settings = { :api_token => Rails.application.secrets.postmark_api_token }
 config.action_mailer.default_options = { from:  Rails.application.secrets.default_from_email }

Share:

Thursday 2 March 2017

Traverse in all files in directory using Java

Using apache collection to traverse all files in directory with regex
Share:

Wednesday 22 February 2017

Java Enumeration Good Example

Enums are lists of constants. When you need a predefined list of values which do represent some kind of numeric or textual data, you should use an enum. You could enter number or string to get the specific value
Share:

Javascript Example To Call an Ajax

Example code in javascript to call an ajax

function changeDeliveryTime() {

    var deliveryMethod = $('#deliveryMethod').val();
    var delAddress = $('#delAddress').val();
    var schedule = $('#scheduleko').val();
 $.ajax({
  type : "GET",
  url : "/ajaxchangedeliveryschedule.do?deliveryMethod=" + deliveryMethod + "&address=" +  delAddress + "&scheduleId=" + schedule,         
  success : function(response) {
   //successfully change the time
   //alert('successfully change the time');   
  },
  error : function(e) {
   alert('Error changing time schedule: ' + e);
  }
 });
}

Share:

JQuery set maximum date on date input.

This entry will set the max date to 13yrs and below normally use for registration for above 13yrs old only http://stackoverflow.com/questions/16232594/datepicker-set-date-during-page-load
Share:

Some Interview Question

What was your bigger achievement?
"I have several notable accomplishments in my career. Probably the most notable accomplishment was the delivery of the most recent version update to one of our core products for customer payments. This was a 12-month project and I was one of 8 team members. What made it notable for me was that my role expanded from being one of the tech team members to taking the lead on building the mobile components of the product. In order to deliver this aspect of the product, I pulled in three new project resources with specific skills in each of the mobile technology platforms we targeted and cross-trained all project resources to support each platform. In the end, we delivered the product on time and have received numerous accolades, both internal and external. The mobile component was specifically identified to be world class and distinguished the product at its release. Our CEO spent time showing the mobile components to the press and industry and it has since met with excellent reviews. Would you like to see the Android version of the product?"

"I have several notable accomplishments in both my education and my work experience. Probably the most notable accomplishment was delivery of the mobile apps project during my internship this past summer. I joined the tech development team at a time when they were in the process of losing a team member due to relocation. That team member was the lead for the iOS version of the mobile app under development. Since I had already developed two iOS apps and no one else on the team had worked with iOS, I was asked to take the lead for the iOS development and deployment, effectively half of the project. This was outside the original scope of my internship, but definitely mission critical. I was able to deliver the app on time before completion of my internship and have deployed it to the iTunes store. It has already received over 100 positive reviews from customers. Would you like to see it?"

Why do you want to work here?
I have read some review from indeed website on working with WestPac,  and truly while there are few negative reviews,  the positive reviews are quite many to mention.  Another thing is that I have worked with a bank before,  and since the role is related and more or less the process are not that different.    


Where do you see yourself in 2 years time?
“My goal right now is to find a position at a company where I can grow and take on new challenges over time. Ultimately, I’d like to assume more management responsibilities and get involved in product strategy. But most importantly, I want to work for an organization where I can build a career.”

My goal right now is to find a position in a company that I can grow and I can utilize my skills,  Id like to assume more management resposibilites and get involved in the business process improvement specially in the IT area

Why do you think you will be good in this role?
I have more than 10 years computing experience, from system analysis, scoping, development and customer support.  I have worked for standard chartered bank singapore for 3 years doing compliance projects like gifts and entertainment request,  business process improvement and monitoring.
So having a background in banking domain gives me a leverage to know your business process in a short time.

Give us example of a situation in which you were able to anticipate an existing customer's need and propose a compelling solution. What was the outcome of your suggestion? 


How would you manage conflicting priorities?
In my previous project with SCB,  we have 3 division Consumer banking, wholesale banking and group functions each of them got different requirements and different priorities.  So what I did
was to check what's the most important requirement and common to all 3 divisions.  I have also
scope each task and present this to the business, like task 1 will take 2 days, task 2 5 days.  I'll let the business decides which one to prioritize.   If this doesn't work then i asked guidance from my line manager.

Describe a time when you performed a task outside of your job description to help your team members to achieve their goal?
These happens really a long time ago, where in I was part of the y2k conversion,  so these are cobol programs that we need to check for y2k exposure.  So we need to create a report how many lines were affected by these exposure.  but our tools that count those line were not working so I decided to create some script that will parse those text file and count those exposures

VB6 text field

Java copy and paste


Describe a time when you had a conflict within a team and how you resolved it?
asdf

Why do you want to work at WestPac?
asdf

Give me a time where you had to compromise in a team?
asdf




How would your manager describe you?
My coworkers and friends would describe me as hard worker, determined, good planner,
professional, flexible, tolerant and a quick learner.

What experience and skills do you have relevant to the role?
asdf

Why should we hire you?
asdf

How would you approach and solve the (problem)?
asdf

What do I like best about my current role?
asdf

Tell me about yourself?


How do you deal with conflicts?
asdf

Why apply for this role?
asdf

Describe a time where you experienced a challenge and how did you overcome it?  
asdf

Usual top 5 strengths and weaknesses?
asdf

What is the name of our CEO?
asdf

Latest News involving westpac?
asdf

Share:

Different Ways To Read A Text File in Java

There's a lot of way to read a text file in java and listed below are some methods I used.
Share:

How to declare a new exception in Java

Sample java code to declare a new exception.


public class MyNewException extends Exception {
 private static final long serialVersionUID = -7994546786269588726L;

 public MyNewException() {
  super();
 }

 public MyNewException(String msg) {
  super(msg);
 }
}

Share:

Display and Change Date in Ubuntu Terminal

I have this requirements before to run a batch job every day and check the generated records. Of course you don't wait for tomorrows outcome so sometimes we need to age the pc or system date.
Share:

Popular Posts

Recent Posts

Pages

Powered by Blogger.

About Me

My photo
For the past 10 years, I've been playing with codes using PHP, Java, Rails. I do this for a living and love new things to learn and the challenges that comes with it. Besides programming I love spending time with friends and family and can often be found together catching the latest movie or planning a trip to someplace I've never been before.