Is the “Data Tsunami” bigger in China?

The vast amounts of this era’s digitized data is commonly referred to as “data tsunami”, illustrating the magnitude of its size.

Early stage AI/ML startups do not usually have sufficient data to efficiently train their models, data multiplies per user and therefore the derived usability – non optimization. The ethical bottleneck western companies phase whilst collecting data does not exist in china. Its population and cultural accumulation introduce a relaxed mindset towards personal data furthermore its population vastly exceeds western populations.

I wonder, is China a better data-centric incubator than western countries?

Will western consumers care if models are trained in a different continent? Will they care if it’s “unethical” when compared to western ethics?

Will they know?

Will China win the game?

The Rails Chronicles – The Tales of CRUD – Part 1

A developer using Rails will likely say that they have created a Post resource. In most cases it is meant that a Posts model, a Posts controller with a set of CRUD actions, and some named routes pertaining to that controller (courtesy of resources :posts) were created.

Lets start with resources; resources can be defined as the RESTful syntactic sugar of routes. By using only one line “resources :posts” the rails routing system provides seven different routes mapping to the posts controller actions.

rakeroutes Even thought we have the routes when trying to access the rules return an error. For example if we wanted to display the list of all posts we would have used http://localhost:3000/posts (Assuming the rails server is running and listening on port 3000). The error is pretty descriptive and informative in regards to the missing piece of the puzzle. “uninitialized constant PostsController”, as mentioned each route points to a controller action, in this case rails just informs us that during the HTTP GET request towards the path /posts it tried to access the post’s controller action index, during that action it realized that the post controller is not defined and therefore returned the “uninitialized constant PostsController” as a routing error.

Well, lets fix that! We already know what’s missing so the next step is already clear. Lets create the Posts Controller.

We can generate a Posts Controller using the rails generator named controller. The controller generator can stub out a new controller and its actions, it accepts the name of the controller either CamelCased or under_scored followed by a list of views as arguments.

Therefore in case we would like to generate a Post controller with the index action we would have issued the following command.

Essentially rails will go to controller_generator.rb and by using the template controller.rb it will create the controller using the values we have given to populate the respective variables; seems like rails is doing a lot of work behind the scenes.

By providing generators rails gives us the opportunity to create the vast majority of the code using generators therefore enabling rapid progress towards establishing the base to work from. We can also create our own generators to improve our team’s workflow or customize the existing ones.

Well there’s one alternative that will enable us to understand how to complete the puzzle, using generators creates a lot of files that we will not use in the context of this article.

How about creating the controller manually? By exploring the template rails is using to generate the controller we can pretty much understand what a controller should look like.

So inside our rails app folder under app/controllers we create a new file posts_controller.rb containing the following.

Done! So what happens if we try to access http://localhost:3000/posts?

unknownaction

As per the route /posts rails expects to access the post’s controller index action. Lets go back to the controllers generator syntax;

“The controller generator can stub out a new controller and its actions, it accepts the name of the controller either CamelCased or under_scored followed by a list of views as arguments.”

By exploring the rails controller.rb template with the previous statement in mind it seems that rails defines each view/action as a method; therefore it seems that we should create a method named index in posts_controller.rb.

Done! So what happens if we try to access http://localhost:3000/posts?

templatemissing

The error as the previous one is quite descriptive “Missing template posts/index” since we are accessing /posts the controller is trying to retrieve the view for the index action, seems like the exception has also informed us of the location it searched in for the template so lets head in that directory and create the index template!.

Lets create the view at app/view/posts/index.html.erb (Each controller has its views in a directory using the same name as the controller)

Done! So what happens if we try to access http://localhost:3000/posts?

index_html_erb

Finally we have a meaningful response!

By use of the conventions rails enables us to create applications that follow the Model–view–controller (MVC) pattern using a predefined structure. By initiating out application using the “resources :posts” to generate the routes, rails through the conventions has “guided” us towards connecting the routes with a controller, the controller with an action and the action with a view.

Deploying a databaseless Ruby on Rails application on dokku!

While developing a web-app, there might be some times that you just need a landing page a page that just informs people that you are in the process of creating something great!.

In those instances a database might not be needed, usually what happens you may have created a database and linked it to the application, since most likely you have PostgreSQL selected as the production database and if not configured the application container will not start since the connection will fail.

What if we actually want to deploy without the database?, is ActiveRecord really required in a rails application at which no migrations or data are pushed to a database?

Lets begin with the Gemfile, since we do not need the database lets remove both sqlite3 and pg gems, this will ensure that these gems will not be installed in our production machine once deployed.

2015-06-29_11h34_28

