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

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() {
    seconds--;
    document.getElementById("countdown").textContent = seconds;
    if (seconds <= 0) clearInterval(countdown);
}, 1000);
Read more

Use PHP header() function to send HTTP headers to client

October 30th, 2017 | #php #http #html

TIL the header() function in PHP that sends raw HTTP headers to a client.

<?php
    header("X-Content-Type-Options: nosniff");
    header("X-Frame-Options: DENY");
?>
<!doctype html>
<html lang="en">
Read more

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