Null coalescing operator in C Sharp, PHP, Bash and SQL

November 27th, 2017 | #csharp #php #bash #sql

TIL about the null coalescing operator in C#, PHP, Bash and SQL. In general, the null coalescing operator returns the result of its first operand—if it exists and is not null.

string siteName = suppliedName ?? "Default Name";

/* is logically equivalent to*/

string siteName = suppliedName != null ? suppliedName : "Default Name";
Read more

Filter by tags in Kirby

November 26th, 2017 | #kirby #php

Since a few days I have made it possible to filter my blogposts by tags. I found it very easy to implement tags in Kirby. In this blogposts I will show you how.

Read more

Compare enums with == instead of equals() in Java

November 22nd, 2017 | #java

TIL you should compare enums with == instead of equals() in Java.

a == SomeEnum.ENUM_VALUE
/* instead of */
Read more

Command man prints “gimme gimme gimme” at 00:30

November 22nd, 2017 | #bash

TIL why the command man print gimme gimme gimme at 00:30. When you run man at 00:30 without specifying the page or with -w, it outputs gimme gimme gimme to stderr.

$ man -w
gimme gimme gimme
Read more

Clear the Secure Enclave if you sell or give away a MacBook Pro with Touch Bar

November 18th, 2017 | #apple #macos

TIL Apple recommends you to clear the Secure Enclave before you sell or give away a MacBook Pro with Touch Bar.

Read more

Passing Default group to form(...) in Play 2.6.x when using group constraints in forms

November 17th, 2017 | #java #playframework

TIL if you pass custom groups to the form(...) method in Play 2.6.x, you also have to pass the group javax.validation.groups.Default explicitly—if you want any of its fields taken into account during the validation process of a form.

Form<FooForm> form = formFactory().form(FooForm.class, Default.class, FooCheck.class).bindFromRequest();
Read more

Do not commit sensitive data to public repositories

November 15th, 2017 | #git #github

Stupid title, right? You probably think it is obvious to not commit sensitive data to public repositories. Well, it is obvious—sort of.

Read more

Make Google Chrome warn you before quitting on Mac

November 13th, 2017 | #chrome #macos

TIL Google Chrome can warn you before quitting (on Mac).

Read more

HashSet in Java is backed by a HashMap instance

November 12th, 2017 | #java

TIL that a HashSet in Java is backed by a HashMap instance.

 * Constructs a new, empty set; the backing <tt>HashMap</tt> instance has
 * default initial capacity (16) and load factor (0.75).
public HashSet() {
    map = new HashMap<>();
Read more

Effectively final variables in Java

November 10th, 2017 | #java

TIL what effectively final variables in Java are.

A variable or parameter whose value is never changed after it is initialized is effectively final.

The Java™ Tutorials: Local Classes

Read more

Optimise local repositories with Git Garbage Collection

November 9th, 2017 | #git

TIL how to optimise local repositories with Git Garbage Collection.

$ git gc
Counting objects: 1278, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (1068/1068), done.
Writing objects: 100% (1278/1278), done.
Total 1278 (delta 234), reused 1096 (delta 102)
Read more

Delete local branches that are merged into HEAD and deleted on remote

November 8th, 2017 | #git #bash

TIL how to delete local branches that are merged into HEAD and deleted on remote.

git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d
Read more

Prevent Google Analytics from making requests to

November 7th, 2017 | #googleanalytics #csp

TIL why Google Analytics makes requests to and how to prevent Google Analytics from making these requests.

Read more

Use Scala match expression in Play Scala template

November 6th, 2017 | #scala #playframework #html

TIL how to use Scala match expression in a Play Scala template.

@badgeColor(subscription: String) = {
    @subscription match {
        case "Authorised" => { primary }
        case "Pending" => { secondary }
        case "Confirmed" | "Paid out" => { success }
        case "Failed" | "Cancelled" => { danger }
        case "Expired" => { warning }
        case "Charged back" => { info }
        case _ => { @* applies also if "Open" *@ light }
Read more 1.0.0 released

November 5th, 2017 |

Saturday 28th October I came up with the spontaneous idea to start a blog. I immediately started to write down what I would need to go live the next day. After going live on Sunday 29th October, it was only about improvements, like making the response time shorter and being mobile-first. After 9 days of development in the evening, after finishing work and studying, I can finally say: 1.0.0 is here!

Read more

Create a seconds countdown in 6 lines of JavaScript

November 4th, 2017 | #javascript #html

TIL how to create a seconds countdown in just 6 lines of JavaScript.

var seconds = document.getElementById("countdown").textContent;
var countdown = setInterval(function() {
    document.getElementById("countdown").textContent = seconds;
    if (seconds <= 0) clearInterval(countdown);
}, 1000);
Read more

In Java 6 == 24

November 3rd, 2017 | #java

TIL that in Java 6 == 24. Let's see how and why.

Read more

How to run JShell on Mac OS X when Java 8 and Java 9 are installed

November 2nd, 2017 | #java #bash #macos

TIL how to run JShell on Mac OS X when both Java 8 and Java 9 are installed. JShell is one of the new features in Java 9. It is a REPL (Read Evaluate Print Loop) for Java, which evaluates declarations, statements, and expressions as they are entered and immediately shows the results.

Read more

Escape single quotes when using Java MessageFormat

November 2nd, 2017 | #java

If you are using Java MessageFormat, you will possibly encounter the issue that single quotes are not rendered.

/* string used in code */
"Hello, it's me!"

/* output */
"Hello, its me!"
Read more

© 2018 Tonny Garić | With from Nijmegen, The Netherlands