By editing the Gemfile the changes are not reflected at the Gemfile.lock, in order to update the Gemfile.lock just run the bundle install command.

Ok, great so far we have ensured that nothing related to databases (external gems) will not be installed. How about ActiveRecord?.

By default and as per the conventions Rails requires all railties, we can also choose which ones to require. Therefore we need to comment out the “require ‘rails/all” and add the#

require ‘action_controller/railtie’
require ‘action_mailer/railtie’
require ‘active_model/railtie’
require ‘sprockets/railtie’
require ‘rails/test_unit/railtie’

Furthermore since the ActiveRecord is not really loaded due to the changes we need to eliminate all calls to it since will likely raise an exception. Therefore we also comment out the config.active_record.migration_error = :page_load

2015-06-29_11h43_39

 

As per the rails guides just about every Rails application will interact with a database. You can connect to the database by setting an environment variable ENV['DATABASE_URL'] or by using a configuration file called config/database.yml.

Using the config/database.yml file you can specify all the information needed to access your database.

In our case we have no database therefore we don’t really need the configuration file, the file was created automatically as per the conventions, since we already violated the conventions we can assume its safe to delete the config/database.yml.

There are some other calls towards the active record that need to be commented out in order to avoid any unforeseen exceptions,one under config/environments/production.rb and one under config/environments/development.rb

At production.rb we need to comment out config.active_record.dump_schema_after_migration = false and at development.rb the config.active_record.migration_error = :page_load.

2015-06-29_12h27_12

2015-06-29_12h27_54

That should be it!.

In case you have created a database and linked it using dokku, ensure that the database container is deleted before pushing the changes to the remote repository.

(dokku postgresql:delete <db> Delete specified PostgreSQL container)

Some useful links for further reading:

RailsGuides: http://edgeguides.rubyonrails.org/

dokku Project: https://github.com/progrium/dokku

PostgreSQL plugin for Dokku: https://github.com/Kloadut/dokku-pg-plugin

The Ruby Basics – Strings

A String is one of the basic data types included in ruby, it is comprised of a collection of textual characters that may contain digits, letters, symbols and empty characters usually referred to as white space.

> String

Strings can be surrounded by single quotes or double quotes, essentially “Hello, World!” is the same as ‘Hello, World’ in this context.

Thinking of possible scenarios, what will happen if a quote is actually be contained within the string?

“Hello, ” World!” this looks quite odd, ‘Hello, ‘ World!’ this is sort of the same.

To handle this possible cases Ruby defines an escape character ( \ ) without the brackets.

“Hello, \” World!” well  this looks odd as well but it will work! ‘Hello, \’ World!’ .

Wait, since a string really begins and ends with a type of quote just a single quote or a double quote could we use double quotes in case a single quote will be used in the string and vice versa?

Of course!

“Hello, ‘ World!” well  this looks odd as well but it will work! ‘Hello, ” World!’ .

Single quotes and double quotes have other differences, double quotes allow something called string interpolation. Interpolation is a process that allows expressions to be defined and executed directly into Strings.

Lets create a statement that prints the class using interpolation.

> The class of ‘Class’ is String

Usually interpolation is used to incorporate and evaluate expressions when used in conjunction with Strings.

The basic syntax is: #{ruby expression goes here}

On choosing a language

One might be called a “programmer” upon successfully completing a bachelors degree in Computer Science, equipped with a theoretical framework of computer science concepts, some sorting algorithms and data structures, having already written multiple lines of code using multiple OOP  programming languages and even some assembly code.

Even though students are introduced to various programming languages the “market” does not automatically qualifies them as capable Junior Software Developers since it is common that every junior job requires some “working experience” and after graduation students are often left “inexperienced” using the languages used in the outside world like .net , Objective C (iOS) , Ruby mostly used in conjunction with Rails.

But does actually using a language as part of a curriculum equips the student with adequate experience?. Well I thing this is Dependant of the student if I had to answer with a yes or no i would have answered “YES!”, but my background is not really related to human resources.

Usually what counts is the amount of projects and material that was accumulated in conjunction with the studies usually completed in parallel in an ideal situation, I wish I could go back in time.

Well lets work towards getting that experience, that self induced experience, the dilemma that occurs is: shall we really use the languages we already learned or should we learn something new?

Usually people actually stick to what they already know and are fast to drop anything dynamic like ruby and python basing their reasoning on performance, argue and debate mumbling all sorts of valid “mambo jumbo”, but what’s really of most importance, productivity or performance?

Here is another graphic on productivity from the book “From Java to Ruby”
“From Java to Ruby” click the image for further reading.