Skip to content

Author: adam

  • One Input Device for Mac and PC Simultaneously

    Sharing one input device across multiple machines seems like a great thing at face value. If you have a Mac and an iPad (or even two Macs) then Apple’s own Universal Control works fantastically and (usually) without a hiccup. My biggest problem that I have encountered is two devices just not automatically communicating which I have always been able to fix by toggling on and off Universal Control from one of my Mac’s settings.

    That’s all well and good but what if you have a Mac and a PC and want to share input devices across the two? If you plan on using one device at a time, a KVM switch will always be the best way to go. Hardware solutions are exactly that – a physical device that connects to two (or more) machines into which your input devices are connected.

    What if you’re like me and use a Mac and a PC at the same time? Here are some solutions I’ve tried with varying degrees of success and usability.

    VNC into your second computer.

    How I would implement this is run VNC server on my PC and then connect from my Mac to the PC. This works best for me if I have multiple monitors running and then dedicate a screen to the VNC session. The benefits to this, for example, is that if your secondary machine is a desktop and your primary machine is a laptop, then you can access your secondary machine from anywhere while only carry one computer. My VNC platform of choice is Real VNC and I’ve had no issues establishing a connection from anywhere. The drawback to this is latency. If I’m connecting over my local network, latency is much less of an issue but when I’m out and about then I am at the mercy of whatever internet connection I may be using. I’ve also connected to my phone’s 5G hotspot and even though my cellular connection may consistently give me well over a 100Mb/s transfer speeds, my ping is usually hovering around the 900ms mark which makes doing any sort of sustained work nearly impossible. For things like a quick move of a file, no problem, but the constant latency from keystroke or mouse click to response from receiving machine is unbearable.

    In summary, this is a great free solution when working locally but is not reliable (for me, at least) when I want to work remotely on a computer than is stationary in my house.

    Use a KVM switch.

    I haven’t used a hardware KVM solution for a few years but changes to KVM offerings don’t change very quickly except when the intent is to share a single monitor with a single connection. A cheap KVM switch can be had from Amazon for less than 50 bucks while enterprise-grade solutions can hit eye-watering, multi-thousand dollar price tags. The pros are that there is no latency – your input devices are physically connected to the target machine. The drawback is that you can only use one computer at a time and you (typically) have to manually (with a physical button) toggle between your target machines.

    The monitor I use is a Samsung Oddysey G9 with a native resolution of 5120 x 1440 at 240Hz. Cheaper KVM switches don’t support ‘exotic’ resolutions and those that do won’t typically go above 60Hz. Luckily, my monitor has to DisplayPort inputs so I keep one connected to my Mac nad one to my PC and just toggle the source on the display and I toggle the inputs between my machines.

    When I want to work, and test code across two machines at the same time, a physical switch just doesn’t fit into my workflow. When I’m done for the day and want to play a game, especially a FPS, a KVM switch works great and doesn’t cause any input lag.

    Symless Synergy 3

    I bought a license for Synergy all the way back in 2018 and had totally forgotten about it. Perhaps that was a bit of foreshadowing but this piece of software was at the top of the search results when I looked for “share mouse and keyboard between PC and Mac”.

    Installing the software is straight forward regardless of platform and I even tried running an old Dell Laptop with Ubuntu in-line with my MacBook Pro and Razer blade to see if their ‘works on all platforms’ meant ‘works on all all platforms at once’. I was surprised but it did. I set my MacBook Pro as the host and connected the Ubuntu machine to the left and my PC to the right. It just worked.

    Even though it works as advertised and it works reliably, it wasn’t without its own caveats.

    When I have my MacBook Pro sitting next to my Razer Blade 16, it works great. I can have both devices side-by-side and, much like Continuity between two apple devices, the cursor floats between the two screens with no trouble. I can test code on both machines at the same time and all is well in the world.

    My Mac is my primary work computer so when I’m working at my desk and have my Mac connected to my external monitor, then I notice hiccups with what I believe is input lag. It’s most noticeable on my PC where I can very clearly see jerkiness when moving the cursor which increases as the cursor accelerates. Input lag from the keyboard is not noticeable but my only “testing” is what I can perceive. Keep in mind, when I am stationary, at my desk, my machines are connected via Ethernet to my home network no network latency should not be a factor. Even so, when I am on WiFi just using my Mac and PC (no external displays) side-by-side, I don’t notice any cursor lag.

    I’m going to dig into this further and plan to post a more in-depth review of Synergy 3 so stick around for that coming soon.

    There is no “one size fits all” solution for me.

    What I have determined is that each solution fits a different use case. When I’m at home working on my ultrawide monitor, a VNC session sharing half of my display works great. When I have both machines present then placing them side-by-side and using Synergy 3 is great. When I’m at my desk and want to switch to my PC for a gaming session, then a KVM switch with my keyboard, mouse and controller fixed in place fits the bill.

    Thankfully, all three of these solutions cost me about 85 bucks. A license for Synergy 3 is $29.99 and the KVM switch I use cost a little over 50 bucks. A personal, 5 device license for RealVNC is free and I’ve used RealVNC for years and have never had an issue aside from maintenance windows on their end.

    Your situation is going to be different and some, all or none of what works for me might work for you. If you’ve got a unique scenario or solution, let me know in the comments.

  • Grip Strength Percentile Calculator Project

    Years ago, I worked with a doctor that specialized in sports medicine and physical therapy. He asked me to create a bespoke grip strength calculator that he could use and present to patients of his. I used charts and data available from the NIH to do the math and meet the task requirements. I wrote this in vanilla JavaScript and in a way that it could be embedded in nearly any site that allowed custom HTML. This was initially going to be embedded in a Magento content page and it worked out well.

  • Change Mouse Scroll Wheel Direction In Windows

    I’ve been using my PC more lately and one thing that Windows lacks is the ability to set the scroll behavior related to mouse wheels. I use “natural” scrolling on my Mac’s Magic Mouse (and always have since its introduction) so using my PC recently has been frustrating since my muscle memory is so well ingrained.

    The mouse I use currently is a Razer Orochi V2 and the Razer Synapse software provides the ability to remap the up and down scroll direction but that seems really clunky for something as simple as “move mouse wheel up, scroll page down”.

    The scroll direction can be set in the Windows registry and for those of us that have edited the registry manually before, it’s not that difficult of a challenge – it’s much more of a chore to have to find the correct registry keys. For those that haven’t or don’t want to edit their registry manually, I have a handy PowerShell script that automates the process.

    Disclaimer: I am not the original author of this script but I did change verbiage and output to be more clear for the end user.

    It’s a basic PowerShell script and the only caveat is that is requires admin privileges to execute (naturally, since it deals with editing the registry).

    As I update Windows on my PC’s, I’ll add the versions that work to the README.md in the repo. Feel free to leave a comment with your version of Windows and if you run into any issues.

    Update as of 12/22/2023: I found that the registry entries for some mice exist in a nested entry within the “Enum” key. My experience specifically has shown that Lenovo-branded mice do this. I am working on a fix but I’m not sure if other OEM’s do something similar. Drop a comment below if you know. Any information is helpful and appreciated!

  • Out With Ghost, In With WordPress

    As much as using WordPress is cliche, my current job revolves around WordPress so it seemed fitting to use it personally as well. I had been using Ghost since I had been fully immersed in NodeJS, Next, React and researching any ‘new hotness’ JS frameworks or libraries that seemed to materialize out of thin air every few days.

    I like Ghost and it did everything I wanted and was very easy to set up and maintain on my Raspberry Pi web server. I appreciated not having to use plugins for features that WordPress should have built into the core long ago. I really appreciated the content editor which was very fast, and had all of the content editing and layout features I wanted. The templating engine was a bit of a learning curve but once I looked at some different themes and poked around under the hood, I was able to figure out how to get the frontend to do what I wanted it to do.

    Having been a PHP person for almost my entire professional career, WordPress was always looming over my shoulder. When I started to delve deep into NodeJS and other JavaScript or TypeScript-based frameworks, using Ghost for my own site seemed befitting. It was easy enough to set up and self-host on a Raspberry Pi so that’s what I did.

    Alas, I find myself fully immersed in WordPress on a daily basis. I wouldn’t have considered myself a WordPress developer before but I certainly would now. In less than a year’s time, I’ve learned sooooooo much about what WordPress can do and some quirks and shortcomings about what it can’t. As much as I want to be one of the cool kids running a JavaScript-based thing for my own site, it makes more sense to use WordPress and use it as a playground of sorts to experiment and get weird if I feel like it.

    Just like the answer to every car question is “Miata”, the answer to every website platform question is “WordPress”…

  • Reset WordPress Password Directly in Database

    My current job has found me in a sea of WordPress sites. Since we don’t allow (or want, at this time) users to register, the PHP mail() function is not enabled along with the security risks that PHP mail(); brings along with it. So what happens when a user needs their password reset? Currently, an admin has to manually set a new password. That’s fine and dandy but what happens if you only have one admin account and you’re locked out?

    The answer to that question is simple – reset the password directly in the database. Before you do that however, the new password needs hashed. You can use a simple MD5 hash to insert into your database which WordPress will run through its own wordpress_generate_password() function to create the proper form or you can use this tool that I built in order to create a ready-to-go WordPress password hash and example SQL query to run against your target database.

    Once you’ve got your hash, go into your WordPress database, and then find the ‘wp_users’ table. Inside of that table is a column called ‘user_pass’ – this is the field to enter your hash into.

    Execute the following SQL command (adjusted for your specific parameters):

    UPDATE wordpress.wp_users t SET t.user_pass = 'your-generated-hash' WHERE t.ID = 1;

    Replace “wordpress” with your database name and make sure you have the correct ID if you have multiple users otherwise, someone else is getting a new password.

    This can also be handy when installing WordPress within MAMP or MAMP Pro. I’ve found that in verisons 5 and 6 of MAMP Pro, when adding WordPress as an extra, the password you enter before MAMP installs WordPress never works. So, I’ve used this method to fix several WordPress installs when done through MAMP.

  • Replace Your Old Site URL with a New Site URL In Your WordPress Database

    I use the following SQL queries regularly to move databases between local, staging and development environments in my current role and have found them to be invaluable. There are plugins that can do this but a simple SQL query is going to be faster and the output from the SQL console will give you clear and concise feedback when executing. The following WordPress database queries are my “Swiss army knife” of tools when migrating databases across environments.

    First, to replace the Site Address (URL) and the WordPress Address (URL), use this query:

    UPDATE wp_options SET option_value = replace(option_value, 'http://www.your-old-domain.com', 'http://www.your-new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';

    After that, we need to replace the URL’s contained within your post content, which is stored in the “post_content” column contained in the “wp_posts” table. To do that, use this query:

    UPDATE wp_posts SET post_content = replace(post_content, 'http://www.your-old-domain.com', 'http://www.your-new-domain.com');

    while we’re at it, we’ll also update instance of the old URL in the “guid” column. We’ll do that like this:

    UPDATE wp_posts SET guid = replace(guid, 'https://www.your-old-domain.com', 'http://www.your-new-domain.com');

    Your site will almost certainly work perfectly fine if you don’t update the “guid” column but if you rely on RSS then your feed will malfunction. Each guid is also a valid URL and each URL contained in the “guid” column will redirect you to the corresponding post so while this may not seem like a big deal if nothing is obviously broken, it is a significant piece in the overall health and proper function of your site.

    It’s also important to not overlook the “wp_postmeta” table. This table stores all of the data related to each post in your site. Any hardcoded instances of your old site URL can have a negative affect on the functionality of your site. To update the post meta_value, use this query:

    UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://www.your-old-domain.com', 'http://www.your-new-domain.com');

    Last, and this only applies if you use or have used the comments feature, is that we need to replace the URL’s in any comments made on your site. Top do that, use this query:

    UPDATE wp_comments SET comment_content = replace(comment_content , 'http://www.your-old-domain.com', 'http://www.your-new-domain.com');

    When the queries run successfully, you should see an output like the following:

    Query OK, 2 rows affected (0.03 sec)
    
    Rows matched: 2 Changed: 0 Warnings: 0

    Depending on how many rows the query will check, this may take some time. Updating the “meta_value” on one of my sites with almost 19,000 posts returned this console output:

    sitedb_wp> UPDATE wp_postmeta SET meta_value = replace(meta_value, 'https://www.my-old-url.com', 'https://www.my-new-url.com')
    [2023-10-02 10:23:42] 231,918 rows affected in 1 s 27 ms

    And likewise, updating the “post_content” column returned this console output:

    sitedb_wp> UPDATE wp_posts SET post_content = replace(post_content, 'https://www.my-old-url.com', 'https://www.my-new-url.com')
    [2023-10-02 10:26:03] 86,156 rows affected in 38 s 573 ms

    Keep in mind that I’m executing these queries on an AWS RDS instance that is size db.t3.medium so take your particular database infrastructure into account when running these commands. I can personally confirm that these queries work on WordPress versions 4.8.x up to 6.3.x. I don’t see this changing in future WordPress versions but who knows. Also, these queries do not take into account any third-party plugins or data that said plugins may be storing in your site’s database.

  • I Launched My First Next.js Project

    I wanted to build a pastebin when I started learning React and Next.js. I thought this would be a good demonstration of what I’ve learned, with the ability to add features as I get more advanced with React and Next.js. It’s been a little over 6 months since I put the project aside as it ws right around the holidays and my work schedule was absolutely awful at the time.

    Fast forward to this week and I have been able to pick it back up, re-familiarize myself with my own work and get a fully functional (albeit very basic) release pushed live! You can check it out at https://pastey.io.

    My goal was to incorporate popular (and modern) technology offerings so along with Next.js, I’m using MongoDB Atlas for data storage and Auth0 for user account creation and authentication. Since this was my first real foray into a project that didn’t use MySQL, trying to wrap my brain around Mongo was difficult at first but, at least in my case, I was making it harder than I really needed to because of working exclusively with MySQL for so long. Auth0 has been fairly easy to work with as well and their documentation on intgrating into a Next.js project was a tremendous help. And finally, deploying everything on Vercel was shockingly easy.

    Once unfortunate side effect of pausing development on this project is that Next.js 13 was released right as I got too busy to make any meaningful progress. I do need to consider migrating to Next.js 13 before I add too many more features that may not be forward-compatible without a lot of rework and refactoring.

    I fully intend to keep Pastey.io operational indefinitely because I do think it’s a useful tool and not just a tech demo. I find myself using paste bins and buckets more frequently in my new role and it seemed fitting that I start using one that I’ve built from scratch. Being a police officer has made me much more paranoid about personal information security and using a tool I built myself means I know excatly what is happening with the information I give it.