Page 5 of 11

Telling a story

Speaking about emotions, everyone responds differently. That which evokes strong emotion in you probably won’t do the same in your friend, your partner, your kids, your workmates. Or would it? Would you know? How well can you know anyone else? What would the person in the neighbouring cubicle do if you told a joke? Would the laughter be genuine?

Let’s say I have a story to tell. Let’s say it’s a story about a strong man who never receives the affirmation or the words of love he craves from his wife, the person he loves most. He works and strives on her behalf but never hears her say that she loves him. His heart hurts throughout the story, but it’s a good heart and he’s an honourable man, and at the end of the story, he gives up his life to save hers. How? It doesn’t matter. Maybe he throws himself in front of a bullet. Maybe he gives her food when they’re starving. It really doesn’t matter. What does matter is that in the last moments of his life, he realises that she’s been telling him that she loves him all his life, but he never understood. And in those last moments of his life he realises that it was worth it.

Would that make you feel?

Or maybe the story I have is about a woman who wants nothing more in life than what she has. There is no striving, no straining. Her husband loves her like few other husbands love their wives, and nothing is too much for him. Her merest wish is his command. In turn, she loves his company, and holds him at every opportunity. She’s not much one for a lot of words, but she turns their house into a home, and ensures that she does for him everything she can do. And at the end of the story, he makes the ultimate sacrifice, and gives up his life for her. How? It doesn’t matter. Maybe he throws himself in front of a bullet meant for her. Maybe he refuses to eat when they’re starving and gives her the last of their food. It really doesn’t matter. What does matter is that, somehow, they realise that there has been a disconnect, and she says the words she’s never said before. Then she has to go on living, knowing that it wasn’t until those last moments that her husband knew she loved him.

Would that make you feel? Would it make you feel differently?

Or maybe it’s the story of a woman, talking to a counsellor so many years after having lost her husband. “When I was thirty-four,” she says. “Because I remember waking up on my thirty-fifth birthday, and feeling so terribly alone. It’s been more than twenty years now, and I—”

She stops, overwrought. “I never forgave myself,” she sobs, eventually. “But I didn’t know! I just didn’t know—”

So I wonder. Is the job of writing to tell a story? Or is it to tell just a part of the story? I can never really provide more than a snippet, because a person is so much more than a single narrative can contain. It all has to be set in some context, and knowing the context, and then a bit more of the context changes the reader’s feelings.

Belief

Prayer is becoming quite a big part of my life now. I help out as an intercessor on one of Greg Beckenham’s teams, and it occurs to me that belief is a big part of prayer. Greg’s ministry is called “Dare to Believe Ministries”, so me being me, I’ve been thinking a bit about how we believe, what we believe, how it relates to our relationship with God, which is pretty much defined by our prayer life.

It seems to me that there has been a deliberate attack on our capacity to believe. Pretty obviously, our language has evolved over time, and words take on different meanings. Let me give you a few other examples.

  • “I was at SG Friday night, it was unbelieveable!”
  • “You should come to our connect group … it’s incredible!”
  • “This morning’s service was fantastic!”
  • “Ollie’s coffee is unreal!”

By using exaggeration, we talk about our experiences using words that rob them of their reality.

  • Unbelieveable … self-explanatory.
  • Incredible … not credible, not believable. Impossible to believe.
  • Fantastic … a fantasy, not real. Imaginative or fanciful; remote from reality.
  • Unreal … again, not real. Imaginary or illusory.

Hang on, Phil’s just going all pedantic on us. We all know what we mean when we use these words, right? Just hold that thought, because we’ll come back to it in a moment.

