React Code Snippet Generators with IntelliJ Idea

I am a big fan of anything than can be automated, especially when it comes to boiler plate plumbing.  Even more so for a Java developer like myself taking up React.  The following snippets have saved me lots of typos and errors, I will suspect it will for you too!

How to generator snippets in IntelliJ Idea

Before we go any further here is how to generate code snippet in IntelliJ Idea

  •  Simply type abbreviation name of the required snippet in the editor in the target file and press 

  • You can further narow the list suggestions by IntelliJ Idea by typing more characters of your abbrevation.

Note:

  • Component name would be taken from the file name “ManageCoursePage.js”
  • For those on Visual Studio Code IDE the Code generation for React can be achieved with the Typescript React Code Snippet Extention

I will pick a few from the above screenshot to illustrate what code is generated.

Creates a React component class with PropTypes and ES6 module system

  1. Type ​`​rccp` in your editor
  2. Then press ⇥ to generate

Generated Snippet

Note Component name would be taken from the file name “ManageCoursePage.js”

import React, {Component} from 'react';
import PropTypes from 'prop-types';

class ManageCoursePage extends Component {
  render() {
    return (
    );
  }
}

ManageCoursePage.propTypes = {};

export default ManageCoursePage;

Creates a React component class with ES6 module system

  1. Type ​`​rcc` in your editor
  2. Then press ⇥ to generate

Generated Snippet

import React, {Component} from 'react';

class ManageCoursePage extends Component {
 render() {
 return (
 );
 }
}

export default ManageCoursePage;

Creates a React component class connected to redux with dispatch

  1. Type ​`​rrdc` in your editor
  2. Then press ⇥ to generate

Generated Snippet

import React, {Component} from 'react';
import {connect} from 'react-redux';

function mapStateToProps(state) {
  return {};
}

function mapDispatchToProps(dispatch) {
  return {};
}

class ManageCoursePage extends Component {
  render() {
    return (
    );
  }
}

export default connect(
  mapStateToProps,
)(ManageCoursePage);

Creates a React component class with PropTypes and all lifecycle methods and ES6 module system

  1. Type ​`​rcfc` in your editor
  2. Then press ⇥ to generate

Generated Snippet

import React, {Component} from 'react';
import PropTypes from 'prop-types';

class ManageCoursePage extends Component {
  constructor(props) {
    super(props);

  }

  componentWillMount() {

  }

  componentDidMount() {

  }

  componentWillReceiveProps(nextProps) {

  }

  shouldComponentUpdate(nextProps, nextState) {

  }

  componentWillUpdate(nextProps, nextState) {

  }

  componentDidUpdate(prevProps, prevState) {

  }

  componentWillUnmount() {

  }

  render() {
    return (
    );
  }
}

ManageCoursePage.propTypes = {};

export default ManageCoursePage;

Conclusion

I hope you found the above helpful in saving you time and potentially reducing typos/errors and your chances of RSI.  And of cause these are live code snippets and can be managed like other snippets for Java and other languages via Intellij Idea’s preferences under “Live Templates”.

React-Code-Snippets-Generator-IntelliJ-Idea-Manage.png

Elasticsearch Ransomware

Elasticsearch logo

TLDR:

  1. Use X-Pack if you can,
  2. Do not expose your cluster to the internet,
  3. Do not use default configurations e.g. ports,
  4. Disable http if possible,
  5. If it must be internet facing: run behind a firewall, reverse proxy – Nginx (see example config), VPN etc,
  6. Disable Scripts,
  7. Regular back-up of your data with curator if you are not already.

Well, we all see that coming, didn’t we?  Once MongoDB started being ransom by criminals other No-SQL type technologies are surely on queue to follow. Now Elasticsearch Ransomware, no surprise neither that most Elasticsearch clusters are open to the internet.  Goes without saying even secure ones are mostly behind week/guessable passwords, default ports with unneeded http enabled.

The attackers are currently empting out clusters with a note left behind for payment:

 “Send 0.2 BTC (bitcoin)to this wallet xxxxxxxxxxxxxx234235xxxxxx343xxxx  if you want recover your database! Send to this email your service IP after sending the bitcoins xxxxxxx@xxxxxxx.org”

Rest assured if your are using elastic cloud you will be protected by their default shield/x-Pack protection.  To protect your self hosted cluster, the team at Elastic have posted a guide here.  Such a guide really should not be news to any Elasticsearch admin! If it is then action is nigh!

There is also a detailed step by step guide on all things securing your Elasticsearch cluster: “Don’t be ransacked: Securing your Elasticsearch cluster properly” by Itamar Syn-Hershko

So far its been mostly Amazon exposed services.  But the same Elasticsearch Ransomware techniques against an unsecure (wrongly configured) Elasticsearch instance can be applied to any other hosted/self Elasticsearch service.