Posted on

Killing all Processes by Name with killall

Asked Gradle to stop but it ignored me.

./gradlew --stop

This is the most efficient method to cleanup after Gradle build.

killall java

Disable Gradle Daemon in /.gradle/gradle.properties

org.gradle.daemon=false

This extreme measure was needed to prevent the greedy daemons from gobbling up all the memory, causing host OS swap file size to increase significantly, that would actually slow things down on the contrary to what Gradle daemon is supposed to do, speeding up. It appears to me that Gradle only cares about its compiling time, ignoring the user’s need of memory for fast responsive IDE, UI etc.

Posted on

Windows 10 for WordPress

WordPress site can run on LAMP on Ubuntu on Windows Linux Subsystem.

sshfs to macOS from Linux Subsystem is not available because fuse is not yet implemented on Linux Subsystem. However, the other way around is possible. sshfs mount directory on Linux Subsystem to macOS folder. Or simply use Windows Network File and Folder Sharing and macOS will mount it in the Finder. This makes file sharing between Ubuntu on Windows Linux Subsystem and macOS seamless. By the way, Windows 10 is running in VirtualBox 6.0 on macOS 10.14.

Ubuntu App Opened
Ubuntu App Closed

The processes on Ubuntu are shown up among the processes in Windows Task Manager. This is beyond my expectation and really cool. Look at the apache2 and mysqld in the Background processes!

WordPress Admin Dashboard
WordPress Front-end Admin Logged In
WordPress Front-end Admin Logged Out
Posted on

kotlin_4_js_knockout

settings.gradle.kts

pluginManagement {
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == "kotlin2js") {
                useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}")
            }
            if (requested.id.id == "kotlin-dce-js") {
                useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}")
            }
        }
    }
}

build.gradle.kts

import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile

plugins {
    id("kotlin2js") version "1.3.11"
    id("kotlin-dce-js") version "1.3.11"
}

dependencies {
    implementation(kotlin("stdlib-js"))
}

repositories {
    jcenter()
}

defaultTasks("uglifyjs")

tasks {
    register<Exec>("uglifyjs") {
        dependsOn("runDceKotlinJs")
        /*
        uglifyjs is installed on the system with npm 
        */
        commandLine("uglifyjs", "build/kotlin-js-min/main/kotlin.js", "build/kotlin-js-min/main/koko.js", "-c","-m", "-o", "build/kotlin-js-min/main/koko.min.js")
    }
    compileKotlin2Js {
        kotlinOptions {
            outputFile = "${sourceSets.main.get().output.resourcesDir}/koko.js"
            moduleKind = "plain"
            sourceMap = false
            sourceMapEmbedSources = "never"
            metaInfo = false
        }
    }
}

Main.kt

package okoko
import kotlin.browser.document
import kotlin.browser.window
external fun jQuery(selector: dynamic): dynamic = definedExternally

fun log() {
    println("log from Kotlin for JavaScript!")
}

fun jtext(selector:dynamic,txt:dynamic) {
    jQuery(selector).text(txt)
}

fun index() {
    jQuery("p").click( {
        jtext("p","Thank You, Sir!") 
        log()
    })
    jtext("p","If you click on me, you will be mesmerized.")
}

fun helloworld() {
    js("""
// This is just a copy and paste of knockout.js hello world example 
// from knockoutjs. (https://knockoutjs.com/examples/helloWorld.html)
var ViewModel = function(first, last) {
    this.firstName = ko.observable(first);
    this.lastName = ko.observable(last);
 
    this.fullName = ko.pureComputed(function() {
        // Knockout tracks dependencies automatically. It knows that fullName depends on firstName and lastName, because these get called when evaluating fullName.
        return this.firstName() + " " + this.lastName();
    }, this);
};
 
ko.applyBindings(new ViewModel("Planet", "Earth")); // This makes Knockout get to work
    """)
}

fun boombayah() {
    jQuery(document).ready({
        val title = jQuery("title").text()
        when(title) {
            "index.html" -> index()
            "helloworld.html" -> helloworld()
            "helloworld2.html" -> helloworld2()
            "helloworld3.html" -> helloworld3()
            else -> println(title)
        }
    })
}

fun main(args: Array<String>) {
    println("Welcome to Kotlin for JavaScript!")
    boombayah()
}

Knockout.kt

package okoko
import kotlin.browser.document
import kotlin.browser.window
external val ko: dynamic = definedExternally

object vm {
    fun ViewModel(first:String, last:String): dynamic {
        val me = this.asDynamic()
        me.firstName = ko.observable(first)
        me.lastName = ko.observable(last)
        me.fullName = ko.pureComputed({ "${me.firstName()} ${me.lastName()}" })
        return me
    }
}

fun helloworld2() {
    ko.applyBindings(vm.ViewModel("Knockout", "Cool"))
}

fun helloworld3() {
    val vm3 = js("{}")
    vm3.ViewModel = { first:String, last:String  ->
        vm3.firstName = ko.observable(first)
        vm3.lastName = ko.observable(last)
        vm3.fullName = ko.pureComputed({ "${vm3.firstName()} ${vm3.lastName()}" })
    }
    vm3.ViewModel("Knockout", "Again")
    ko.applyBindings(vm3)
}

index.html

<!doctype html>
<html>
<head>
<title>index.html</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/knockout/knockout-3.4.2.js"></script>
<script src="../build/kotlin-js-min/main/koko.min.js"></script>
<style>
    p {
      font-size: 200%;
      background-color: aliceblue;
    }
    </style>
</head>
<body>

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

</body>
</html>

helloworld.html

<!doctype html>
<html>
<head>
<title>helloworld.html</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/knockout/knockout-3.4.2.js"></script>
<script src="../build/kotlin-js-min/main/koko.min.js"></script>
<style>
    body {
      font-size: 200%;
      background-color: aliceblue;
    }
    </style>
</head>
<body>

<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>
<h2>Hello, <span data-bind="text: fullName"> </span>!</h2>

</body>
</html>

helloworld2.html

<!doctype html>
<html>
<head>
<title>helloworld2.html</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/knockout/knockout-3.4.2.js"></script>
<script src="../build/kotlin-js-min/main/koko.min.js"></script>
<style>
    body {
      font-size: 200%;
      background-color: aliceblue;
    }
    </style>
</head>
<body>

<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>
<h2>Hello, <span data-bind="text: fullName"> </span>!</h2>

</body>
</html>

helloworld3.html

<!doctype html>
<html>
<head>
<title>helloworld3.html</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/knockout/knockout-3.4.2.js"></script>
<script src="../build/kotlin-js-min/main/koko.min.js"></script>
<style>
    body {
      font-size: 200%;
      background-color: aliceblue;
    }
    </style>
</head>
<body>

<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>
<h2>Hello, <span data-bind="text: fullName"> </span>!</h2>

</body>
</html>

Live Demos

https://cloud.ibinti.com/file/ko4js/index.html

https://cloud.ibinti.com/file/ko4js/helloworld.html

https://cloud.ibinti.com/file/ko4js/helloworld2.html

https://cloud.ibinti.com/file/ko4js/helloworld3.html

Posted on

kotlin_4_js_page6

settings.gradle.kts

pluginManagement {
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == "kotlin2js") {
                useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}")
            }
        }
    }
}

build.gradle.kts

import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile

plugins {
    id("kotlin2js") version "1.3.11"
}

dependencies {
    compile(kotlin("stdlib-js"))
}

repositories {
    jcenter()
}

tasks {
    compileKotlin2Js {
        kotlinOptions {
            outputFile = "${sourceSets.main.get().output.resourcesDir}/output.js"
            sourceMap = true
        }
    }
    val unpackKotlinJsStdlib by registering {
        group = "build"
        description = "Unpack the Kotlin JavaScript standard library"
        val outputDir = file("$buildDir/$name")
        inputs.property("compileClasspath", configurations.compileClasspath.get())
        outputs.dir(outputDir)
        doLast {
            val kotlinStdLibJar = configurations.compileClasspath.get().single {
                it.name.matches(Regex("kotlin-stdlib-js-.+\\.jar"))
            }
            copy {
                includeEmptyDirs = false
                from(zipTree(kotlinStdLibJar))
                into(outputDir)
                include("**/*.js")
                exclude("META-INF/**")
            }
        }
    }
    val assembleWeb by registering(Copy::class) {
        group = "build"
        description = "Assemble the web application"
        includeEmptyDirs = false
        from(unpackKotlinJsStdlib)
        from(sourceSets.main.get().output) {
            exclude("**/*.kjsm")
        }
        into("$buildDir/web")
    }
    assemble {
        dependsOn(assembleWeb)
    }
}
Posted on

kotlin_4_js_page3

buildscript {
    ext {
        kotlin_version = "1.3.11"
    }
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
    }
}

apply plugin: "kotlin2js"
apply plugin: "kotlin-dce-js"

repositories {
    mavenCentral()
}

dependencies {
    compile("org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version")
}

defaultTasks "ko4js"
assemble.dependsOn runDceKotlinJs

build.doLast {
    configurations.compile.each { File file ->
        copy {
            includeEmptyDirs = false

            from zipTree(file.absolutePath)
            into "${projectDir}/js"
            include { fileTreeElement ->
                def path = fileTreeElement.path
                path.endsWith(".js") && (path.startsWith("META-INF/resources/") || !path.startsWith("META-INF/"))
            }
        }
    }
}

//Note that if your function has parameters, its name will be mangled, so the mangled name should be used in the keep directive.
runDceKotlinJs.keep "ko4js.okoko.log", "ko4js.okoko.jtext_wn2jw4\$"

task uglifyjs(type: Exec) {
    commandLine "uglifyjs", "build/kotlin-js-min/main/kotlin.js", "build/kotlin-js-min/main/ko4js.js", "-c","-m", "-o", "js/ko4js.core.js"
    // commandLine "uglifyjs", "build/kotlin-js-min/main/kotlin.js", "build/kotlin-js-min/main/ko4js.js", "-b", "-o", "js/ko4js.core.js"
}

task ko4js {
    dependsOn build, uglifyjs, runDceKotlinJs
    uglifyjs.mustRunAfter runDceKotlinJs
}

compileKotlin2Js {
    kotlinOptions.outputFile = "${projectDir}/js/ko4js.js"
    kotlinOptions.moduleKind = "plain"
    kotlinOptions.sourceMap = false
    kotlinOptions.sourceMapEmbedSources = "never"
    kotlinOptions.metaInfo = false
}

task wrapper(type: Wrapper,overwrite: true) {
    gradleVersion = "5.0"
    distributionType = Wrapper.DistributionType.ALL
}
<!doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cloud.ibinti.com/file/ko4js/ko4js.core.js"></script>
<script>
$(document).ready(function(){
  $("p").click(function(){
    ko4js.okoko.jtext_wn2jw4$("p","Thank You, Sir!")
  });
  ko4js.okoko.jtext_wn2jw4$("p","If you click on me, You will be mesmerized.")
});
</script>
</head>
<body>

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

</body>
</html>
Posted on

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.