Blog

Exploring the .NET CoreFX Part 1: Annotate Pure Methods With PureAttribute
Exploring the .NET CoreFX .net core csharp system.collections.immutable
Published: 2014-11-17
Exploring the .NET CoreFX Part 1: Annotate Pure Methods With PureAttribute

This is part 1/17 of my Exploring the .NET CoreFX series.

A pure method is a method that does not make any visible state changes.

John Carmack, in his article In-Depth: Functional Programming in C++, notes many advantages of pure functions:

Pure functions have a lot of nice properties.

Thread safety. A pure function with value parameters is completely thread safe. With reference or pointer parameters, even if they are const, you do need to be aware of the danger that another thread doing non-pure operations might mutate or free the data, but it is still one of the most powerful tools for writing safe multithreaded code.

Read more...
The Power of Central Banks
Finance / Investing finance
Published: 2014-05-14
The Power of Central Banks

In Europe, the transformation in the sovereign debt market since Mario Draghi’s “whatever it takes” promise in July 2012 has been remarkable. Ireland, which just exited an IMF bailout program in December, can now issue 5-year debt at yields well below 5-year Treasuries.

Put all Maven dependency versions in properties
Maven java maven
Published: 2014-05-02
Put all Maven dependency versions in properties

Because security vulnerabilities in third-party software are so common, it is important to manage the versions of your dependencies and to be prepared to upgrade them quickly. For Maven projects, I recommend putting the versions of all your dependencies in the properties section of your pom.xml. Furthermore, for libraries which require multiple dependency entries in pom.xml, this allows you to ensure you use the same version for all of those dependencies.

For example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <properties>
        <spring.version>3.2.6.RELEASE</spring.version>
        <jackson.version>2.2.3</jackson.version>
    </properties>
    <dependencies>
        <!-- spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- Jackson -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>
    </dependencies>
</project>
Publishing a Java Servlet to Azure Website Using Maven
Maven azure FTP java jetty maven servlet wagon-maven
Published: 2014-05-01
Publishing a Java Servlet to Azure Website Using Maven

This blog post shows how to publish a Java Servlet, encapsulated in a WAR file, to an Azure Web Site using FTP via Maven.

The first step will be to generate a simple servlet using Maven:

1
mvn archetype:generate -DgroupId=com.example -DartifactId=hello-world -DarchetypeArtifactId=maven-archetype-webapp

This creates a simple, Hello World application in the hello-world directory. We can verify it works by running it in a local servlet container using the instructions found in Supporting mvn jetty:run in Maven applications. Add the Jetty maven plugin to pom.xml under the build section:

Read more...
Supporting mvn jetty:run in Maven applications
Maven java jetty maven
Published: 2014-04-30
Supporting mvn jetty:run in Maven applications

When I’m writing a Java servlet using Maven, I find it convenient to be able to run the Java servlet in a local servlet container for testing purposes. This is very easy to do using the Jetty Maven plugin.

To add the Jetty Maven plugin to your project, modify pom.xml as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<build>
    <plugins>
        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.2.0.M0</version>
        </plugin>
        ...
    </plugins>
</build>

You can then run your project in Jetty using the following command:

Read more...
Using Handbrake to Encode Blu-Rays for the Roku
Technology blu-ray handbrake mp4 roku
Published: 2014-04-27
Using Handbrake to Encode Blu-Rays for the Roku

This post is a sibling of my earlier post Using Handbrake to Encode DVDs for the Roku and contains the settings I use for Blu-Ray movies. The instructions apply to Handbrake 0.9.9.