Has anyone heard the expression “the willing suspension of disbelief”? It was actually coined by Samuel Taylor Coleridge who suggested that if a writer could infuse [a] “human interest and a semblance of truth” into a fantastic tale, the reader would suspend judgement concerning the implausibility of the narrative. What does this mean? It means that, if the story is good, we suspend our disbelief, and, for an hour or two, we accept that an overdose of gamma radiation will turn an angry man into a big green monster; that good guys never run out of ammo; that cars will explode if shot the right way; and that Kermit the Frog and Miss Piggy can be romantically involved. We shunt aside our native skepticism, and for the duration, we believe.

So I started wondering … Do I suspend my disbelief (or my unbelief) for a period of a couple of hours on Sunday? Do I believe for the duration of a church service? Is it possible that I go back to my ground state of unbelief when I drive of this environment and go home, just as I set aside the adventures of Tony Stark when I leave the cinema?

I’d suggest that our culture trains us to do this. Yes, it says, believe and enjoy the story, but just for this period of time. Because … you know it’s not real. Come on, it’s just not believeable. It’s not credible. It’s a fantasy. And these are the very words we use to describe our experiences with our God.

How can you pray if you don’t believe? Why would you?

But you know what? IT’S ALL REAL!

God is real! He exists! And He exists on a Tuesday at 10am, and on a Friday afternoon at 3pm!

John Eldgredge wrote:

“Right above my bed I think I shall hang a sign that says, GOD EXISTS. You see, I wake most mornings an unbeliever. It seems that during the night, I slip into forgetfulness, and by the time the new day comes, I am lost. The deep and precious truths that God has brought me over the year and even just yesterday seem a thousand miles away. It doesn’t happen every morning, but enough to make it an ongoing reality. And I know I am not alone in this.”

Do you believe? If you believe in Him, you have to accept the lot. You have to believe that Jesus died for you because He loves you. That He rose from the dead and is seated at the right hand of the Father, interceding for us. And that love … that love calls forth a response, a desire to talk to Him. Not necessarily reading prayers out of books, but communing with him, heart to heart.

So stoke the fires of your belief. Have you ever made a deliberate confession of faith out loud since you were saved? A real one, not something that was the result of someone saying “repeat after me”? Try it. Go up to someone during the week and say “You know what? I believe that Jesus died for me.” Or “I believe that Jesus was raised from the dead.” Or “The Holy Spirit is my comforter.” Set an alarm on your phone that will go off on Wednesday at lunch time, and ask you … “Do you believe right now?” I hope you can answer “Yes.”

Bootstrap list views with badges as links

I’m using a Bootstrap list-group containing recently-used search criteria. The user can click a search criteria set in order to re-run the search. However, this wasn’t good enough for the users, because they wanted (reasonably enough) to tweak their search criteria, so I figured that the smart thing to do would be to add a badge to the list-group-items with the caption “edit”. Clicking this would bring up the search criteria editor, and they could tweak to their hearts’ content. Something that looks like this:

searching

Problem #1: the list-group-item was an anchor element, and these can’t be nested, so I couldn’t put the new “edit” anchor inside the badge.

Problem #2: I didn’t want to make the human-readable version of the search into a link because that way, the link wouldn’t cover the whole width of the list-group-item.

What I ended up doing in the PHP was this (I’m using Yii2):

<div class="list-group">
  <?php
  foreach ($recentSearches as $search)
  {
    $edit = Html::a('edit', $search->editUrl);
    $badge = Html::tag('span', $edit, [
      'class' => 'badge',
    ]);

    $clickableCond = Html::tag('div', $search->hrConditions, [
      'condhash' => $search->cond_hash,
    ]);

    echo Html::tag('span', $badge . $clickableCond, [
      'class' => 'list-group-item',
    ]);
  }
  ?>
</div>

This produced a structure that looks like this (roughly):

<div class="list-group">
  <span class="list-group-item">
    <span class="badge">
      <a href="/properties/search?condhash=9fe8">edit</a>
    </span>
    <div condhash="9fe8">
      District EQUALS DISTNAME<br>
      AND Street name CONTAINS STREETNAME<br>
      AND Suburb EQUALS SUBURBNAME<br>
      AND Cancelled = NO
    </div>
  </span>
