24/03/2019 19:01 GMT

For dealing with dynamic ip addresses, the most elegant solution I could find, is to place the ip address of the network into a simple file using a shell script and sync the folder across different machine that you trust using file sync software like Syncthing or Relio Sync. Here an example of a script:

#!/bin/bash
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
IP=$(dig -4 +short myip.opendns.com @resolver1.opendns.com)
if [ "$IP" != "$(cat IpAddress/Server)" ]; then
        echo $IP > IpAddress/Server
        # Tips: you could do some fancy curl stuff here, e.g. cloudflare API ;)
fi

And setup a cron to run the script about every 15 minutes.

Yes, one could say you can use DynDNS but there is a few disadvantages to that approach, for example, you can’t control where you’re sourcing the IP address from, you’ll end up distributing the IP address globally which may not be desirable and you’re handing over control to a third party.

How would I use the file with SSH, that easy I show you an example.

$ ssh -o 'HostKeyAlias myhost' [email protected]$(cat ~/IpAddress/Server)

It’s really that simple, just make sure you add the alias to ~/.ssh/known_hosts and you’re done 🙂

10/03/2019 17:13 GMT

I recently swap Mongo DB driver from a third party to the official driver, the process mostly went smoothly because I was well disciplined in writing high quality code and sticking to good practice otherwise it would of took me a lot longer to complete.

I did have a few issues along the way.

09/03/2019 22:22 GMT

I could stand there and watch the wave all day.

01/03/2019 14:21 GMT

This is the script I used to manage Go’s SDK, it’s built on top of the official Google go way. I run it inside Windows Subsystem for Linux (WSL), it’s manages both WSL and Windows itself in one call inside WSL.

./gvm

#!/bin/bash
go get golang.org/dl/$1
GOOS=windows go build -o /d/go/bin/$1.exe golang.org/dl/$1
$1 download
$1 version
$1.exe download
$1.exe version

Usage example ./gvm go1.9

I also written an uninstall counterpart.

./ugvm

#!/bin/bash
cd $( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )
rm -rf sdk/$1
rm go/bin/$1
rm -rf /c/Users/ChristopherJohn/sdk/$1
rm /d/go/bin/$1.exe

Usage example ./ugvm go1.9

Note: you may to need to adjust the code to get it to work on your system. It’s can also work on pure Unix style systems, just get rid of anything Windows related .exe in the script

I could of used Moovweb’s GVM, but the complexity of the system scares me, honestly I value simple yet brilliant things much better. 🙂

17/02/2019 14:14 GMT

That very easy, all I used was constant variable in it’s own package, just reference the constant variable inside the router or sprintf if you’re doing reverse URL. Here an example of the constant variable I used for URL routing.

package frontUrl

const (
	BlogIndex      = "/"
	BlogAjaxIndex  = "/blogajax"
	BlogIndexPage  = "/p/:page"
	BlogIndexPageF = "/p/%d"
	BlogEntry      = "/blogentry/:idSlug"
	BlogEntryF     = "/blogentry/%d-%s"
	BlogFeed       = "/feed.json"

	FontsFiles       = "/fonts/*filepath"
	JavascriptsFiles = "/javascripts/*filepath"
	StylesheetFiles  = "/stylesheets/*filepath"
	ImagesFiles      = "/images/*filepath"
	FaviconFiles     = "/favicon/*filepath"
	DynImg           = "/dyn-img/:name"
	DynImgF          = "/dyn-img/%s"
	Style            = "/generated.css"
)

| |