Change the File Extension in Typescript – Using Path

Posted by in Software, Tutorial

Following from my previous post, I’ve updated the function to use only the path module. Now, the code looks like:

I’ve updated the workflow presented previously to: isolate the dir, ext and root components of the path replace the ext with the new extension return the normalized version of the composed path Now, our function accepts complete paths, not only filenames. Note: The path.normalize() function does NOT calculate the absolute path. It only changes the path separators. A little experiment: If you find this post and ad below useful,…read more

Configure Volumio with PiFi DIGI DAC+

Posted by in Hardware, Tutorial

The other day I’ve got a Chinese clone of HiFiBerry, a PiFi DAC+ v2.0: Here are the steps to configure it with Volumio. First, you need to install Volumio 2 (2.129 at the moment of writing). You need to configure it to e.g. connect to the network, index songs. Note: Back up your config.txt (and wpa_supplicant.conf) Once you’ve got it up and running, select the Playback menu: … and select the Hifibetty DAC Plus for the Output Device and *DAC Model. Make sure you enable I2S DAC: For the options,…read more

Change the File Extension in Typescript (or Javascript)

Posted by in Software, Tutorial

TL;DR: You need to get the root name (without the extension) and append the new extension. Then, it only depends on how tolerant you are. The other day I figured I needed a function to change the file extension (from a .jpg to a .nfo). Since I haven’t found a ready made function to do this, I decided to create my own (it’s also a good exercise for my neurons…). The function ended up having the following steps: Prerequisite: the function input parameters are the file name (not the full…read more

Consistent Testing

Posted by in Software, Tutorial

TL;DR: Delete the settings file before starting the test. Today I implemented a simple wrapper over the electron-settings functionality to gibe me access to a set of properties via get/set methods. My scenario is simple: I have a property named path.backup and I want to be able to get, set andtest it’s set`. The code is:

Now, my testing code would be something along the lines:

And I was surprised to find the test failed in the second part (can detect it has source paths). Consistently. Then, I…read more

Delete Dependent Entries of a Table in Oracle PL/SQL

Posted by in Software, Tutorial

The other day I had a task to clean up a database which was populated with a list of records. Unfortunately, my main table is linked to a host of other tables via foreign key dependencies and, to make things worse, no CASCADE constraints are specified. The process I want to is as follows: Scan main table First, we need to find the records in the main table we want removed. This is a simple SELECT statement:

In my case, the statement is:

(the 80, and 122 are…read more

Poor Man’s Mocks in TypeScript

Posted by in Software, Tutorial

Today I went against my better judgement of usign a mock framework and decided to create my own mocks to allow coverage testing for an IPC-calling code. My reference code I wanted to test is:

The code would use an angular service named PathService which, for the purpose of this test only has a method named getSourcePaths(), which returns a Promise. Now, I needed to emulate that method, and the code I wrote to do that is:

It basically defines an object containing a method getSourcePaths() which returns…read more

WordPress with HTTPS on Dreamhost and CloudFlare

Posted by in IT, Tutorial

Today I’ve got my blog work over HTTPS, including admin. Woo-hoo! Below are the steps I used to do it. Prerequisites My configuration is as follows: Hosting on Use CloudFlare free account WordPress 4.7.1 at the time of writing Initialisation From the Dreamhost Panel, select Domains > Secure Hosting: You’ll be presented with a panel to select the type of certificate. I chose to use Let’s Encrypt because it’s free: Once you select Let’s Enctypt SSL, you’ll have to select the domain, accept the T&C and click Add Now:…read more

Scan Decorated Classes in Typescript

Posted by in Software, Tutorial

TL;DR: Make the decorator set a property in the class and look for it. While trying my hand at writing an ORM, I had a problem of initialising the database through a dummy instantiation of some models, without running an explicit command. In java, I can use code generation to provide a list of objects following a pattern (e.g. implementing an interface). Here, the concepts are somewhat different and I found out I can use decorators. My model looks like this:

where the @table() and @field are decorators. Ideally,…read more

Make Electron Work with Sqlite3

Posted by in Software, Tutorial

The other day I tried to integrate knex with a SQLITE3 back-end. Unfortunately, the instant I’ve tried to instantiate knex, I’ve got a lot of errors. After getting rid of them, I found that I can’t get sqlite3 to work at all, even though I’ve checked the installation and it was OK (got the binary downloaded and even rebuilt it). Uncaught Error: Cannot find module ‘/…/node_modules/sqlite3/lib/binding/node-v51-darwin-x64/node_sqlite3.node’ So, here are the steps that I did to make it work: install electron-rebuild

install sqlite3 using npm

rebuild electron with sqlite3….read more