ARTLUNG LAB Share

Created in Febuary 2018: Markov Chains are Hilarious!

BloggingBot Source Code

PHP & HTML (bloggingbot.php)

<?php
require_once '../../loader.php';
$rand = rand(0, 9999); // there are 10,000 sentences in the file
$sentences = file("sample_sentences.txt");
$line = $sentences[$rand];

if (isset($_GET['bloggingbot'])) {
    $defined = $_GET['bloggingbot'];
    // must be numeric and from 0 to 9999
    if (is_numeric($defined) && $defined >= 0 && $defined <= 9999) {
        $line = $sentences[$defined];
        $rand = $defined;
    }
}

$canonical_url = "https://lab.artlung.com/bloggingbot/$rand";
$og_image_url = "https://files.artlung.com/lab.artlung.com/bloggingbot/og-bloggingbot-$rand.jpg";
$og_description = "BloggingBot (2018) is a bot based on 17 years of blog posts from artlung.com.";
$share_url = 'https://shareopenly.org/share/?url=' . urlencode($canonical_url) . '&text=' . urlencode($line);


?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title><?php print $line; ?></title>
    <?php printf("<script>var itemId = %s;console.log(%s)</script>\n", $rand, $rand); ?>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="webmention" href="https://webmention.io/lab.artlung.com/webmention" />
    <?php
        printf('<link rel="canonical" href="%s" />', $canonical_url);
        print "\n";
        printf('<meta property="og:image" content="%s" />', $og_image_url);
        print "\n";
        printf('<meta property="og:description" content="%s" />', $og_description);
        print "\n";
    ?>
    <link rel="stylesheet" href="bloggingbot.css<?php
        echo '?' . filemtime('bloggingbot.css');
    ?>">
    <script src="bloggingbot.js<?php
        echo '?' . filemtime('bloggingbot.js');
    ?>"></script>
    <script src="/2025.js<?php
    echo '?' . filemtime('../2025.js');
    ?>"></script>
</head>
<body>
<header>
<h1><?php echo $line; ?></h1>
</header>
<section>
    <button popovertarget="about-bloggingbot">About BloggingBot</button>
    <div popover id="about-bloggingbot">
        <p>
            I created BloggingBot as a <a href="https://twitter.com/bloggingbot" target="_blank">Twitter</a> bot in 2018.
            I fed into the Python library <a href="https://github.com/jsvine/markovify" target="_blank">Markovify</a> 17 years worth
            of blog posts from <a href="https://artlung.com" target="_blank">artlung.com</a>, creating thousands of sentences.
        </p>
        <p>
            The blog post:

            “<a href="https://artlung.com/blog/2018/02/23/markov-chains-are-hilarious/" target="_blank">Markov Chains are Hilarious!</a>”
        </p>

        <p>The <a href="source.php" target="_blank">source code</a>
        </p>

        <p style="text-align: end">
            <strong>
                <a href="<?php print $share_url ?>" id="share" target="_blank">SHARE</a>
            </strong>
        </p>
    </div>
</section>
<nav>
    <a href="/" class="btn" title="go to lab.artlung.com"><span>lab</span><span>.artlung</span><span>.com</span></a>
    <em><a href="/bloggingbot/" id="loadRandom" class="btn" title="load another random Markov chain based on artlung.com">random++</a></em>
</nav>
</body>
</html>

JavaScript (bloggingbot.js)