</div>

With the judicious application of the following styles and script, I achieved what I was looking for.

<style>
span.list-group-item span.badge a {
    color: white;
}
span.list-group-item span.badge a:hover {
    text-decoration: none;
}
span.list-group-item {
    color: #555;
}
span.list-group-item:hover {
    background-color: #f5f5f5;
    cursor: pointer;
}
</style>

<script>
$(document).ready(function() {
  var sel = 'span.list-group-item div[condhash]';
  $(sel).unbind().bind('click', function(evt) {
    var url1 = "/properties/index?condhash=";
    var url2 = $(this).attr('condhash');
    window.location.href = url1 + url2;
    return false;
  });
});
</script>

Annoying display before styles applied

Sometimes, you’ll write a piece of markup for a web page, and surprisingly, it works. Well, almost. If you close your eyes, hit F5, wait a second or so, and then look … it’s perfect! However, if you watch the page load, you can find things being rendered before final styling is applied.

The worst culprit for this sort of thing is when tabs are being used. jQuery or Bootstrap tabs, in particular. You see, your tab set is really a collection of lists and/or divs that are rendered within the page initially without styling. So everything is visible first up. To be blatantly obvious, all of your tab content flashes on to the page, and then, when the styling is applied, all except the active tab disappear.

In case you’re wondering … yes, people do care about this. So how to get around it? Well, I’ve created a CSS class called “initially-hidden”. It looks like this:

.initially-hidden {
  display: none;
}

Then you can apply this class to anything that you want to be hidden while the page is loaded. For instance (using Bootstrap’s tab code):

<div role="tabpanel" class="initially-hidden">
  <!-- Nav tabs -->
  <ul class="nav nav-tabs" role="tablist">
    <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li>
    <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
    <li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li>
    <li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li>
  </ul>

  <!-- Tab panes -->
  <div class="tab-content">
    <div role="tabpanel" class="tab-pane active" id="home">...</div>
    <div role="tabpanel" class="tab-pane" id="profile">...</div>
    <div role="tabpanel" class="tab-pane" id="messages">...</div>
    <div role="tabpanel" class="tab-pane" id="settings">...</div>
  </div>

</div>

If you leave things as they are, you’ll never see the tab, so what you have so far is (at best) a sub-optimal solution.

You also need this bit of code at the end of your page:

jQuery(document).ready(function() {
  $('.initially-hidden').show();
});

So at the end, when the page is fully loaded (including the style sheets), your component will be shown in it’s desired form.

Automatic position when inserting rows

I have a need to make sure that there is always a position value when adding a row to a table. In this case, it’s an attachment position. So this query creates a trigger function (PostgreSQL) that will set the ‘posn’ value appropriately whenever I insert a row.

CREATE OR REPLACE FUNCTION tf_auto_position()
      RETURNS trigger AS
$BODY$
    DECLARE
        nextpos INTEGER;
    BEGIN
        EXECUTE 'SELECT COALESCE(MAX(posn), 0) + 1 FROM ' || TG_TABLE_NAME
            INTO nextpos
        NEW.posn = nextpos;
        RETURN NEW;
    END;
$BODY$
    LANGUAGE plpgsql VOLATILE;

And this is how the trigger is applied to a table:

CREATE TRIGGER ins_attachments
    BEFORE INSERT ON attachments FOR EACH ROW
    EXECUTE PROCEDURE tf_auto_position();

Note that the table must have a ‘posn’ column.

I’ve also had the situation where I’ve had to set the position for rows that are children of another table’s rows. In this case, the EXECUTE statement changes to something like this:

EXECUTE 'SELECT COALESCE(MAX(posn), 0) + 1 FROM ' || TG_TABLE_NAME || ' WHERE foreign_id=$1'
    INTO nextpos
    USING NEW.foreign_id;