What is the path to .NET Core SDK on macOS

I thought I’d look into C# development for a bit, and the first hurdle I came across is that I didn’t know the path to the .NET framework when I tried it out on my Mac. I did some digging and found that after installing it from here, the framework (SDK and Core Runtime) are installed here:

Super! I should now be able to call the dotnet command from a Terminal window, but for that I need to add that path to my $PATH variable. Yes… how do I do that again…?

Adding dotnet to your local PATH on macOS

You’d think that after working with Mac and Linux for over 10 years, and being confident on the command line, I’d remember something as trivial as this – but I frequently forget. Sigh! Best write it down somewhere. Here’s a good place, before I make this a separate note.

To see what’s in the current path, we can do this:

This will give is a (more or less) long string of paths that our shell will traverse before giving up with “command not found”. To add to this long list, we should copy it, then add a path of our choice, separated by a colon. Like this:

For dotnet, we want to add the path to the command, not the actual command. Hence we need to do this:

Now we should be able to type dotnet anywhere in our Terminal session and get something like this (rather than “command not found”):

Let the fun begin!

Removing the latest Kernel in CentOS

I’ve had a power cut recently, which seems to have corrupted the latest Kernel I have installed on my CentOS 6 server. I can boot into the previous one just fine, but of course if I forget to make a choice on startup, the server doesn’t start up. That’s annoying.

Thankfully there are ways to either fix the latest version, remove it, and even exclude a particular version from future updates. Here’s what worked for me on CentOS 6:

Continue reading Removing the latest Kernel in CentOS

Including Custom Posts on Archive Pages in WordPress

By default, Custom Posts don’t show up on regular Archive Pages. They still show regular posts, but none of the Custom Post Types are included. I suppose you’d have separate pages with custom queries for that. In my project however, which consists mainly of Custom Posts, it made sense to use the regular WordPress queries to simply include my Custom Posts.

I found an elegant solution that makes this happen:

This will hook right in before the query reaches the theme and adds my own “games” post type to the query. The double-if statement at the top makes sure this only happens on archive pages. Amend this to your needs, for example by using is_home or is_category instead. Replace ++ with two ampersands (I can’t work out how to make WordPress print them properly, and believe me I’ve tried hard).

Note that the hook will not be executed when the search is executed in the admin area. Doing so will show an “invalid post type” error.

Thanks to Tomás Cot and Mathew for their approaches to this solution.

Accessing Custom Taxonomy of a Custom Post Type in the_loop

I was wondering how to access the custom taxonomy of my custom post types so it can be mentioned in the_loop. To continue my example from earlier posts, I have custom post type of “game”, with a custom taxonomy of “platform”. When I list a game, I’d like to show the platform in a list after its title.

On regular posts, I have access to access to both categories and tags using the get_the_category() or get_the_tags() functions. For my project I have a custom query for the custom post type, and I’m using a custom taxonomy on it. I’d like to find out the name of that custom taxonomy. How do we do that?

We’ll use get_the_terms(), which is used by WordPress for both the above functions under the hood. Here’s how we can display all taxonomies of one type (must be used in the_loop):

Thanks to Ankur Bhadiania for this tip.

How to fix “active developer path does not exist” with git on macOS

I’ve recently removed Xcode from my ageing MacBook. Ever since then, I’m getting an error when I try to run git from the command line. The error goes something like this:

That’s because Xcode had installed several command line tools provided by Apple, and one of them was Git. I thought simply installing it via Homebrew would do the trick but alas that too brings up an error message, albeit a different one. Somewhat frustrated, I was wondering how I was ever going to run Git from the command line again.

I did some testing and found a fix to this issue. Here’s what worked for me.

Turns out that I had a symbolic link (or rather a stub) at /usr/bin/git, a place at which git might indeed be expected to live. This however redirected to a no longer existent Xcode installation, or more precisely the xcrun command. All I had to do was rename the symbolic link with admin privileges:

Once that was taken care of, I could download the macOS installer from the official Git-SCM website. I found it under Downloads (it’s not the GUI version, just the command line version at the top of the page). It’s a .pkg file that will install git to /usr/local/git, and places symlinks into /usr/local/bin and /usr/share/man/.

Lo and behold, after the quick and painless installation, I could simply type git from the command line and the above error was gone, and git was operational again.

How to add FTP sync in Visual Studio Code

To my delight I found out how to add an FTP destination to Visual Studio Code. It’s an extension called sftp by liximomo, available for free from the VS Marketplace. Here’s how to install, configure and use it on both Mac and Windows.

Obtain it by selecting the extensions symbol in the sidebar (the bottom one, consisting of four little squares) and enter sftp in the search box. Click the green install option to proceed.

Continue reading How to add FTP sync in Visual Studio Code

How to add the path to PHP in Visual Studio Code

I’ve recently started using Microsoft’s Visual Studio Code on my Mac. It works great, and I really like its simple useful features. The installation and most of the configuration worked flawlessly on my Mac and I was up and running very quickly. I had assumed it would be the same on Windows, but of course that wasn’t the case. Nothing is ever easy in Windows, is it?

