971ScrollTo, Vue and Vue-Router

After navigating to a certain page - let's call it Chat, it want to scroll programmatically to the bottom of the page. In pure JS it would look like this:


Which words fine - but it does not work after Vue-Router changes. For that to work, the rounter config needs to be changed:

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else if (to.name === 'Chat'){
      return { x: 0, y: window.innerHeight }
    return false

If a savedPosition exist (in case of back/forward navigation with browser buttons), return that saved position, if the page is called Chat, then scroll y to the window.innerHeight.

970Parsing Body JSON for quick inspection

An API dumps its output as string in the HTML body. Not really much use, not really easy to inspect it. The solutions? Parse the body with JSON.parse an inspect it in the console.

job","status":"publish","type":"jobs","link":"http:\/\/\/aaa\/jobs\/another-test-job\/","title":{"rendered":"Another Test 

968Clean Vue Distribution Files

Removing the timestamp from css and js distribution files.
File: vue.config.js

module.exports = {
  publicPath: '',
  chainWebpack: config => {
    if(config.plugins.has('extract-css')) {
      const extractCSSPlugin = config.plugin('extract-css')
      extractCSSPlugin && extractCSSPlugin.tap(() => [{
        filename: 'css/[name].css',
        chunkFilename: 'css/[name].css'
  configureWebpack: {
    output: {
      filename: 'js/[name].js',
      chunkFilename: 'js/[name].js'

966Combining JSON files in Python

Quick python script to combine several JSON files into one. File names are dict keys in the JSON output.

import os
import json

entries = os.listdir(os.getcwd())

animationFiles = [

output = {}

for name in animationFiles:
  with open(name + '.json') as f:
    output[name] = json.loads(f.read())

outputFile = open('output.json', 'w')
outputFile.write( json.dumps(output) )


964Gettting HTML Content from index.html into Vue

Vue index.html:

    <div id="app"></div>
    <!-- built files will be auto injected -->
    <div id="modalContent" style="display:none">
      <div id="modal1">
        Hello Modal Content Hello Modal Content

Why add another hidden div to index.html? To be able to edit/add content without rebuilding and running npm run build.

In Vue:


Actually basic JS, nothing special to Vue.

963General JS Variables in Vue

Accesses JS from outside Vue:


  var test = "test";

In Vue:


Obvious, but nevertheless

962Zooming and Panning in D3 with Bounds

Standard d3.zoom, pans to infinity:

this.zoom = d3.zoom()
  .scaleExtent([1/2, 100])
  .on("zoom", () => {
    g.attr("transform", d3.event.transform)

Restrict pan to visible area, adjust padding (p):

this.zoom = d3.zoom()
  .scaleExtent([1/2, 100])
  .on("zoom", () => {
    var p = 0.95, e = d3.event.transform, w = this.width, h = this.height
    e.x = Math.min(Math.max(e.x, -w * e.k * p), w * p)
    e.y = Math.min(Math.max(e.y, -h * e.k * p), h * p)
    g.attr("transform", e)

Vue 2.x, D3 5.0

961A Relative Path for Vue

Create a new file, call it vue.config.js


module.exports = {
  publicPath: ''

This overwriting the default value of '/'.

Source: https://cli.vuejs.org/config/#publicpath

959Making a Bootable Installer for OSX

Straight from the Apple Support page: How to create a bootable installer for macOS https://support.apple.com/en-us/HT201372 High Sierra Page https://support.apple.com/en-us/HT208969 High Sierra App Store Link (hidden from standard Search) https://itunes.apple.com/us/app/macos-high-sierra/id1246284741?ls=1&mt=12

953Changing Languages in WordPress

Install additional language: Change user language: