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

Apache2 VirtualHost


intra.conf

<VirtualHost *:8080>
        ServerName intra
        DocumentRoot /var/www/intra
</VirtualHost>

000-default.conf

<VirtualHost *:80>
        DocumentRoot /var/www/default

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog /var/www/default/error.log
        CustomLog /var/www/default/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

IP address in VirtualHost *:80 directive is the one that apache2 binds. It may be different from the public IP if apache2 is behind proxy, etc. Or It can have multiple IPs. In any case, default will be served if no ServerName matches.

To respond to port 8080, apache2 must listen to it.

port.conf

Listen 80
Listen 8080

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>
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_page5

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 boombayah() {
    jQuery(document).ready({
        jQuery("p").click( { jtext("p","Thank You, Sir!") })
        jtext("p","If you click on me, You will be mesmerized.")
    })
}

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

build.gradle

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/"))
            }
        }
    }
}

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"
}

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
}

Main.kt becomes ko4js.js after gradle build

if (typeof kotlin === 'undefined') {
  throw new Error("Error loading module 'ko4js'. Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior to 'ko4js'.");
}
var ko4js = function (_, Kotlin) {
  'use strict';
  var println = Kotlin.kotlin.io.println_s8jyv4$;
  var Unit = Kotlin.kotlin.Unit;
  function log() {
    println('log from Kotlin for JavaScript!');
  }
  function jtext(selector, txt) {
    jQuery(selector).text(txt);
  }
  function boombayah$lambda$lambda() {
    jtext('p', 'Thank You, Sir!');
    return Unit;
  }
  function boombayah$lambda() {
    jQuery('p').click(boombayah$lambda$lambda);
    jtext('p', 'If you click on me, you will be mesmerized.');
    return Unit;
  }
  function boombayah() {
    jQuery(document).ready(boombayah$lambda);
  }
  function main(args) {
    println('Welcome to Kotlin for JavaScript!');
    boombayah();
  }
  var package$okoko = _.okoko || (_.okoko = {});
  package$okoko.log = log;
  package$okoko.jtext_wn2jw4$ = jtext;
  package$okoko.boombayah = boombayah;
  package$okoko.main_kand9s$ = main;
  main([]);
  Kotlin.defineModule('ko4js', _);
  return _;
}(typeof ko4js === 'undefined' ? {} : ko4js, kotlin);

Now uglifyjs combines ko4js.js with kotlin.js and minify the result to produce ko4js.core.js.

The final ko4js.core.js is ~50KB. Not bad size when considering it is a transpiled JavaScript from Kotlin and jquery.min.js is ~80KB.

ex4.html

<!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>
</head>
<body>

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

</body>
</html>