This is procrastination

Right now, at this exact moment in time, I have work to do. Before me I have a spread of code open in vim, a small JavaScript library that I have to refactor into a jQuery plugin. It is open, but I have made a willful choice to dally here instead. I have #ubuntu on Freenode open through my server and quality 70’s music lined up on Spotify while I play 2048.

So, yeah, procrastination.


More Social Meta updates

I have never used crafted excerpts any more than I use the media library, but today that became a problem. WordPress expects an excerpt when you call get_the_excerpt(). If it doesn’t, it calls wp_trim_excerpt(), which generates a dynamic excerpt from post content. wp_trim_excerpt() doesn’t accept arguments, nor can it be called outside of the main loop, which left me dangling for a dynamic post excerpt.

generate_meta_desc() is designed to run outside of the main WordPRess loop. It takes in the post and an optional word length and trims down the content to a suitable length. If that is still empty, then it falls back to the site’s description.

private function generate_meta_desc($post = null, $word_limit = 55) {
    $desc = '';

    $post = get_post($post);

    if ($post && is_single()) {
        $desc = $post->post_excerpt;

        if (!$desc) {
            // Strip all HTML. If first paragraph was only a linked image, output length will be 0.
            $desc = preg_replace('/<\/p>.*$/s', '', $post->post_content);
            $desc = strip_tags($desc);

            if (str_word_count($desc) > $word_limit) {
                // Trim description to set length and add ellipsis.
                $desc = explode(' ', $desc);
                $desc = array_slice($desc, 0, $word_limit);
                $desc[] = '[...]';
                $desc = implode(' ', $desc);
            }
        }
    }

    if (!$desc) {
        $desc = get_bloginfo('description');
    }

    return $desc;
}

Mountebank Mark

When I was at my worst I had constant manic fits. Anything at all could bring it on — a photo of the kids, a chance meeting, or spontaneous flashbash could set off an anxiety attack. It would spread out over the course of up to a week and diffuse into my daily life. The worst attacks would feed on themselves; I used my own failure to defend myself from the attack to punish myself. It wasn’t that the attack was too much me, no, not at all; it’s all my fucking fault that I failed to fight it. The stupid mess of self-hate and anxiety would stick and build and build and stick and build until it was 4am and I had been away for three days and now I need to go cut up my arm now. Then I’d crash and sleep for a full day. And it never quite went away; there would always be a little left over to tide me over until the next attack.

I had my first anxiety attack in almost two years on Tuesday gone, and it was bad enough that Eadaoin had to talk me down. Things are better now, scout’s honour, but it’s a reminder I’m not all the way there just yet.

I write and design and code for a living. I’m a bonafide self-employed creative who does smart thinky things to make do, and a bunch of people look to me for my talent if not my tact. I have an awesome girlfriend, and kids I love, somewhere far away in the US, and a big house with a cat in Dublin. I’m 34 with grey in my beard and laughter lines around my eyes. Despite all that, I still think I’m a fucking charlatan. I’m a big fat phony.

I mean, on Tuesday afternoon, I acted as a representative of a company. I met another creative and interview them. On Tuesday night I haggled a price for an emergency-all-hands–has-to-be-done-now article. On Wednesday I chaired a Skype conference call to review progress on a project and. At each meeting I expected someone to open up and denounce me as a knownothingfaker. My anxiety spikes with every buzz, ping and flash of my phone. I open every email with the certainty that this is the one with the denouncement.

It’s taken a toll. I’ve put on weight because I eat shit, my back’s all fucked (again) because I’ll be at my desk for twelve hours. I’ll work until 2am and sleep in the guest bed and roll out and go right back to work the next morning.

What I can say in my benefit is that imposter syndrome is a reverse pattern. Most creatives feel that. Two friends I spoke to on Tuesday admitted the same feelings. We’re out there, self-started and educated in position that demand we make binding choices that derive from our expertise. We all stumble through the day terrified that an Actual Adult will call us out.

The shared impostor syndrome leave me upbeat and convinced that I’m just at a rough spot on the path to good places. I took today off to reflect and relax. I stayed in bed until after 11. I laughed at a SJW while she shouted at me on Twitter, and I beat my old 2048 high score with panache. I need to edit an article tonight after dinner, but that’s it. Maybe a film and more 2048 while Eadaoin laughs at me and doubles down on my best score.

After today I need to chill out, mark a definite end to the work day and pay attention to Dublin and my girlfriend.


Porn, porn, porn

I’m at the bottom of kind of rabbit hole where you stand knee-deep in shit and wonder how the fuck you got here. So two of my last three articles were on the subjects of the Apache log file and regular expressions. Then this morning a plagiarized article popped up on Reddit.

The plagiarism was so bad that it hotlinked to the assets of the original article. Whoever ripped off the article had no fucks to give. Now, I know it isn’t hard to detect a hotlinked image and then block it (or redirect it to horse porn), but I don’t care as a rule. Still — I was curious about who hotlinks to my site. I attacked my one million line log file because I wanted the information without clicking around a website.

I went through a few iterations of searches until I hit on this query:

grep -v -P '(bhalash|google|baidu|yahoo|bing|yandex)' access.log | sed 's/^.*http/http/' | awk '{print $1}' | sed 's/)\?"//g' | sort | uniq -c | grep -P '(porn|sex|x{2,5}|adult|video)'

You will already know Google, Yahoo! and Bing, but Yandex are a big Russian search portal, and Baidu are a Chinese counterpart. I also excluded referrals from bhalash.com because I link between posts. Once I had excluded the search engines, what I had left was porn, lots of porn. Teen porn, amateur porn, video porn, fetish porn and fattie porn. There hundreds of backlinks to my site from spammy sites who want to boost their search engine rank.

The best worst part is that I can’t even list these sites without either giving them traffic or winding up on on a spam blacklist.


Recursive sass asset manager

I have a stack of assets that needed a minimum-fucking-around solution to manage and load on demand, so I came up with this function: Call it with a mandatory asset and optional variants, and it returns the path to the asset wrapped in url($foo);.

@function asset($asset, $variants: null) {
    $asset: map-get($assets, $asset);

    @if ($variants) {
        @each $variant in $variants {
            $asset: map-get($asset, $variant);
        }
    }

    @return url($asset);
}
$assets: (
    brand: (
        tuairisc: (
            black: $brands + 'tuairisc-black.svg',
            white: $brands + 'tuairisc-white.svg'
        ),
        foras: (
            black: 'foras-black.svg',
            white: 'foras-white.svg'
        ),
        greann: $brands + 'greann.svg'
    )
);

For example (yes, the selector is cancer; it’s a theme engine tied to the <body> tag):

body[class*=section]:not(.section-greann) a#home {
     background: center/contain no-repeat asset(brand, tuairisc white);
}

The function looks for brand, and then recursively fetches tuairisc white. Compiled output is:

body[class*=section]:not(.section-greann) a#home {
     background: center/contain no-repeat url('assets/images/brands/tuairisc-white.svg');
}