Kotlin Native 1.0 was quietly released today. No announcement, no blog post. I thought v1.0 would be a bigger deal and would have some announcement.
HOWTO and stuff...
Notes to keep
Friday, October 12, 2018
Thursday, October 4, 2018
Why Kotlin does not use new keyword when creating a new instance?
The answer is
1) Kotlin functions are first-class
2) A constructor is a function that can be assigned to a property of a function type, passed as an argument to a higher-order function or returned by a higher-order function.
class Foo
val foo : () -> Foo = ::Foo
val a : Foo = foo() // Creating a Foo through a property
val b : Foo = Foo() // Creating a Foo directly by calling a
// constructor
val c : Foo = new Foo() // <-- Incorrect syntax that clearly shows
// that "new" keyword has no place in
// a language where functions
// are first-class
1) Kotlin functions are first-class
2) A constructor is a function that can be assigned to a property of a function type, passed as an argument to a higher-order function or returned by a higher-order function.
class Foo
val foo : () -> Foo = ::Foo
val a : Foo = foo() // Creating a Foo through a property
val b : Foo = Foo() // Creating a Foo directly by calling a
// constructor
val c : Foo = new Foo() // <-- Incorrect syntax that clearly shows
// that "new" keyword has no place in
// a language where functions
// are first-class
Wednesday, February 14, 2018
How to get a list of file names from gradle runtime dependencies
If you need a list of file names from runtime (or other type of) dependencies, this is one way to do it:
def files = []
configurations.runtime.files.forEach() { f ->
files += f.name
}
The list can be helpful if you need to put it as a Class-Path attribute of JAR manifest file:
jar {
manifest {
def files = []
configurations.runtime.files.forEach() { f ->
files += f.name
}
attributes("Class-Path": files.join(' '))
}
}
def files = []
configurations.runtime.files.forEach() { f ->
files += f.name
}
The list can be helpful if you need to put it as a Class-Path attribute of JAR manifest file:
jar {
manifest {
def files = []
configurations.runtime.files.forEach() { f ->
files += f.name
}
attributes("Class-Path": files.join(' '))
}
}
Monday, December 18, 2017
Service worker and authentication in a Polymer app
In order to sign in with a Google account or to sign out, a web app running on Google App Engine needs to navigate to a URIs that start with /_ah. If the app is configured to use a service worker, the service worker will intercept these URIs and won't allow the sign-in/sign-out flow to continue.
In order to enable sign-in/sign-out for a Polymer app, polymer.json configuration needs to specify swPrecacheConfig option, e.g.:
"builds": [
{
"preset": "es6-unbundled",
"swPrecacheConfig": "sw-precache-config.js"
}
In order to enable sign-in/sign-out for a Polymer app, polymer.json configuration needs to specify swPrecacheConfig option, e.g.:
"builds": [
{
"preset": "es6-unbundled",
"swPrecacheConfig": "sw-precache-config.js"
}
And sw-precache-config.js file needs to specify navigateFallbackWhitelist option:
module.exports = {
// Everything except '/_' prefixes
navigateFallbackWhitelist: [/^(?!\/_).*/]
};
When built with these options, the generated service worker will allow a Polymer app to successfully navigate to sign-in/sign-out URIs.
See Generating a Service Worker for more information.
Sunday, December 17, 2017
Debugging an AppEngine app locally using IntelliJ Community Edition
This post puts together information that is spread across different GCP documents.
First, configure appengine.run.jvmFlags in build.gradle as described here:
appengine {
run {
jvmFlags = [
'-Xdebug',
'-Xrunjdwp:transport=dt_socket,' +
'server=y,suspend=y,address=5005'
]
}
}
Second, configure remote debug configuration as shown here.
In order to debug the app, start the local server from the Gradle or Maven toolbox in the margin of your IDE, or run
gradle appengineRun or gradle appengineStart
from the command line.
Then choose the remote debug configuration on the top toolbar and click Debug icon.
First, configure appengine.run.jvmFlags in build.gradle as described here:
appengine {
run {
jvmFlags = [
'-Xdebug',
'-Xrunjdwp:transport=dt_socket,' +
'server=y,suspend=y,address=5005'
]
}
}
Second, configure remote debug configuration as shown here.
In order to debug the app, start the local server from the Gradle or Maven toolbox in the margin of your IDE, or run
gradle appengineRun or gradle appengineStart
from the command line.
Then choose the remote debug configuration on the top toolbar and click Debug icon.
Monday, December 4, 2017
Leap years in Android CalendarView
Use CalendarView with caution.
MonthView uses Utils.getDaysInMonth() that defines a leap year as follows:
case Calendar.FEBRUARY:
return (year % 4 == 0) ? 29 : 28;
And this is how a leap year should be defined:
Exactly Which Years Are Leap Years?
We add a Leap Day on February 29, almost every four years. The leap day is an extra, or intercalary, day and we add it to the shortest month of the year, February.
In the Gregorian calendar three criteria must be taken into account to identify leap years:
This means that in the Gregorian calendar, the years 2000 and 2400 are leap years, while 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years.
So, 2100 is not a leap year, but according to Android, it is:
There are more problems related to CalendarView. For example, the control does not allow a user to select February 29, 2100, but it allows to select February 28. Again, be cautious.
MonthView uses Utils.getDaysInMonth() that defines a leap year as follows:
case Calendar.FEBRUARY:
return (year % 4 == 0) ? 29 : 28;
And this is how a leap year should be defined:
Exactly Which Years Are Leap Years?
We add a Leap Day on February 29, almost every four years. The leap day is an extra, or intercalary, day and we add it to the shortest month of the year, February.
In the Gregorian calendar three criteria must be taken into account to identify leap years:
- The year can be evenly divided by 4;
- If the year can be evenly divided by 100, it is NOT a leap year, unless;
- The year is also evenly divisible by 400. Then it is a leap year.
This means that in the Gregorian calendar, the years 2000 and 2400 are leap years, while 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years.
So, 2100 is not a leap year, but according to Android, it is:
There are more problems related to CalendarView. For example, the control does not allow a user to select February 29, 2100, but it allows to select February 28. Again, be cautious.
Friday, October 20, 2017
Adding a dependency to compileReleaseSources or compileDebugSources
Simply adding a dependency to compileReleaseSources causes a gradle error.
compileReleaseSources.dependsOn 'someTask'
Could not get unknown property 'compileReleaseSources' for project
The dependency need to be added in whenTaskAdded closure:
tasks.whenTaskAdded { t ->
if (t.name in ['compileReleaseSources', 'compileDebugSources']) {
t.shouldRunAfter 'someTask'
t.dependsOn 'someTask'
}
}
Note that you need both t. shouldRunAfter (or t.mustRunAfter) and t.dependsOn.
compileReleaseSources.dependsOn 'someTask'
Could not get unknown property 'compileReleaseSources' for project
The dependency need to be added in whenTaskAdded closure:
tasks.whenTaskAdded { t ->
if (t.name in ['compileReleaseSources', 'compileDebugSources']) {
t.shouldRunAfter 'someTask'
t.dependsOn 'someTask'
}
}
Note that you need both t. shouldRunAfter (or t.mustRunAfter) and t.dependsOn.
Subscribe to:
Posts (Atom)