function randomWebColor() {
    var number_of_colors = 0xffffff;
    var num = Math.round(Math.random() * number_of_colors);
    return ('#0' + num.toString(16)).replace(/^#0([0-9a-f]{6})$/i, '#$1');
}

function foregroundColorFromWebColor(color) {
    // #RRGGBB
    // 0123456
    var bg = {
        R: parseInt(color.substr(1, 2), 16),
        G: parseInt(color.substr(3, 2), 16),
        B: parseInt(color.substr(5, 2), 16)
    };
    var nThreshold = 105;
    var bgDelta = ((bg.R * 0.299) + (bg.G * 0.587) + (bg.B * 0.114));
    return (255 - bgDelta < nThreshold) ? '#000000' : '#ffffff';
}

function loadSentence(itemId) {
    var url = 'bloggingbot.ajax.php?id=' + itemId + '&format=json';

    fetch(url)
        .then(response => response.json())
        .then(data => {
                document.querySelector('h1').innerHTML = data.sentence;
                document.querySelector('title').textContent = data.sentence;
                // rel canonical
                var canonical = document.querySelector('link[rel="canonical"]');
                if (canonical) {
                    canonical.href = 'https://lab.artlung.com/bloggingbot/' + data.itemId;
                    document.querySelector('#share').href = 'https://shareopenly.org/share/?url=' + encodeURIComponent(canonical.href) + '&text=' + encodeURIComponent(data.sentence);
                }
            }
        );
}

var lastExecution = 0;

function changeColors() {
    if (Date.now() - lastExecution > 1000) {
        var bgColor = randomWebColor();
        var color = foregroundColorFromWebColor(bgColor);
        document.documentElement.style.setProperty('--color', color);
        document.documentElement.style.setProperty('--bgColor', bgColor);
        lastExecution = Date.now();
    } else {

    }
}

document.addEventListener('DOMContentLoaded', function () {

    var h1 = document.querySelector('h1');
    h1.addEventListener('mousemove', changeColors);
    h1.addEventListener('click', changeColors);
    h1.addEventListener('touchstart', changeColors);

    function pushState(itemId) {
        var url = '/bloggingbot/' + itemId;
        history.pushState({itemId: itemId}, '', url);
    }


    document.querySelector('#loadRandom').addEventListener('click', function (evt) {
        var itemId = Math.floor(Math.random() * 10000);
        pushState(itemId);
        loadSentence(itemId);
        changeColors();
        evt.preventDefault();
    });

    // handle history changes
    window.addEventListener('popstate', function (event) {
        loadSentence(event.state.itemId);
        changeColors();
    });

    changeColors();
    pushState(itemId);

});


PHP (bloggingbot.ajax.php)

<?php

require_once '../../loader.php';

if (isset($_GET['id'])) {
    $id = (int)$_GET['id'];
    // if not 1 to 10000, error 404
    if ($id < 0 || $id > 9999) {
        header('HTTP/1.0 404 Not Found');
        exit;
    }
    $sentences = file("sample_sentences.txt");
    $line = $sentences[$id];

    header('Content-Type: application/json');
    header('Cache-Control: max-age=31536000');
    print json_encode(
        [
        'itemId' => $id,
        'sentence' => trim($line)
        ]
    );
}

Apache (.htaccess)

# account for urls
# /bloggingbot/0
# /bloggingbot/1
# /bloggingbot/9999
RewriteEngine On
RewriteRule ^([0-9]+)$ bloggingbot.php?bloggingbot=$1 [L]
RewriteRule ^sitemap.xml$ sitemap.xml.php [L]

PHP (Sitemap XML)

<?php

use ArtlungLab\SiteMap;

require_once '../../loader.php';


$numbers = range(1, 10000);
$urls = [];
foreach ($numbers as $number) {
    $urls[] = "/bloggingbot/$number";
}
$sm = new SiteMap($urls);
$sm->setDomain('lab.artlung.com');
$sm->setDefaultFilectime(filectime('bloggingbot.php'));
$sm->setPriority(0.2);
$sm->output();

SCSS

:root {
  --bgColor: #242424;
  --color: #fff;
}

html, body {
  height: 100%;
}

* {
  box-sizing: border-box;
}

body {
  background: var(--bgColor);
  color: var(--color);
  transition: 0.8s all;
  font-family: "Helvetica Neue", Helvetica, arial, sans-serif;
  text-align: start;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr min-content min-content;
  font-size: 1rem;

  > * {
    display: flex;
    justify-content: space-between;
    align-items: center;

    a.btn, button {
      color: #fff;
      text-decoration: none;
      display: block;
      padding: 1rem;
      border: none;
      background: transparent;
      font-size: 1rem;
      cursor: pointer;

      &:has(span + span + span) {
        display: flex;
        justify-content: center;
        align-items: end;
        line-height: 1;

        span {
          line-height: 1;
          font-size: 1.3rem;

          &:first-child {
            font-size: 0.7rem;
          }

          &:last-child {
            font-size: 1.7rem;
          }
        }
      }
    }
  }

  header {
    h1 {
      margin: 0;
      text-wrap: balance;
      max-width: 60ch;
      font-weight: normal;
      font-size: 3rem;
      padding: 1rem;
    }

  }

  section {
    background: linear-gradient(
                    #000 10%,
                    #222 0
    );
  }

  nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(
                    #000 10%,
                    #222 0
    );
  }
}


div#about-bloggingbot {
  max-width: 60ch;
  background: var(--bgColor);
  color: var(--color);
  border: 1rem solid var(--color);
  padding: 1rem;
  font-size: 1.3rem;
  transition: 0.8s all;

  a {
    display: inline;
    color: var(--color);
    text-decoration: underline;
    text-decoration-style: dotted;
  }

  &::backdrop {
    transition: 0.8s all;
    background: color-mix(in srgb, var(--color) 80%, #0000);
  }
}

#loadRandom {
  font-size: 2rem;
}

// when the screen is portrait, make body > header >  h1 font-size 1.5rem
@media screen and (orientation: portrait) {
  body > header > h1 {
    font-size: 1.5rem;
  }
}

Bloggingbot Sentences first 100 lines of 10,000 shown, generated using jsvine/markovify

Here are videos of some of Leah's brothers and sisters.
Trying to get back on the horse, and I suppose I'm glad I don't get seasick.
If there are fewer, but still a long way to go. from Instagram IFTTTHere for kind of a joke as a band.
I appreciate the principled point of view is that science and technology will provide power.
Right now, I don't care, for despite going to the con with my own methodology.
I forget what these links are, but I suppose I would.
Trying to get to work.
Next up I have a lot of work, but also getting a makeover.
Peterson said there is a great subject for drawings.
Basically this is a good way to slowly give users more capabilities on a website.
An additional bit of fun, and the drive home was not bad.
Some possible questions: How clean is the inside of their lungs seemed to be so encouraged.
Even though I am aging, I definitely have a problem with focus sometimes.
When I got there I was greeted by my mother, who was more upset, as in angry, than I had ever heard that word.
Tomorrow I'm going to make a link blue.
Trying to get to the end of the week!
Welcome to the new TOS.
I've been pretty disgusted by the manner of the classic Shatner SNL-ism: GET A LIFE!
Winning handily. from Instagram IFTTTIt's that oh-so magical time of year is hard.
I'm sort of famous to Leah for being able to share info on it with you folks!
The job is in downtown San Diego, business appears to be down at the moment.
#dogsofslacker from Instagram IFTTTPart of the reason is that the TSA never asked him to test their security.
Anyone want to play with it.
Reads like a great little conference.Desktop Linux Summit in San Diego and I do more.
But tonight I'm catching up with todayOS X Software I want to do it their way.
The complexity of my heart, and leading with my chin.
Maybe there will be Christmas.
And in a moment later I have a lot of that bad feeling--that sense of hopelessness.
Check it out in the best shape I've seen him in in perhaps 20 years, and he is inventive, smart, and witty.
Here's where I'm not sure how we could have done to monetize the service with ads or anything else.
Every year Jenny harps on me to find the balance that serves us both emotionally, mentally, physically, and spiritually.
Must have a valid student ID at the time I believe he had some electrified brass knuckles.
It's got some nice features for a free google analytics account.
I'm looking forward to it since I had read TCJ for decades.
Checking in on email and whatnot for the first time I've been making a concerted effort to make my portfolio area make sense.
I am even less pleased not to have a copy I can cart around and read in the bathtub.
I wonder if there's a way to make this online space more livable.
Cobain and Nirvana signified a generation and a sound file from Andreas Brantmo.
Bit of a time finding where to fix the slideshow code so that it would need to represent objects in a virtual world.
My Super Bowl Prediction: IncorrectSo back on Thursday I couldn't get any work done, since all my work is digital.
I imagine you'd have been a year since we got married?
Now, racquetball, and later a Mother's Day thing for my Pop's side of the hair stretched and doubled.
That's fair, because I get the thing looking right.
Color stands out in my notebooks because most of what are thought of as a chronic disease, and it's managed as such.
Though looking at his work now, the feeling I get to see it this weekend.
You are a fascinating character and I have a binder with flyers of the animation has a lot of art supply stores.
I remember hearing about this and expect change in this area.
But also, I loved animation, which meant that I also feel sort of ignorant of California History.
I think the show Samurai Jack is gorgeous?Have I mentioned that we're gonna get married?
Homeland InsecurityLeah is making a change in how we are approaching things.
I got to do is have a new entry on Words, a new radio thing, by the end of June.
If you had asked me in 1986 what I thought might be romantic notes.
Futzing with the camera to take a picture of me in line that we'd get blown up.
Yet I tell you about your love life.
The next day, a Port of Seattle terminal was evacuated because someone's cosmetics triggered a false positive for explosives.
AnswerBus looks like a good option.
I found none in the living part of it.
The biggest transition is that my Grandparents are on dial-up.
What seemed like a good time at BarCampLA-7.Whitney Brothers; Processing, JbumI prefer Chank.
The other day I did make those cookies, so I got that book in some bookstore in the world.
Thanks Leah! from Instagram IFTTTToday needed more color.
Thanks Leah! from Instagram IFTTTToday began with a new bot!
It has to say about 2001 or 2002.
Happy Thanksgiving Everybody! from Instagram IFTTTToday needed more color.
People will start caring more about you as a person who takes to creative projects with aplomb and seemingly, with ease.
My friend Chris pointed out that as a given, a city will return because it has the capability to act against him.
MonoTouch's C-powered runtime blends the power of the web as soon as possible.
So I picked up at the very end of July and I'm not sure if you all could take a peruse back through the archives: and and take a look.
Oh, and I also particularly want to thank all our loyal fans.
The UN was to be the most informed and most aware developer that I can conquer the beast.
But I fear for the clutch of the vehicle I would be remiss if I did not lose anyone close to me in the mind of a creative obsessive.
Your job is hard and I need to do email to work.
Let me think about the Gmail and Facebook accounts I set up for family dinner, a tradition in the family in San Diego, and I miss it.
Maybe we'll go to the lah-bee!”
We got there maybe half an hour to forty minutes.
The whole week seems to be more than 4 times.
Particularly over something like the poem from the other day and got a cookie jar.
My Vons card is in my neighborhood, predominantly Spanish.
Thank God Leah and I had a really great time, learned what a _zaibatsu_ was and what a salaryman was.
About which more I will not be able to share was important and cathartic.
He's able to generate hope and cynicism at the same time I have a reason to watch the meteor showers a few weeks ago.
I'm very pleased to be picked up by my Dad.
I supposed Wired should have been blogging for some time myself.
That's crazy and kind of a "take" after a gag.
Questioning the wisdom of simply driving around where you want to talk, and it's a good read so far.
I will probably deploy some of those qualities stay with me.
After that we stayed the night with conversation and a nightcap.
In reality, these Ten Warning Signs are every bit as wonderful as the hype says it is.
And in a moment later I have a very hard time writing here.
Postscript: I'm flirting with the notion of something like baptism, and how it relates to risk.
From February, 1996This appears to be going nuts in this country.
Another hour killed, I made my way to the Mighty Haus party at Adaptive Path.
It's a busy week But it's all gonna work out My parents are doing well, and it was awesome news but I had to stop somewhere.
I'll be in and out of there by then.
I'm leery of buying the pass, if only because I don't already have enough irons in the fire for me too, but for now, that's enough.
If you want to come to 8am mass at the new University Town Center Apple Store tonight.
The dispassionate side of me has no problem thinking about going into a 100 yard stare, defocusing my eyes.
Let me reassure all of you have noted, I like to think I got offended or they did something wrong.
Trying to get to it, and maddening to not get to do everything in the excellent suggestions my blog commenters had.
And since I'm married, do I count graphic novels, of which I got lost in the crowds there.