Streamlined My JavaScript Build Configuration

I’m developing this web app on the visualization of mathematics, and I had set up a build configuration with two phases. I wrote the graph drawing code in ES6 JavaScript, then transpiled to ES5 JS (that browsers understand) with Babel and then ran that that through Browserify with the help of Gulp.

I, however, had a nagging doubt that this could be done more efficiently, avoiding the duplication of the code (or actually triplication due to Browserify). I found out how this could be done with a relatively quick search around the Interwebs.

I then decided to run Browserify directly in the ES6 folder, adding a Babelify transform to the process.

Here’s a snippet of my gulpfile.js:

gulp.task('bonsai', function() { // create a new Gulp task
    var bundleFiles = function(filenames) {
        filenames.forEach(function(filename) {
            var filenameWithoutExtension = filename.split('.')[0]; // split the filename at the dot and use the preceding element
            // this should probably be generated with the help of the Node 'path' module
            var sourceFilePath = './src/bonsai_movies/' + filenameWithoutExtension + '.js'; 
            var bundle = browserify([sourceFilePath]) // call Browserify
                .transform("babelify", {presets: ["@babel/preset-env"]}) // here we're changing the ES6 to ES5
            bundle.pipe(source(filenameWithoutExtension + '.js')) // from...
                .pipe(gulp.dest('../js/bonsai_movie_bundles/')); // ... to

    // actually call the function, give the filenames under 'bonsai_movies' as parameters to it

So now my codebase is simpler, cleaner and smaller. 🙂


Django Database Routing Was Broken But I Fixed It

I noticed today that the Django routing system was broken when using the administration script file, specifically when migrating new changes. After a little over an hour of debugging, I found a solution – I had to specify the database in the migrate command.

Like this:

python3 migrate myapp --database=mydatabase

Problem solved and everything works again!

Creating MySQL Users on the Command Line After Fresh Install

I’ve installed MySQL and PHPMyAdmin on my laptop, but I encountered an issue when logging in to the latter. I, however, was able to login to MySQL via command line as root. So I ran

sudo mysql

and wondered what to do next. The MySQL documentation was helpful after a little browsing. So, for first I created a user:

CREATE USER 'maija'@'localhost' IDENTIFIED BY 'P4ssw0rd';

Then I granted all privileges to myself:

GRANT ALL on *.* TO 'maija'@'localhost' WITH GRANT OPTION;

And I was able to log into PHPMyAdmin and actually do stuff there.

How to Configure PHPMyAdmin on a Local Apache Server

I installed PHPMyAdmin on my Linux laptop via apt-get, but when I tried to navigate to the address localhost/phpmyadmin, there was a 404 Not Found error. I’ve been dealing with this issue before, so I kind of knew what to do.

What I had to do was to add the following entry to the Apache configuration file (residing in /etc/apache2/apache2.conf):

Include /etc/phpmyadmin/apache.conf

Then I had to run the following command to restart Apache:

sudo systemctl restart apache2

and I was able to navigate to PHPMyAdmin.

Now all that’s left is the user setup (I won’t be root all the time).

Source – Stack Overflow

Fixed a Unity Problem with Editor Scripts

I was coding a little game in Unity, and briefly moved all of my scripts to the Assets/Scripts/Editorfolder for unit testing. This, however, caused problems later on when I moved them back to the Scripts folder, as Unity still thought they were Editor scripts. The error was

Can't add script behaviour NewBehaviourScript because 
it is an editor script. To attach a script it needs to be 
outside the 'Editor' folder.

I tried various things as I attempted to solve the problem. I finally found the solution – the files were told to reside in the Editor folder in the MyProjectAssemblyDefinition.csproj file. There was a block like this…

    <Compile Include="Assets\Scripts\Editor\GameMasterScript.cs" />

So I removed the “Editor” from each <Compile /> entry like this:

<Compile Include="Assets\Scripts\GameMasterScript.cs" />

…and everything worked again.

Got IntelliSense for Unity and C# Working on Linux

I was thrilled to find out that I could do development with Unity on Ubuntu 18.04. I had decided to use VS Code as the C# script editor. However, I encountered a frustrating problemIntelliSense was broken – and I banged my head against a wall for a couple of hours because of it.

VS Code outputted the following error to the console:

The reference assemblies for framework ".NETFramework,Version=v3.5" 
were not found. To resolve this, install the SDK or Targeting Pack for 
this framework version or retarget your application to a version of the 
framework for which you have the SDK or Targeting Pack installed. Note that 
assemblies will be resolved from the Global Assembly Cache (GAC) and will be 
used in place of reference assemblies. Therefore your assembly may not be 
correctly targeted for the framework you intend.

I tried multiple things. I installed Mono with apt-get. I tried to install Mono from Homebrew. I changed the Unity .NET Framework version.  Nothing helped.

Then I came across this link. It resolved the issue in a simple way. I just had to install Mono development libraries. The commands were the following (for Ubuntu 18.04):

sudo apt-key adv --keyserver hkp:// --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

echo "deb stable-bionic main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list

sudo apt update

sudo apt-get install mono-devel

So, happy hacking ensued, and I finally got on with my project, with IntelliSense helping along the way!

Bought a Used ThinkPad (And Installed Linux in It)

I’ve been thinking about getting a Linux box for a long time. I’ve used Linux for about ten years before, but then bought a Win10 laptop a some time ago. I was fairly satisfied with it, and so decided to stick with it. But I did miss the freedom Linux offered and its great performance. I also like to tinker with things and to see how they really work, and Linux makes that easier.

I got my thirteenth salary this month and so could afford another computer. I decided to go for a used one, as I wouldn’t get a new machine with these specs at the same price. So, what I got was a Lenovo ThinkPad T440 with an i5, 8 GB RAM and a 240 GB SSD. It had Windows 10 preinstalled, but I installed Kubuntu 18.04 in it as dual-boot and shrinked the Windows partition to the smallest possible size (just in case).

The main reason I decided to use Kubuntu as the flavor of Linux was that I like KDE (a long time OpenSUSE user here 👋). Ubuntu also happens to have a large community and user base, and it supports many applications I use that other distros don’t (like Spotify and Unity).

I also bought a mobile broadband plan to be able to use the laptop on the go. Unfortunately I wasn’t successful in configuring Kubuntu to use the built in USB modem of the ThinkPad, but fortunately had some spare USB dongles left (didn’t think I’d use any of those now that I have an optical fiber connection at home).

So I guess it’ll be happy hacking for me!