Oct 14

Using Javascript to Provide Dynamic Content in Tumblr

This article describes how content can be added to Tumblr using Javascript, and the jQuery library. The reader should be familiar with web development.

A Simplified Theme

<html>
<head>
  <title>My Tumblr</title>
  <script type="text/javascript" src="http://example.org/jquery.js"></script>
  <script type="text/javascript" src="http://example.org/tumblr-dyn.js"></script>
</head>
<body>
    {block:Posts}…{/block:Posts}
    <p id="quote-of-the-day" style="display:none"></p>
</body>
</html>

We shall add a quote to #quote-of-the-day for permalink views.

tumblr-dyn.js

var isSinglePostView = function() {
    var loc = document.baseURI;
    var re = new RegExp(".*mytumblr.example.org/post/.*");
    return loc.match(re) != null;
}

$(window).ready(function() {
    if (isSinglePostView()) {
        var qotd = $("#quote-of-the-day");
        qotd.html(
            '"You should\'ve seen the look on her face. It was the same look ' +
            'my father gave me when I told him I wanted to be a ventriloquist."' +
            ' – George Costanza');

        qotd.css('display', 'block');
    }
});

You can use this approach to add custom content depending on what page the user is viewing.


Oct 13

Configuring an SSH Gateway

An SSH gateway can be used where multiple hosts share the same IP address, where it isn’t possible, or acceptable, to use separate ports for the hosts’ SSH daemons.

Read More


How to Include Reddit in Tumblr

I wanted to include a reddit widget in my posts, in order to submit and vote on entries. Here’s a theme snippet that solves the task:

<script type="text/javascript">
    reddit_url = "{Permalink}";
</script>
<script type="text/javascript" src="http://www.reddit.com/button.js"></script>

Put in a simplified tumblr theme:

{block:Posts}
    {block:Text}
        <div class="post text">
            {block:Title}
                <h3><a href="{Permalink}">{Title}</a></h3>
            {/block:Title}
            {Body}
            <script type="text/javascript">
                reddit_url = "{Permalink}";
            </script>
            <script type="text/javascript" src="http://www.reddit.com/button.js"></script>
        </div>
    {/block:Text}
{/block:Posts}

More info on how to customize the reddit widget can be found here.


Oct 12

Enabling NTP in OpenBSD

The system clock in my Sun Ultra 5 drifted away every few days. This is how NTP is enabled in OpenBSD:

$ sudo su -
# echo 'ntpd_flags=""' >> /etc/rc.conf.local

This will cause the ntpd daemon to be started next time you reboot the system. To start it right now, do:

$ sudo ntpd

Last, to make sure the daemon is running correctly, examine the contents of /var/log/daemon:

$ sudo su -
# cat /var/log/daemon | grep ntpd
Oct 12 17:35:50 sverker ntpd[17976]: ntp engine ready
Oct 12 17:36:09 sverker ntpd[17976]: peer 62.20.50.110 now valid
Oct 12 17:36:10 sverker ntpd[17976]: peer 217.118.216.117 now valid
Oct 12 17:36:11 sverker ntpd[17976]: peer 83.241.233.179 now valid
Oct 12 17:36:11 sverker ntpd[17976]: peer 91.194.67.9 now valid
Oct 12 17:36:12 sverker ntpd[17976]: peer 81.234.213.16 now valid
Oct 12 17:37:08 sverker ntpd[19401]: adjusting local clock by 4.491034s
Oct 12 17:40:57 sverker ntpd[19401]: adjusting local clock by 2.992072s
Oct 12 17:43:03 sverker ntpd[19401]: adjusting local clock by 1.459956s
Oct 12 17:47:16 sverker ntpd[19401]: adjusting local clock by -0.598555s
Oct 12 17:50:25 sverker ntpd[19401]: adjusting local clock by -0.347570s
Oct 12 17:50:25 sverker ntpd[17976]: clock is now synced
Oct 12 18:25:26 sverker ntpd[19401]: adjusting local clock by -0.968709s
Oct 12 18:27:36 sverker ntpd[19401]: adjusting local clock by -0.929344s
Oct 12 18:27:36 sverker ntpd[19401]: adjusting clock frequency by -1280.000000 to -1280.000000ppm
Oct 12 18:27:36 sverker ntpd[17976]: clock is now unsynced
Oct 12 18:31:55 sverker ntpd[19401]: adjusting local clock by -0.614471s
Oct 12 18:31:55 sverker ntpd[17976]: clock is now synced

If you are unfamiliar with the sudo and su utilities, I suggest you read this intro and this manpage. The short version is that you substitute user identity (to root, in this case).

Update: As mentioned by joedonut at reddit, it is possible to enable NTP when you install OpenBSD. This article describes how to enable the daemon for users who chose not to do it at install time.



Simon Pantzare
Simon Pantzare, also available on
facebook,
twitter,
reddit,
github.
Ask me anything.