blackman.zip blog https://blackman.zip A simple blog written by a simple developer boot-loop.md https://blackman.zip/post/boot-loop.md I am writing this one the same day I posted my last post, I wrote the majority of little-space-game about a month ago, but through the process of moving and getting my server to work under a different ISP, it took awhile. I wanted to share something funny that happened during the process of troubleshooting a problem I’ve had with my server for a few months. I self-host my server. All the hardware is at my house and on my network. I did just move everything behind cloudflare and tailscale to make it more secure, also it was easier that fiddling with ssl certificates and ssh keys. The hardest thing I’ve found about self-hosting is uptime. If my server goes down or has some kind of error, then I have to be physically at the machine to reboot it. This isn’t the worst thing, except when I’m travelling and won’t be home for a few days (which so far everytime it’s broken on me I’ve just coincidentally been away). This particular issue I’ve been trying to troubleshoot caused everything on the server to disconnect from the internet. It wouldn’t even responds to arbitrary pings. Eventually I wanted to troubleshoot it further and connected a monitor to it to see what the crash logs were. Weirdest thing is that there didn’t seem to be anything wrong with it, just stopped connecting to the internet. My best guess was this was the router didn’t like the fast my server existed, so it kept kicking me off when it felt like it. Luckily rebooting it fixed the issue everytime, so I made a simple script that just pinged out to a reliable server and then restart if it returns a 404. Trying to be clever I decided the best server to ping was itself, or the website that this is hosted on https://blackman.zip. I tested it a few times and found that it works. I then figured that if it runs into the error more than once without me noticing, the second time it will just stop work. I then added it to a cron job to start the program at launch, meaning I won’t have to deal with it. Here is the code: #!/bin/python3 import os import time import platform import subprocess from datetime import datetime def ping_website(website): command = ['ping', '-c', '1', website] return subprocess.call(command) == 0 def reboot_system(): os.system(\"sudo /sbin/reboot\") def log_time(): with open(\"reboot_log\", \"a\") as f: f.write(f\"{datetime.now()}: Server unreachable\n\") def main(): website = \"blackman.zip\" while True: if not ping_website(website): log_time() reboot_system() time.sleep(3600) if __name__ == \"__main__\": main() I reboot the server the first time and… nothing. I thought about it for a second and realized, oh I’m an idiot. I created a boot loop. The above code first checks if the server is running and then waits an hour. The problem is the server can’t run until after this program has already started. Meaning the server can never start because this program keeps rebooting the system before anything can reach it. Luckily linux has live USBs and I hav a few versions using Ventoy. It was an easy fix, but it was just a funny oversight. Here’s the updated code: #!/bin/python3 import os import time import platform import subprocess from datetime import datetime def ping_website(website): command = ['ping', '-c', '1', website] return subprocess.call(command) == 0 def reboot_system(): os.system(\"sudo /sbin/reboot\") def log_time(): with open(\"reboot_log\", \"a\") as f: f.write(f\"{datetime.now()}: Server unreachable\n\") def main(): website = \"1.1.1.1\" while True: time.sleep(3600) if not ping_website(website): log_time() reboot_system() if __name__ == \"__main__\": main() I just made the program wait an hour first before it pings out and had it ping the cloudflare cdn, because if that goes down then there is probably more problems than this blog. Just a funny story I thought I would share before I start my next job and don’t have time for any fun side projects. Thanks For Reading! little-space-game.md https://blackman.zip/post/little-space-game.md A few months ago, I was sitting at work and inspiration struck \"I want to make a space game.\" I have always liked space, I imagine it to be such a cool experience that only a few humans have ever gotten to experience. In light of my ever dwindlinhg chances to visit someday, a game is probably as close as I’m ever going to get. I have dabbled in 2d games before, at one point I wanted to start an indie company, mostly to say that I can make a company, but I quickly realized I don't really enjoy making games. I prefer making games from very minimal frameworks and contructing the rest myself. When I first started designing games, I made them in html5 canvas and handled holding buttons and collision myself. Here is one of my first games I made as part of a game jam itch . This influenced this \"game\" as it is currently more like a simulation than a game. The mos input the user has is changing which body is being focused. I origionally had more planned and cooler ideas for it, but as most of my side projects go, once I have created the original idea that I thought of, I just lose interest in it. Gravity The first thing I had to solve was how am I going to get things to revole. I had several ideas about how I could create gravity and drag when in a planets atmosphere. My first idea was giving each planet have a hitbox around it. When something entered into the sphere of influence it would have a force that draggedd it into the planet. This seemed easy enough, I could have different planets with larger hitboxes to simulate their size and voilà, it works. Except I ran into a problem with path projection. Maybe I was under assuming the amount of power a computer has, but I wanted to have a projecting for each body where they would be in the future. This makes travel way easier, as you can guess where your ship or the planet you want to end on will be in x timesteps. Kerbal Space Program Orbit Example source If you have never player kerbal space program, this is what I'm getting at. You can see where each body will intersect or when it will pass through its gravity in the future. The way I was doing it would require simulating every physics step, every frame, for every body and keeping track of their positions. The hitbox idea seemed to complex for that, so I was looking for alternatives and I found a video where someone was doing something similar in unity: Coding Adventure: Solar System. This person just used Newtons equation for gravity and changed the forces of every movable object every frame. This greately simplified what I wanted to do and it seemed easier to implement. This didn't solve my other problems though, how could I project the path of celestial bodies in a less compute intensive way and how could I keep planets in a orbit without having to guess an initial velocity and balance that with the many other bodies in a system. 2 body problem My solution to this problem was to create 2 types of objects Planets These would have a deterministic path, they would not be influenced by our gravity function and would have an elliptical orbit around a parent body. Their revolution would be based off of the timestep, making them deterministic. When calculating for the gravity of an object, I just have to give it the timestep I want and get its position withouth having to keep track of the previous positions of every object in the solar system. Any project path would just be the outline of an ellipse drawn based on the A and B values. Physics Bodies These would be the ones actually moving around based on gravity. The trajectory is just a list of different points at each timestep up to a certain amount. I picked 10,000. At startup, each step is created then each additional frame the last position is popped off and then create an additional new position at startup is calculated to 10,000 steps, then each frame I only have to calculate the next step in the list, and hopefully just using the next freed-up object so I won’t have to allocate more memory. So that gives you this: Orbiting bodies in vesper The white lines are the orbits of the different planets, they are only able to orbit in and elliptical fashion and don’t change based on other bodies. A funny quirk of this system is there is no orbital rotation of the planets, so the ellongated orbits can only be on the x or y axis, I can’t make them go diagonal. The Yellow and green orbits are the physics bodies. They move around and you can see which planets they are going to bounce off in the future. The green line means that is the body you have selected. The camera will follow the selected one so it’s easier to follow. Another funny thing, before I implemented the simple hitbox system, the physics bodies would often collide with planets, and apparently when two objects don’t have collision they have insane amounts of gravity, so the physics body would launch into space super fast and you could always tell when it was going to happen based on the trajectory line. Here is another screenshot that is a lot closer, the above screenshot is zoomed out 1000% to make it easier to see if the whole system is working, which is pretty, but it is really hard to see just how big each planet and object is. Zoomed in Orbiting Bodies Future I was about halfway into implementing the rocket system, where I decided I would end. I never wanted to completely make the game to its end and found this place a good chance to stop. I really just wanted to explore a celestial physics simulation and I accomplished that. All code for this project is on my github Thanks For Reading! start_of_a_blog.md https://blackman.zip/post/start_of_a_blog.md At the time of writing this, on the front page of my blog I have written that I started this blog because I have free time on my hands and I am inspired by other developer blogs. That's mostly true, but I also thought it sounded like a good headline. Part of it is out of spite. Javascipt I was browsing hackernews a few months ago and found an article about someone reviving an old project and the problems he ran into (found it: (https://abdisalan.com/posts/tragedy-running-old-node-project)). The author was having problem upgrading and dealing with old Node dependencies. Some of them calling into python2 and c. Currently in my programming career, I have tried to use javascript as little as possible. I first learned it to create games using the canvas and handling keyboard inputs and events myself, Later moving onto the broader javascript ecosystem and realizing what a mess it is. This point is brought up a lot, but on npm there is an is_even package that tells you if a number is even, and it's even downloaded 100,000 times or so per week. Not sure how hard it is to write function isEven(number) { return number % 2 === 0; } So, while reading the above article I thought \"I could probably write an entire blog from scratch in the time it took him to troubleshoot javascript.\" Now that I've made it and have a url that I'm not really using, might as well write on it. Technology This year I have been writing a lot of work and side projects in golang. It's a nice and simple language that I've enjoyed writing in. If I decided to write this in golang, it probably would have only taken me 2 hours. Instead, I felt that golang is missing some nice features. After writing in Rust, I missed a lot of the functional stuff that golang was missing. I wanted something in between the two and decided to use vlang. Vlang is very similar to golang in it's simplicity, but adds some things that golang desperately needs, like good iterators, embedded structs, and unions. This made picking up the language very easy for me because of my experience with golang and rust. The biggest problem with Vlang, is it's still in beta, so whatever skills I gain using it more than likely won't translate to any job. I guess I could check, but I doubt that there is a single person hiring for Vlang in 2024. Also if I want to restart this project in a few years, the apis will have probably changed, making it harder to fix and edit things. I also chose HTMX for the front-end because it's the best and simplifies everything. Templates are easy and I don't need a full react stack just to render 7 words on a page. Design I wanted the simplest design possible, it's a blog, nothing fancy. I wanted to have a function walk a file tree, then from the contents of the folder I would structure the posts on the front end. There would be an initial folder that I could denote (I called it pages) any file that would be displayed would be shown in the navigation bar and any folder would become a dropdown. Contents of folders would show a list, contents of files would be renderted to html and inserted into a template. This was a cool way, in my opinion, to represent the different pages. I mean it's basically how the web was designed to work in the first place, each directory being its own file. This way, I could denote different \"series\" of posts by placing them in folders, making them easier to organize. This way ended up being more complex than it needed to be, A user could end up clicking through 4 different folders just to a single post, and probably lost interest in the mean time. The approach I went with instead, is there is a folder called pages that has \"home.md\" and \"links.md\" with a \"posts\" folder. Coincidentally, those are all the tabs at the top of the site, with all the posts having a place in the posts folder. Their dates being sorted by the last date edited. Each post is read every hour or so. When requests come in, the information is cached, which eliminates reading from disk. This is more efficient, but I don't see it making a substantial difference because of how few people will be visiting. Conclusion Simplest way I could think about creating a blog, mostly because I thought it was funny and wanted to contriute my thought process while building my side projects. Thanks for reading!