One of Those Things You Don't Know If You Should Post in Your Blog Or on TheDailyWTF

From Rails, or more specifically, ActiveSupport's json.rb:

# When +true+, Hash#to_json will omit quoting string or symbol keys
# if the keys are valid JavaScript identifiers.  Note that this is
# technically improper JSON (all object keys must be quoted), so if
# you need strict JSON compliance, set this option to +false+.
mattr_accessor :unquote_hash_key_identifiers
@@unquote_hash_key_identifiers = true

AudioFormat 0.4 released

After a longish break, released a new AudioFormat when I noticed how aggravating the current version was :-)

The new version, 0.4, allows you to add files to the list of files to convert via a file selector or by dragging. It also should handle and report errors a bit better. And maybe it'll even recognize Vorbis files? Although I suspect it'll get very confused if it encounters something like Ogg Tarkin files. Will have to work on that a bit more.

Enjoy.

Unit conversion in Java

JUGC is a Java library for unit conversions. It allows you to define a set of units and their relationships (a kilogram is a thousand grams, a tonne is a thousand kilograms, etc), translations for those units (gramma is fi_FI for gram), generate a Java library from those units (well, most of the library won't be generated, but the unit definitions will be) and then deploy that library in a project.

So basically you'll go from unit definitions like this:

    <units>
            <unit>
                    <id>fahrenheit</id>
                    <alias>F</alias>
                    <derive>celsius</derive>
                    <from>9 5 / * 32 +</from>
                    <to>32 - 9 5 / /</to>
            </unit>

            <unit>
                    <id>rankine</id>
                    <alias>R</alias>
                    <derive>fahrenheit</derive>
                    <from>459.67 +</from>
            </unit>
    </units>

to converting units like this:

    ConverterFactory.getConverter("celsius", "rankine").convert(42);

And the translation support is pretty simple, too:

    <units>
            <unit>
                    <id>gram</id>
                    <alias>g</alias>
            </unit>

            <unit>
                    <id>kilogram</id>
                    <alias>kg</alias>
                    <derive>gram</derive>
                    <from>1000 /</from>
            </unit>
    </units>

    <unittrans>
            <locale>fi_FI</locale>
            
            <translation>
                    <unit>gram</unit>
                    <trans>gramma</trans>
            </translation>

            <translation>
                    <unit>kilogram</unit>
                    <trans>kilogramma</trans>
            </translation>
    </unittrans>

And then in your code:

    ConverterFactory.getConverter("gramma", "kilogramma", "fi_FI").convert(42);

The conversion expressions are in RPN.

I have yet to make a release and it's not totally finished — it should be possible to ask for the conversions to be done with arbitrary precision math, for instance — but I believe it's pretty usable already.

License: BSD sans advertising clause.

© Juri Pakaste 2021