Posted on Leave a comment

kotlin_4_js_page1

Unified coding model. Kotlin is an interesting programming language that can write codes for both web front-end JavaScript and back-end server side JavaScript as well as server Java Virtual Machine (JVM). Kotlin also does native Android and iOS apps. Kotlin can work things out with existing JavaScript and JVM ecosystems and native C/Objective-C/C++/Swift static, dynamic libraries and frameworks.

In this article, I would like to teach myself on how to target JavaScript with Kotlin.

Official Kotlin documents on the Web: here

Official document recommends to use Gradle build tool. So I will use Gradle to generate JavaScript code from Kotlin code.

Also I would like to use jQuery as an example of existing JavaScript library.

Here is a sample HTML with JavaScript

<!doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("p").click(function(){
    $(this).text("Bless You!");
  });
});
</script>
</head>
<body>

<p>If you click on me, You will be blessed.</p>

</body>
</html>

The JavaScript part of the example above is:

$(document).ready(function(){
  $("p").click(function(){
    $(this).text("Bless You!");
  });
});

I will produce above JavaScript code with Kotlin. Follow me next.

Posted on Leave a comment

The Sun gives off energy for free. Thanks!

How much do we get after all?

The energy rate aka power of sunlight is measured and known to be about 1kW/m^2. In a square area of one meter by one meter, how many people can live? One human consumes about 100W of power for a 2000 Cal diet per day. So if human is caged like a chicken farm, Sun can grow max 10 humans per square meter. How big is the earth normal to sunlight direction? Earth radius is known to be about 64000kM. Simple math of an area of circle is 3.14 * 6400kM * 64000kM = 3.14 x 6.4 x 10 ^6 m x 6.4 x 10^6 m ~ 129 x 10^12 m^2 = 1.29 x 10^14 m^2. Considering non-ideal cases, let us suppose a yield of one human per square meter with 10% efficiency. One million is 10^6, one billion is 10^9, one trillion is 10^12. In a simple calculation, 100 trillion humans can live on earth sustainably. Currently there are less than 100 billion people living on earth. Gee, a thousand times more people still can live with the energy received from generous Sunlight. With 1 dollar for 10kWh rate, 1.29 x 10^14 m^2 x 1kW/m^2 x 1 dollar / 10kWh= 1.29 x 10^15 dollars/h = 1.29 x 10^15 dollars/3600s ~ 358 x 10^9 dollars/s = 358 billion dollars per second. So we seem to receive 358 billion dollars every second from Sun. Everyone on earth should earn 3 dollars per second. The minimum wage should be 10 thousand dollars per hour. Then why are we not rich? Where does all the money go?

Is it really free?

You don’t know until you have to pay for it.

Is it not enough?

If everyone uses a thousand times more energy than needed, it is not enough. We need to find an alternative energy source. One example is well known fossil fuel that captured previously given sunlight and stored in the form of oil, gas and coal, etc. Another is from energy-matter conversion using E=mc^2, the energy captured in the form of matter in the very early stage of our Universe. The fossil fuel is current major energy supplier with a limited inventory. Energy-matter conversion has seen a limited success in the laboratory so far with a promising result to come later. Energy-matter conversion is what the Sun is doing to give us free energy.