How to handle resize event in Nuxt JS

NuxtJS

How to use Tab key to move between macOS controls

Tips and tricks

By default, you cannot move between macOS control using Tab key. You can change it after some steps:

  1. Open System Preferences → Keyboard → Shortcuts
  2. Find section Full keyboard access…, then select All controls.
macOS Keyboard Settings

Loading Web Fonts with the Web Font Loader in Nuxt.JS

NuxtJS

Several years ago the consensus on font loading in the community was that, as a website loads, all fonts should be hidden until the correct resources have.

Now, let ‘s do it for Nuxt.JS. This is steps to configure:

  • Include webfontloader via npm install webfontloader --save
  • Add webFontLoader.js file to /plugins folder:
import WebFont from 'webfontloader';

WebFont.load({
google: {
families: ['Fira Sans:400,500,600,700:latin,vietnamese']
}
});
  • Adjust nuxt.config.js:
plugins: [
{src: '~/plugins/webFontLoader.js', ssr: false}
],

Reference resources:

How to auto redirect Netlify site to HTTPS

Netlify

Netlify support two ways to config redirect rules for your Netlify site:

  1. Via _redirects file.
  2. Via netlify.toml file.

I prefer the second way because of limitation of the first one.

If you’re running a build command or site generator, the _redirects file should end up in the folder you’re deploying (the Publish directory in your settings)

From Netlify documentation

Just put below config into your netlify.toml file.

For more information, you can read it from https://www.netlify.com/docs/netlify-toml-reference/#redirects.

How to solve ‘ReferenceError: window is not defined’ when importing Vue plugin in Nuxt.JS

NuxtJS

I need to use Vue plugin named vue-flash-message in Nuxt.JS. I installed it via NPM and created file vue-flash-message.js in folder plugins.

import Vue from 'vue';
import VueFlashMessage from 'vue-flash-message';

Vue.use(VueFlashMessage);

Then I tried to run `npm run dev` to test whether the plugin works. But it doesn’t work.

The reason is the default mode of Nuxt is SSR. The variable window is only available in the browser, not on the server.

And I found the solution, I just change the file content like below:

import Vue from 'vue';

if (process.browser) {
window.onNuxtReady(() => {
const VueFlashMessage = require('vue-flash-message');
Vue.use(VueFlashMessage);
})
}

After that, it should work fine. You also apply the idea for other Vue plugins.

How to make Bulma cards have equal height

Bulma

How to make Bulma cards have equal height?

Just add the following CSS:

Vue.js 2 Cookbook

VueJS 2 Cookbook Cover

Vue.js is an open source JavaScript library for building modern, interactive web applications. With a rapidly growing community and a strong ecosystem, Vue.js makes developing complex single page applications a breeze. Its component-based approach, intuitive API, blazing fast core, and compact size make Vue.js a great solution to craft your next front-end application.

From basic to advanced recipes, this book arms you with practical solutions to common tasks when building an application using Vue. We start off by exploring the fundamentals of Vue.js: its reactivity system, data-binding syntax, and component-based architecture through practical examples.

After that, we delve into integrating Webpack and Babel to enhance your development workflow using single file components. Finally, we take an in-depth look at Vuex for state management and Vue Router to route in your single page applications, and integrate a variety of technologies ranging from Node.js to Electron, and Socket.io to Firebase and HorizonDB.

This book will provide you with the best practices as determined by the Vue.js community.

Download link for ebook: http://bit.ly/2M3I47K.

Please send a request and I will share it with you with sample code files (~300MB zipped)

How to remove “Remaining deprecation notices” while running Symfony test cases

Symfony Test

Sometime, when you run some Symfony tests, there is a lot of deprecation warning like this:

Symfony Test

Solution: Just add below code

<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
</php>

to your phpunit.xml (or phpunit.xml.dist)

How to use jQuery in NuxtJS

NuxtJS

Today, I will guide you how to use jquery with NuxtJS project.

  1. npm install --save jquery.
  2. Open nuxt.config.js and add:

That’s all! Hope this helpful for you!

Generate JPA Entity Script

IntelliJ IDEA Logo

I am using IntelliJ IDEA to write Java code.

It has built in script to generate POJOs class, but I want to generate JPA Entity classes. So today, I wrote a Groovy script to do it.

It saved my time and I hope it helpful to you!

Ten ways to become a better developer

  1. Read other people’s code. ☑
  2. Get someone to read your code. ☑
  3. Fix bugs before writing new code. ☑
  4. Learn a new technology. ☑
  5. Keep it stupid simple (KISS). ☑
  6. Write a blog post about your code. ☑
  7. Contribute to open source. ☑
  8. Fix it, don’t hack it. ☑
  9. Increase code coverage by 1%. ☑
  10. Leave your desk every hour.

Source: https://stephenhaunts.files.wordpress.com/2014/04/10-ways-to-be-a-better-developer.png

Note on migrating Spring Boot 1.5 to 2.0

Spring Framework Logo

1. Useful links
First of all, you should read recommended links:

2. Tips and solution for problems

  • Table ‘hibernate_sequence’ doesn’t exist

Solution: Add config spring.jpa.properties.hibernate.id.new_generator_mappings=false

  • Spring Boot 2.0 use HikariCP by default, so you should add config for HikariCP

Solution:

Add config

spring.datasource.hikari.max-lifetime={max-lifetime-value}
spring.datasource.hikari.idle-timeout={idle-timeout-value}

Note:
– Value for config must be in millisecond.
– spring.datasource.hikari.idle-timeout < spring.datasource.hikari.max-lifetime < database wait_timeout
– For MySQL/MariaDB, use query SHOW GLOBAL VARIABLES LIKE 'wait_timeout'; to get wait_timeout, this value is in second
– For example, database wait_timeout = 600 second, so I can assign value as below:
spring.datasource.hikari.max-lifetime=500000
spring.datasource.hikari.idle-timeout=400000

  • Use MariaDB driver for MariaDB instead of MySQL Driver

Solution:
Step 1: Remove MySQL Driver:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
Step 2: Add MariaDB Driver:
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<scope>runtime</scope>
</dependency>
Step 3: Change database connection URL: change from jdbc:mysql://... to jdbc:mariadb://...

%d bloggers like this: