Blog Posts

closeCursor()

I haven't been using #PDO and #MySQL for a very long time, so things are bound to pop up from time to time that confuse me a little. While developing the system for storing #hashtags in a table, I tried my hand at using a MySQL variable for the first time. In hindsight, it looks as though it wasn't necessary, but it's good practice anyway.

So, I wrote a statement that looked like this:
$stmt = $dbh->prepare('
INSERT INTO blog_posts (title, safe_title, body, created, author) VALUES (?, ?, ?, NOW(), ?);
SELECT LAST_INSERT_ID() INTO @post_id;
'.$hashtags['tag_insert'].';
');

$hashtags['tag_insert'] is another insert statement generated by the function that parses for tags in the post. It uses the @post_id variable. So, I'm not actually selecting anything in this statement, other than into the variable. But, trying to get the LAST_INSERT_ID() from this statement, either by adding an additional line to SELECT it, or by SELECTing it with another statement, does not work.

If you SELECT it with the same statement, fetch() doesn't return anything, but if you create a new statement, you get an error saying you "Cannot execute queries while other unbuffered queries are active" and that you should call fetchAll(). But there's nothing to fetch, so it doesn't work. So we need to deactivate that query some other way.

The solution is to use $stmt->closeCursor();. Whatever PDO thinks you might want to do with the statement, it just drops it. Now I can create another statement for the LAST_INSERT_ID(). And it still remembers the value of the variable @post_id, so I can just use that.

Here's a link to the Stackoverflow question that I read to solve my problem.

Weird. But I imagine it only seems that way because there's some insight into MySQL that I'm currently missing.

Posted 30 Jan 2019 by Brian

React JS

I've mentioned #javascript #frameworks before. I generally don't like them. I'm not convinced they solve the problems they set out to solve. But, to find out, and because a lot of employers use them, I got together with my friend Josh to learn some of the basics of React.

So, the goal was simple, each of us would create a very simple game using #React. The game would be in the style of one of those clicker games where an enemy appears and must be defeated by clicking. Our version contains only the most bare bones features.

It wasn't too bad. There was a bit of a learning curve, and I'm sure there is more advanced stuff, but we were able to create our games in a few hours. Take a look. Speaking of more advanced stuff, I built mine with a single React component, but if I were to expand the game with more features, I can see how additional sub-components could speed up development. Here is the source on github if you're interested.

Am I convinced? Not really, but I get the picture. I'll want to practice with it some more before I could tell a potential employer that I know react, but for now I think I'd prefer to try a few other ones. Vue looks pretty interesting.

The format of setting aside a day with a friend to learn a new framework was very successful and a lot of fun. Thanks #Josh!

Posted 28 Jan 2019 by Brian

Hash Tags

Here they are! #Hashtags. Most blogs have a system for tagging posts with various tags or categories to help with searching for things, but I really like the tags to be built into the body of the post like many social media. It makes the information more cohesive or something. But I also like not having to put a separate box on the new post form for tags. And the regex to find them in the body is simple enough. Although I did get a bit of help from a guy on the freenode regex channel. Maybe I'll make a post about how it works. #NewFeature

EDIT: Hehe, need to add the table for tags. :P
EDIT: Fixed.

Posted 25 Jan 2019 by Brian

Apostrophes are back

Hashtags no longer break apostrophes. So that's nice. I'm also trying to make code blocks a thing. That's gonna be a little more work, but I'm not sure what problems there are to solve at this point.

For now, this is what they look like.

Posted 22 Jan 2019 by Brian

Update on Spam

I got my first spam email sent to the address on the left, and it is a doozie. Erin the anonymous hacker promises to send a very inappropriate video of me to all my contacts if I do not provide $2000 worth of bitcoin in the next 72 hours.

At the very least, look up the definition of anonymous. I do not assume Erin is your real name, but it is a name nonetheless.

I do find it amusing that this must work on somebody, otherwise they would not try. Imagine remembering that you did whatever they say they have video of you doing, and believing that your webcam caught you doing it, AND a hacker had access to the cam and all your contacts. At that point, you probably deserve to lose 2 grand.

Posted 21 Jan 2019 by Brian

Hashtags

Not quite yet. I almost got it, but there are a few bugs.

First, I am unable to use apostrophes in new posts because the hashtag finder is turning the HTML entities into links. Which makes them display very broken.

Second, I need to decide how the URL rewriting is going to handle multiple pages of posts for a particular tag. This isn't a terribly difficult problem, but I want a clean and consistent solution.

Posted 17 Jan 2019 by Brian

Blog Backup Tool

I wanted to be able to backup the blog posts from my database without having to log into database manager, so I created a page just for that. I can't see any reason it shouldn't be public, as the content of posts already is, so Here's a link!

On a related topic, dates in javascript are a little funny to get formatted nicely. Compare this stackoverflow answer for javascript with This php documentation for the date() function.

I've been spoiled by php. :/

Posted 15 Jan 2019 by Brian

Backend Mobile View

Basically, the backend was separated into two columns. Stacking them on mobile would be tedious to use, because you'd have to scroll a lot. Now, it just slides left and right with css transitions to let you see what you need.

That probably doesn't make much sense, but I can't really show what's going on here because the backend is not publicly visible, but I've added the creation of a demo version of the backend to my todo list. Not sure when I'll get to that, but for now, I can use the backend on my phone. So that's cool.

Posted 14 Jan 2019 by Brian

Custom Text Links

Quick feature today, didn't take a lot of effort to add custom text links!

But y'know, more than zero, which is why I've only done it now. If you haven't seen Game Maker's Toolkit and you're into game design, then you're missing out.

That's... What the link goes to... In case you were scared to click it.

Posted 8 Jan 2019 by Brian

Pretty URLs

Yep, all working now on the front end. Even got those differences from the local to the remote server down to a single change on a file I rarely upload. But I clearly still do not understand RewriteCond. Googling for the exact problem I want to solve (do something different on local server) was able get what I wanted, but I don't know why my method was not working.

Specifically, I was trying to test if the URI contained a particular string. But either I was doing it wrong, or that's not possible. But It works, so I'm not complaining.

The URL for each individual post is
vp/ for viewpost.php.
someid/ for the post id
some-title-of-a-post which is just for show

Because the title portion is ignored, you can actually leave it out for a shorter link. Handy. But you'll still get redirected to the correct url by php.

Posted 7 Jan 2019 by Brian

About

You found me! I'm Brian Bogedin. This is my website and blog. Obviously. Anyway, I'm a full stack web developer and game programmer operating in Southeast Michigan. I do freelance, too, so feel free to contact me with business inquiries. Thanks for stopping by!

Ping me: brian@bogedinbr.com

Projects

This blog!

I'm making this blog from scratch. No CMS, frameworks or libraries! Just MySQL, PHP, JS, HTML and CSS. Is it necessary to create a blog from scratch? No, but it is great for learning, and customization. Does your blog have hashtags?

DrawingWiffWaffles.com

Website for a youtube channel that creates instructional and entertainment videos about illustration. I built the site and manage giveaways there from time to time. Currently working on a miniature custom CMS so that the site owner can administer the giveaways without my assistance.

SECO Tools

I do some work here and there for a company that sells mill tooling. Most recently built a batch processor for their tool converter. Basically, it takes a bunch of competitor product numbers and returns the information on tools offered by SECO with similar specs. Still needs some user friendliness enhancement, but it's currently only for internal use.

Geospin

This is a small couch multiplayer game made in gamemaker for a game jam I organized with some friends. Up to 6 players use controllers or the keyboard to fire rockets on the side of their city to rotate a planet and avoid incoming missile. The trouble is, everyone else is trying to rotate the same planet! Download it on itch.io!

Showpony

Mulitimedia engine being developed by my friend, Josh Powlison. Plays audio, video, comics, text, and kinetic novels. Cool stuff. I'm helping out a tiny bit. See the demo here.