Once again, start with the High Profile preset and then make the following changes:

  • In Output Settings:
    • Set Container = Mp4
    • Ensure Large File Size is checked
    • Ensure Web Optimized is checked
    • Ensure iPod 5G Support is unchecked
  • In Picture:
    • Set Anamorphic = Strict (all Blu-Rays I’ve seen are 1920x1080)
    • Set Cropping = Automatic.
  • In Filters:
    • Set Detelecine = Off
    • Set Decomb = Fast
    • Set Deinterlace = Off
    • Set Denoise = Off
    • Set Deblock = Off
    • Ensure Grayscale is unchecked
  • In Video:
    • Set Video Codec = H.264 (x264)
    • Set Framerate (FPS) = Same as source
    • Set Constant Framerate
    • Set Quality = Constant Quality of RF:20
    • Set Optimise Video = Use Advanced Tab instead
  • In Audio:
    • Create two audio tracks. The first audio track will have:
      • Source = AC3 5.1 (which is what you should have ripped from your DVD)
      • Codec = AAC (faac)
      • Bitrate = 160
      • Samplerate = Auto
      • Mixdown = Stereo
      • DRC = 1.5
      • Gain = 0
    • The second audio track will have:
      • Source = AC3 5.1
      • Codec = AC3 Passthru
  • In Subtitles, keep everything empty. I do not handle subtitles.
  • In Chapters:
    • Ensure Create chapter markers is checked
  • In Advanced:
    • In Encoding:
      • Set Reference Frames = 3 (Default)
      • Set Maximum B-Frames = 3 (Default)
      • Ensure CABAC is checked
      • Ensure 8×8 Transform is checked
      • Ensure Weighted P-Frames is checked
      • Set Pyramidal B-Frames = Normal (Default)
    • In Analysis:
      • Set Adaptive B-Frames = Optimal
      • Set Adaptive Direct Mode = Automatic
      • Set Motion Est Method = Hexagon (Default)
      • Set Subpixel Motion Est = 7: RD in all frames
      • Set Motion Est Range to 16
      • Set Partition Type = Most (Default)
      • Set Trellis = Encode Only (Default)
    • In Psychovisual:
      • Set Adaptive Quant Strength = Middle
      • Set Rate Distortion = Middle
      • Set Psychovisual Trellis = Leftmost Setting
      • Ensure No DCT-Decimate is unchecked
      • Set Deblocking = 0 (Default), 0 (Default)
    • In x264 Encoder Options, set it to b-adapt=2:rc-lookahead=50:direct=auto
Using Handbrake to Encode DVDs for the Roku
Technology dvd handbrake mp4 roku
Published: 2013-12-02
Using Handbrake to Encode DVDs for the Roku

Update 2014-04-27 10:00 PM: See also Using Handbrake to Encode Blu-Rays for the Roku

In a previous post, I noted that I use ffmpeg to convert DVDs to MP4s which will play on my Roku. I recently encountered two problems with this approach. First, the resulting MP4s only include a stereo audio track, so are highly sub-optimal for surround sound systems. Second, for a yet-undetermined reason, Plex (my current preferred media client) will transcode the videos rather than play them directly.

Read more...
Instrumenting a Java Web Application with JMX
Telemetry java jmx
Published: 2013-11-25
Instrumenting a Java Web Application with JMX

Java Management Extensions (JMX) is a technology for managing and monitoring Java applications. JMX instructs application developers how to instrument their applications to expose metrics and management mechanisms, and instructs operations teams how to collect metrics and manage Java applications. JMX is ubiquitous: there are a large number of off-the-shelf commercial and open source tools which speak JMX.

This article is intended for application developers to introduce JMX, to teach them how to create some simple metrics via JMX, and to encourage them to thoroughly instrument their applications with JMX.; This article uses only J2SE 5 and the Java Servlet specification. There may be better, more efficient, or more appropriate ways to add JMX counters to applications using other frameworks. For example, Spring developers should read http://static.springsource.org/spring/docs/2.0.x/reference/jmx.html.

Read more...
Clean Code is Not Threadsafe Code?
Concurrency clean-code thread-safety
Published: 2013-10-05
Clean Code is Not Threadsafe Code?

I am currently reading Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin and I’ve noticed a pattern.

In Listing 2-1, Martin recommends refactoring this code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
private void printGuessStatistics(char candidate, int count)
{
    String number;
    String verb;
    String pluralModifier;
    if (count == 0) {
        number = "no";
        verb = "are";
        pluralModifier = "s";
    } else if (count == 1) {
        number = "1";
        verb = "is";
        pluralModifier = "";
    } else {
        number = Integer.toString(count);
        verb = "are";
        pluralModifier = "s";
    }
    String guessMessage = String.format(
        "There %s %s %s%s", verb, number, candidate, pluralModifier
    );
    print(guessMessage);
}

into this:

Read more...