The error I got was with two PHP extensions: PHP Executable not found. Install PHP 7 and add it to your PATH or set the php.executablePath setting.

Hey sure, I get that. The extension needs the location of my local PHP installation. No problem, I can provide that… but how??? You click on Open Settings and expect to just navigate there – but that would be too easy. All we get is this:

Then you think, ah OK, it must be in that mysterious settings.json file, but all that does is to open a new coding window, with two curly braces. How the hell is anyone going to know what the syntax is? It surprises me that the rest of Visual Studio Code is so good, and something as simple as am option to browse to (or even find itself) what some component is looking for isn’t there? Oh Microsoft, you haven’t changed a bit in 30 years!

Well here’s what to put in that settings.json file:

I know. Crazy. Not a syntax I would have dreamt up in 100 years. This can be written on the same line, and it looks like it’s a key value pair to me. The second parameter points to my local XAMPP installation, so feel free to point it to your own PHP location.

Bizzarely, instead of regular backslashes, make sure to use double-backslashes. Because… you know, reasons. Escaping things or whatnot, I have no idea. All I can tell you is that it works.

This tip comes courtesy of Mohamed Elrashid on StackExchange. Thank you, Mohamed!

Note to self: I believe had PHP been set as an environment variable to PHP been set in System Properties, there is a chance that Visual Studio Code would have found it upon first run. That’s what happened on my Mac, so I’m assuming it’s possible on Windows as well. It’s also what that mysterious error message at the beginning alludes to.

How to create Custom Post Types in WordPress

I’ve been working on a game database that’s powered by a vanilla WordPress instance. For the project it made sense to create a new post type (game), as well as a custom taxonomy (platform). I didn’t want to use a plugin and instead opted to create the new post type as part of the child theme’s function.php file.

Here’s how I did it.

Continue reading How to create Custom Post Types in WordPress

How to use Sidechain Compression in OBS

OBS has a super neat feature that works great if you’re narrating over an existing audio track. It’s called Sidechain/Ducking, and it will automatically lower the audio of one source if an audio level is detected on another source. For example, when you’re playing a game, the audio would be lowered when you speak, and when you’re quiet the game audio could be played higher. It’s like MAGIC!

In this article I’ll show you how to set it up, and the values that I’m using for some of my streams.

Adding the Sidechain/Ducking Compression Filter

On the audio source in question, apply a filter. You can either right-click on the source in question, or use the little cog icon in the Audio Mixer for that. Add a Compressor filter and call it “Sidechain Compression”, or another identifiable name.

The default values work OK, but I’m using these as I find them more pleasing:

  • Ratio: 32:1
  • Threshold: -40dB
  • Attack: 250ms
  • Release: 500ms
  • Output Gain: 0dB (default)

The important bit is set at the bottom, which which we can pick a Sidechain/Ducking Source. Set this to your microphone source from the drop-down menu. That way the Compressor knows which other source to listen to and apply the effect. When a level above a certain threshold is detected, the filter kicks in. Anything below that will not trigger the filter.

It’s worth doing some test recordings to see which exact values suit your needs. To figure out the threshold, take a look at the audio meter while you’re not speaking into your mic. You’ll see some low level noise on the left, know as the noise floor. Make sure to set the sidechain threshold to somewhere above that level so that it won’t trigger accidentally.

Have fun!

SVN Command Line Basics

I keep forgetting SubVersion basics from the command line, and thought this quick little cheat sheet might come in handy. I’ll cover the basics:

  • checking out
  • updating your local copy
  • checking current file status
  • committing a change
  • adding a file
  • removing a file

Checkout Out

To make an initial copy of an online repository, we use the checkout command. It’ll create a new folder with the name of the online repo in the current directory and copy all its contents into it. Checkout can be abbreviated with co:

Updating your Local Copy

If you’ve already checkout out a repository, and you’re not sure if changes have been made on the remote, you can update your local copy using the update command. It can be abbreviated with up:

A list of updated files will be displayed, as well as the revision of the current commit. If no files are displayed, your local copy is up to date. Check svn help update for details.

Checking the status of current files

SVN let’s you display a status of all current files. This lets us decide what has been changed locally before a commit has been made. We use the status command for this, or its abbreviation stat:

A list of files and their status appears, or nothing if all files in your local copy match the online repository. Check svn help status for details.

Committing a change

When one or more files have been changed, it’s time to submit this change to the online repository. We do that with the commit command, abbreviated with ci (short for checkin). It’s customary to leave a small comment as to what this change does, using the -m switch:

Commit will store changes across multiple files. There’s no need to submit each file individually. The commit command is designed to make all changes final, such as updates, additions and deletions. It’s usually used at the end of all changes that have been make, as a final synchronisation step.

Adding a file

Add will add a new file to the repository. It’s necessary to add files to put them under version control, otherwise they’ll be designated with the ? parameter (as unknown state). The same goes for directories.

Removing a file

If you delete a file from the local directory, we must tell SVN about it. Otherwise it will assume the file still in the online repo is out of sync and should be downloaded to your local copy first (being obviously missing and all). Delete will remove a file for us. The command can be abbreviated with del, remove or rm:

Further Reading