TrickJarrett.com

Posts Tagged: javascript

Sometimes the correct answer is to not touch it anymore

Yesterday I did a surprising amount of coding on Glowbug. Most of it entirely invisible to you all. The quick overview:

  1. Bluesky embeds (we'll come back to this)
  2. Updating my css editor page in the admin to be able to edit any of the template files
  3. Updated my image management page in the admin to have pagination
  4. Simple CSS updates

Okay, so let's come back to Bluesky.

I managed to get invited to it yesterday, as noted when I shared my (current) account name. It's fine. It feels like basic Twitter. What I loved though was seeing how simple generating an embed URL can be. It's just an iframe to a path which includes the desired post.

Great.

Except that took me down a rabbit hole of trying to understand why the Markdown generation of my blog continually failed to handle embedded html example iframe to show how clean the embed code is. Embedding html in posts in my blog is currently one of the things which is broken and I haven't really fixed because I never do it. Except for yesterday when I wanted to do it.

It's broken in a few ways:

  1. When I go back to edit that post, the embedded html is processed as html into the in-browser editor, which often leads to it breaking itself.
  2. The code tag delineations are no help here. Even wrapping the iframe in HTML's 'pre' or 'code' tags didn't stop it from rendering as html. And I have no idea why.

So, this means once I submit a post with embedded html, I can't touch it again except directly through the database.

I'll figure this out eventually, but I didn't last night.

And as I did these various codings, I apparently broke something. The automated end-of-day post didn't happen. The code that generates it wasn't even something I worked on yesterday, but because of how the blog is coded it's quite possible I accidentally messed it up.

So I tried to figure it out this morning. In doing so, I also noticed the newsletter generation wasn't working. So I worked on that some.

None of these, by the way, have satisfactory "I fixed it!" resolutions. The newsletter eventually sent, though I don't know why. We'll see if the end of day post runs tonight or not.

Sometimes, when you run and use your own code, if it suddenly works - the correct answer is to not touch it anymore.

Share to: | Tags: javascript, php, glowbug, programming

Newsletter bug fixed

Discovered a bug in my code this morning. Yesterday's and today's newsletters pulled the entries from November rather than December - oops. It's fixed now.

The issue originated because I changed how I called my newsletter generation code, moving the date selection from built-in PHP to Javascript. However, I missed that Javascript numbers months starting with zero. So January = 0 and December = 11.

So it was calling for 2022-11-27 thinking we all agreed that this meant December 27th, rather than November 27th. Whoops.

Share to: | Tags: glowbug, programming, javascript

Advent of Code - Day 7

Remember when I was waiting for a day where I felt really challenged? Well, I'm a few days behind and Day 7 did it.

I was able to get, I'd say 80% of the way there for getting an answer to Day 7's first challenge. I am confident I would have eventually figured out what was going on with my code and gotten to the solution, but it was taking a while and I realized that I didn't need to keep banging my head against the wall. Rather than blindly bumble into the correct eventual solution, I decided to stop and see how it was done by others. YouTuber 'thibpat,' a French programmer and casual YouTuber, had a video showing how he approached solving it.

Also, I have realized over the course of these days of coding, that I need to better understand Regular Expressions. They are an example where I have a very base level of understanding and rely heavily on googling up a solution when I need them. I would like to just understand them. So I'm going to work on that.

I asked on Mastodon and @shiftingedges recommended recommended Execute Program's free course on it. So I'm going to check that out in the coming weeks.

Share to: | Tags: programming, advent of code, javascript, regex

Insomnia into Code

I suffered some pretty horrendous insomnia last night (speaking comparatively for myself.) But the good news is I've really been enjoying coding in Javascript and I spent most of that time doing it. I expect later today to be in a pretty dour mood given the lack of sleep and the heat, but I'll survive.

I spent most of last night working on basically a complete rewrite of my taxonomy system for posts. I'm adding hierarchy to tags, and also completely rewriting the way the admin page that manages them works. I'd say I'm about 75% of the way there, and then I'll dig into reorganizing them. Once they are reorganized I'll be changing how they function in the backend when I'm writing a new post (for example, when I choose a tag that has a parent tag it will auto-add that tag to the post), and then I'll be experimenting with how they're displayed on the front end.

This will also likely mean that I begin making the tag archive pages. Which has been on my to do list for a while, but I have just held off.

One of the "gardening" tasks for tags is to go through and catch typos (I had both "conspiracy" and "conspirazy"), or when I use synonyms (I decided last night to use "programming" instead of "coding" and also that when a tag is a verb, I'll use the -ing form of it.)

One feature I realize I need to add in my admin tool is that when I merge tags, rather than simply deleting the old one I should save it and what it's merging into. So, in the future, if I try to add that tag again the system will be able to autocorrect it to prevent the "weed" tag from popping back up. Not doing that now, I've added it to my backlog of things to add. Adding that feature now requires a bit more back-end reconfiguration and I don't want to rabbit hole on this all, I'm hoping to be done with my current run at the taxonomy system later today. Who knows though. Maybe another night of insomnia will make it happen.

The next big thing is figuring out the right level of complexity to enable with nesting of tags. For example, I could group all of the programming language tags under the 'programming' tag - that makes perfect sense. Is it worth grouping all the tags which are names of individuals (Boris Johnson, Joe Biden, Elon Musk, etc.) into a group under 'Person'? I don't think so, at least not as of now. Or I have a slew of "us politics", "us history", "us soccer" - do those go under "USA"? As I'm working on implementing the tag hierarchy, I'm thinking about these things and trying to decide my feelings on them.

After this bit on taxonomy, I think the next "big" feature for the blog is to add a photolog of sorts. I've never been a consistent photologger, though I've tried a few different photologs over the years. I also never really adapted Instagram as a regular place to post. But, I do post photos here from time to time, and I could add an auto-tweet for new photos, etc. It's in the backlog, we'll see when I get to it. I still have another small coding project that isn't part of Glowbug to distract myself with.

As far as my enjoying working in Javascript: What I mean is that I'm enjoying working without any library. Historically I've relied on jQuery when writing complex Javascript, but I've come to realize it isn't needed anymore. The language has come a long way over the years, especially with its growth as a backend language rather than just for browser frontends. I'm doing things with native JS which I never would have been able to do without wanting to gouge out my eyes and it's as elegant and simple as jQuery.

It's just really impressive to dive in and really appreciate how far the language has come. Well done to its maintainers.

Share to: | Tags: glowbug, javascript, programming

After a busy and meeting filled day at work, where I ended it with almost 2 hours of Excel-combat I came home and have been spending this evening watching The Gray Man on Netflix, and hammering on some Javascript. Playing with a new idea. We'll see what comes of it, whether I share it or not.

Share to: | Tags: javascript, programming

Learning React.js

I have decided to improve my coding skills and catch up with some modern trends and tackle one of the most popular javascript frameworks, React. Up to now my front-end coding has been HTML + Jquery which ages me by decades compared to the modern day.

It's been a long time since I learned a new programming langue. I messed around a bit with Python recently but, to be honest, it felt very meh to me. Nothing revolutionary. To be clear, I recognize it as a great language and am not trashing it but I found no real hook for me.

So, in my effort to learn and adopt react as my front-end coding of choice, I have this rough development process in mind:

  1. Tutorial project - Done! This was a very simple task manager tool that showed the basics.
  2. A D&D HUD - This would be a tool I could use for managing combat in D&D as well as something to provide a nice front-end view for players to know who's up in the initiative, and out of combat, an easy way for me to show then stuff and convey bits of info about the world. We'll see how complicated it gets.
  3. Fixture Picker - This was the project that actually caused me to jump into learning React. The way I want to take the tool really leans heavy on Javascript to allow people to personalize stuff. So I'll be using React as part of a full rewrite, making it the V4 of the Fixture Picker.
  4. Glowbug - While I'm not blogging as much as I want to, I think this would be an excellent project to learn React and rebuild my admin functionality in it. The frontend will likely not change for readers, we'll see.
  5. Pick'em - This is a further off project. I just did the major rewrite of my Pick'em site for this past season. I don't intend to do this in the short term, but it is a very likely development in the future. Probably 12-18 months down the line.

I am sure other projects will pop up, given time, but this is my road map of projects which I'll work on to develop my react.js chops. And of course, I'll keep this blog semi-updated with my progress.

Share to: | Tags: programming, programming, javascript, react

Toledo Javascript Chess Game

A reddit post shared a user's old chess computer, and I wondered if any nerds had emulated some of the old chess systems to play. I am not a grandmaster, but I'd love to play against them and see how I'd do. In googling, I came across this tiny Javascript chess engine. The total script is 2.1 kilobytes which is stunning. The javascript which runs the backend of Glowbug is many times that size, and looking at the Toledo sourcecode, it is incredibly dense.

It's so dense in fact, the creator has released a book that dives into his code and explains every single detail. I haven't purchased the book, but it's existence is case enough to be impressed.

I played two games against the computer and was very impressed. I won one and managed to draw the other.

Share to: | Tags: programming, chess, javascript

Tonight's coding is not on Glowbug but on another one of my projects. One in need of a refresh and rewrite: My Fixture Picker. Currently it lives on firsttou.ch, but honestly I might let the domain drop and just bring it over to trickjarrett.com. We'll see.

This site solves a problem for me: I really like watching soccer. I have access to lots of games in different leagues on different channels or streaming services. How do I pick what I should watch?

What exists right now is entirely made via server side code using PHP. What I need is to rewrite it so instead it provides your browser with all the raw match data and then you can set some variables for preferences, pick favorite teams, etc. And then it is saved in cookies or as a unique user for you.

So, my plan today is to begin working on that rewrite. I might use this as a chance to experiment with ReactJS since I have no experience with it. We'll see.

Share to: | Tags: programming, php, javascript, soccer, proj:fixture picker

Javascript is a weird language and today as I was changing stuff on the admin side, I caused a bug in the pagination of the posts where it normally outputs a selection and elides the majority of the pages. Instead it was giving me all 25 pages. It was because I was grabbing the current page from the URL, so javascript was seeing the number as a string. One 'parseInt()' function later I've got it fixed, but it took me a while to debug this one silly thing.

Share to: | Tags: programming, glowbug, javascript

So, this morning's biggest coding lesson was to put "preventDefault()" on a keydown event rather than keyup event if you want to stop a form from submitting when you press enter.

Share to: | Tags: programming, javascript