React.Component cannot use getInitialState

When React 0.13 was launched, you no longer needed to use React.createClass.

These are basically the same.

class YourComponent extends React.Component {
  constructor(props) {
    super(props);
    this.state = { /* initial state */ };
  }
}
var YourComponent = React.createClass({
  getInitialState() {
    return { /* initial state */ };
  },
});

getInitialState won’t work when you are using React.Component. Using it will show up as an error in your console:

Warning: getInitialState was defined on YourComponent, a plain JavaScript class. This is only supported for classes created using React.createClass. Did you mean to define a state property instead?

Btw, The React community is moving closer to ES6. Also it is considered as the best practice.

 Your password has expired. To log in you must change it using a client that supports expired passwords

Started GET "/" for 127.0.0.1 at 2017-03-14 05:29:35 +0800

Mysql2::Error (Your password has expired. To log in you must change it using a client that supports expired passwords.):

This is an instance I encountered a few days ago. Apparently, MYSQL allows users to automatically expire passwords.

To fix the issue, log in to your MySQL console using your old password.

You will need to alter your password by using the following command:

ALTER USER `root`@`localhost` IDENTIFIED BY 'new_password', `root`@`localhost` PASSWORD EXPIRE NEVER;

Here it is in action!

$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.10

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use database your_database
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> ALTER USER `root`@`localhost` IDENTIFIED BY 'new_password', `root`@`localhost` PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.00 sec)

mysql> \q
Bye

Voila! done!

 Loop through multiple arrays in Ruby

Loops are one of the first things you learn in programming. Here is a way to loop through multiple arrays in ruby.

first = Array(1..16)
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
second = Array(19..34)
=> [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34]

Loop through 2 arrays in Ruby

first.zip(second).each {|b| puts b}
=> [[1, 19],
 [2, 20],
 [3, 21],
 [4, 22],
 [5, 23],
 [6, 24],
 [7, 25],
 [8, 26],
 [9, 27],
 [10, 28],
 [11, 29],
 [12, 30],
 [13, 31],
 [14, 32],
 [15, 33],
 [16, 34]]

Loop through 3 arrays in Ruby

first = Array(1..16)
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
second = Array(19..34)
=> [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34]
third = Array(37..52)
=> [37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52]
first.zip(second, third).each {|b| puts b}
=> [[1, 19, 37],
 [2, 20, 38],
 [3, 21, 39],
 [4, 22, 40],
 [5, 23, 41],
 [6, 24, 42],
 [7, 25, 43],
 [8, 26, 44],
 [9, 27, 45],
 [10, 28, 46],
 [11, 29, 47],
 [12, 30, 48],
 [13, 31, 49],
 [14, 32, 50],
 [15, 33, 51],
 [16, 34, 52]]

Voila!

 Using Serialized data in Rails ActiveRecord

In the previous article, How to Add a Blob using Rails ActiveRecord, we needed to use a blob to store large data. We added a blob data type via the migration file.

class AddMonthsToNyC240 < ActiveRecord::Migration
  def self.up
    add_column :ny_c240s, :weeks52, :binary, :limit => 10.megabyte
  end
  def self.down
    remove_column :ny_c240s, :weeks52 end
  end
end

We migrated the file:

== 20161029155357 AddMonthsToNyC240: migrating ================================
-- add_column(:ny_c240s, :weeks52, :binary, {:limit=>10485760})
   -> 0.1093s
== 20161029155357 AddMonthsToNyC240: migrated (0.1095s) =======================

Now we need to add some functions to the ActiveRecord Model

class NyC240 < ActiveRecord::Base
  serialize :weeks52
end

Voila! You can now save data here and ActiveRecord will automatically know if it is a Hash or Array.