ReactJS: Synthetic Mouse Event Properties Null

While working with ReactJS, I added a click handler. I used console.log to dump the event object passed into the handler, but all the properties on the SyntheticMouseEvent were null.

synthetic-event

An insightful tip via StackOverflow point me in the right direction. Chrome and React interact strangely with the event object in this situation: Chrome does not copy the properties, and by the time Chrome prints the object to the console, React has nulled out the values. But at runtime, the properties are not actually null, they’re there.

Just reference your synthetic event properties directly instead of trying to dump the entire object.

Enable Custom Configuration Files in Lumen

Lumen does support custom configuration files, but they need to be enabled first.

You need to add calls to $app->configure('file.php') in your bootstrap/app.php. A cleaner method might be to make a config.php to contain the configure calls and then include that file from bootstrap/app.php.

If you want to use .env values directly, you can also uncomment Dotenv::load(__DIR__.'/../'); at the top of bootstrap/app.php. That will allow getenv('name') to work.

Rename extensions with the terminal

I had a directory full of files with the same extension, and a script was design to process any file in the given directory with that specific extension – to ignore the processing on a file, all I had to do was rename the extensions of all the files except the one I wanted to process specifically.

There’s a great answer on Ask Ubuntu, of all places.

rename ‘s/.original$/.new/’ *.new

SML: operator and operand don’t agree

I am tired of having to look this up every time I forget everything I know about SML.

Error: operator and operand don’t agree [tycon mismatch]
operator domain: ‘Z * ‘Y
operand: ‘Z

When you get this error, you have called a function with the wrong argument types.

The operator domain is what the function called expects, and the operand is what the function was called with.

To fix the problem, call the function with the proper arguments.

You can learn more about a variety of SML errors at the SML NJ error document.

Laravel 5 Released!

Laravel 5 was released yesterday. It’s a more humane version of the anti-monolithic Symfony. For the last couple weeks, I have been reading, learning and experimenting with Laravel and it has been great.

I have been tinkering and tweeting about it occasionally. Everyone needs a PHP framework in their life.

Rust: Btree Implementation

In my Algorithms class a few years ago, my professor said it would take a couple weeks to suss out a good Btree algorithm from the algorithmic aether. From his warning, it is not something I would want to do (or be qualified to partake in).

Here is the story of a naive to a complex but performant Btree implementation in Rust.

Rust: core::ops::Fn(char) -> bool

Here’s a Rust error:

error: the trait core::ops::Fn(char) -> bool is not implemented for the type &str

I was trying to split a string of numbers with spaces a delimiter. Here’s the line for which this error occured:

Apparently, split was expecting a single character, not a substring. This obtuse error was easily solved by changing the double-quotes to single-quotes.

Rust WarGame

I have been trying Rust out lately. Rust is a systems language like c/c++ but uses newer and more modern programming styles (so I am told). The WarGame has existed in Java form for years but this is the first time I have a fairly acceptable native solution. If you want to give it a try, you can compile the source yourself or you can ping me for a binary.

PHP: “??” RFC Proposal

The isset-ternary operator pattern is common in PHP:

This proposal would shorten that:

I am not a huge fan of the syntax, but it is nice syntactic sugar anyway.