Git branch from a specific commit

May 7th, 2014

Yet more git syntax I keep forgetting. To branch and create a new line of development from a specific commit, do the following:

git branch newbranchname a9c146a09505837ec03b

Add the -b switch to immediately checkout after branching.

Since the commit will likley be behind, use --force when pushing to tell git to ignore future commits from the original branch and start a new fork.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Know your CSRF timeouts

May 1st, 2014

Web development frameworks such as Symfony these days bake-in a number of security features, CSRF protection being a fairly common one. I recently made the mistake of not scrutinizing Symfony’s CSRF protection defaults, which led to occasional confusing CSRF errors after a web app had been deployed.

CSRF protection embeds a code into both the generated form and some client-side storage mechanism (cookies, though I suppose this could work with an HTML5 client-side database or whatnot). On submit, if the value embedded into the form and the cookie value match, then we know the form is submitted by the user who originally requested it.

In Symfony, the CSRF cookie lifetime can be configured, defaulting to null, which falls back to session.cookie_lifetime value from php.ini. I had originally set this to be one hour, probably based on configuration examples from a year or so back..

Anyway, app users lately have been leaving forms open for more than an hour. This is a good thing: It means they are treating our web app more like a client side app, which indeed it is meant to replace. Took some sleuthing, however, to figure out why I was seeing the occasional CSRF error when everything else seemed hunky dory. I’ve now set this to

which will retain the cookie for the length of the browser session.
Lesson learned. Know your timeouts. And for that matter, plan some time to review old assumptions.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Cache invaldiation, naming things, and vertically aligning the damn checkboxes

April 24th, 2014

One of the two three hard things in computer science solved:

http://stackoverflow.com/questions/306252/how-to-align-checkboxes-and-their-labels-consistently-cross-browsers

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Use “the big E” for quick and clean monitoring

April 3rd, 2014

Despite all the great tools out there these days for monitoring, it’s difficult to get away without writing a custom monitoring script or two. Spools, various types of cache, multi-server indexing. So many things that can go wrong.

Once upon a time I used to write quick and dirty complex scripts that would email in one case, otherwise do some-such-thing, etc. They were brittle with questionable reliability. Talk about a false sense of security.

These days I like to use an untouted feature of mail to keep things simpler. The idea is to only make noise when there is a problem. If all is well, keep silent.

Take this cron job for example:


*/5 * * * * root /somedir/check-spool.sh | mail -E -s 'Spool Monitor' problem@somedomain.com

check-spool.sh will do just that: Check a spool each time it is run. If everything is fine, no output. If it finds a problem then it outputs what it finds. The “big E” (-E) switch tells mail to ignore any body-less input, and will therefore only spam us when there is some panic-worthy output.

Thanks big E.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

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

March 9th, 2014

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.

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

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

February 14th, 2014

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.

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...

Simple Twig Fallback

February 6th, 2014

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() }}

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

ElasticSearch Delete All

January 13th, 2014

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.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Bananas for Fruitcake: Hipsters Explain the Collapse

September 11th, 2013

This is awesome on many levels.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Not Defined and Not Empty/Null in Twig

May 1st, 2013

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.

1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 5.00 out of 5)
Loading ... Loading ...