JMS\Serializer\Exception\RuntimeException: “Resources are not supported in serialized data…” Yadda yadda

Been bit by this a couple of times now. It’s really a problem with a bad route. In my case I had some ajax using the FOSJsRoutingBundle to generate a route along the lines of:

Routing.generate('some_titles', {id: $(this).val()});

where val() was actually returning an empty string. The resulting URL (“some//titles”) was invalid, looks to JMSSerializer like a resource thanks to the double slash, and badda bing badda boom: completely irrelevant error.

I think this may also be the source of “Cannot redeclare class Doctrine\ORM\Mapping\Annotation” errors to boot. Double whammy.

Couldn’t reserve space for cygwin’s heap, Win32 error 0

Cygwin and Windows git stopped playing nicely together after a recent Windows update. There’s a variety of recommendations for how to fix this this on StackOverflow and elsewhere, but this post actually makes the most sense. In a nutshell, msys-1.0.dll (installed into your Program Files\Git\bin directory) is not built to be position independent. Use the dll rebaser to get it to load at a new address, like so:

$ rebase.exe -b 0x50000000 msys-1.0.dll

And voila, git goodness restored.

Simple Twig Fallback

Love the simplicity of Twig; mainly that it allows us to do away with the conditionals that tend to litter most interface code.  You know the drill: If this then show that otherwise show the other thing except in such-and-such a case..  Confusing and brittle.  Twig’s hierarchical layout is the way to go.

Falling back to a parent block depending on complex output can be tricky however.  Here’s a simple way to do it without a bunch of ifs:

Yay. If less.

Or with one ternary conditional if running parent() through default() is unclear:

{{ details|trim|raw ?: parent() }}

ElasticSearch Delete All

Even though it’s not documented anywhere (as far as I can tell), I probably should have realized this would work:


$ curl -XDELETE http://localhost:9200/
{"ok":true,"acknowledged":true}

Deletes all indices in one fell swoop. Nuclear option. Use caution.

Defeating mysterious “This form should not contain extra fields” errors in Symfony Forms

I love the Symfony framework, but really hate the form component at times. Two years after the initial release of Symfony 2 and we’re still waiting on some decent form validation debugging.

But enough griping. If you’ve ever worked with form events, then undoubtedly you have run into the This form should not contain extra fields error. Basically what it means is that the request parameters don’t match up with the form against which you’re trying to validate.

“Yes, but.. but.. which parameters??” I hear you ask.  Try this:

 

Those “extra data” parameters.

 

Not Defined and Not Empty/Null in Twig

Long time no write.  Came across some syntax today that solves an old annoyance in Symfony's Twig.

Rather than blather on in code with the following complex statement to make sure that a value is both defined and not null:

{% if var is defined and var is not null %}

one can instead simply do this:

{% if var|default is not empty %}

or even more simply:

{% if var|default %}

Nice.

Redacted

If you’ve ever seen Stan Friedman talk about UFO’s, you’ve probably seen his shtick about redacted documents.

For example:

Always loved that.

Well, move over Stan. Apparently the U.S. government has even bigger secrets than aliens.

“But how else would we prevent war?”

Some time back I found myself discussing the fate of the Euro and the European Union with folks from academia-land. I was, and remain, rather confident that what is apparently an ill-conceived political shotgun polygamy will not survive another five years in any significant manner, at least not without some kind of military intervention.  Multiple cultures with their own economies and their own sovereign debt…  And Goldman Sachs lending a helping hand to fund it all. What could go wrong?

Anyway, academia argued the following point:  Only by binding the nations of Europe and “controlling” them with a single currency could humanity be spared another World War.

Which at first sounds reasonable… until we look at what multinational central financial planning has wrought.  Austerity, violent unrest, and talk of civil war.  I suppose convincing what remains of each nation state to commit suicide would prevent a “world” war, sure.

In my opinion, war — any war — is best prevented, not via centralized control, but organically through trends that have been evolving naturally:  Increased travel and improved communication.  Increasing freedom and understanding.  It’s difficult to hate your neighbors, murderously, when you understand them, even dine with them.  And since the second World War, technology has enabled a global renaissance in communication, travel, and as I see it, a trend towards a world of disparate yet harmonious cultures.

So how else would we prevent war?  Allow cultures to communicate.  Give them the freedom to self-actualize.  And stop with the centralized meddling.