Image for post
Image for post
Google Cloud SQL, PostgreSQL Edition

When creating a new Cloud SQL instance…

Ensure that the instance name is picked wisely. You may find it helpful if it remains short, and contains the Cloud SQL edition (MySQL, PostgreSQL, SQL Server) and version number. For example, pg12.


Image for post
Image for post

There might be some confusion regarding using NODE_ENV variable in Node.js apps. A few things you need to be aware of:

(1) Do not set NODE_ENV to anything other than production, development or test.

When you deploy your app to let’s say Google Cloud Functions, the NODE_ENV variable will always be set to production, you will not be able to override it.

Similarly, when you run unit tests, the NODE_ENV variable will always be set to test by the test runner (this is a good default value that you don't want to mess around with, too many tools depend on it). …


If you normally start building your swing- or day-trading watchlist starting from tech analysis, here is a good tool that can help you accelerate this process.

Step 1: Decide which stocks or other financial instruments to trade

For example, in the case with swing trading, you may prefer stocks of large companies with predictable volatility and noticeable up or downtrends.

Step 2: Open this list on the watchlist.io website and scroll through the charts

See S&P 500 Companies list as an example.

Image for post
Image for post
https://watchlist.io/sp500

Step 3: Mark charts with patterns that you’re already familiar with as favorites

Step 4: Save your “Favorites” as a new list, e.g. “July 18th, 2019 (daily)”. Go through each instrument on the list, examine the full price history and financial ratios in your favorite stock analysis tools. Remove instruments that don’t pass your trading criteria. …


Image for post
Image for post
React with/without Redux

As you probably know React.js provides us with these two helpful hooks — React.useReducer() and React.useContext(). You may think that combining them in a creative fashion would give you a perfect replacement for Redux? Not so fast :)

First, let’s see what’s the problem with Context-based implementation and how it may look like:

import React from 'react';const initialState = { ... };function reduce(state, action) { ... }const ReducerContext = React.createContext();function useGlobalReducer() {
return React.useContext(ReducerContext);
}
function App() {
const reducer = React.useReducer(reduce, initialState);

return (
<ReducerContext.Provider value={reducer}>
<Example />
</ReducerContext.Provider>
);
}
function Example() {
const [state, dispatch] = useGlobalReducer();
return (...); …


With Facebook Customer Chat widget you’re now able to connect with your website visitors (customers) even after they left your site. How cool is that ;)

Image for post
Image for post
View source code at https://github.com/kriasoft/react-firebase-starter

You start by creating a Facebook Page for your app or product. Find your Page ID in the About section — you will need that for the widget. Then go to Page Settings > Messenger Platform and whitelist your domain name, otherwise, the widget won’t show up on your site after integrating it.

The widget itself can be integrated by injecting Customer Chat SDK script into your React.js …


Image for post
Image for post

Have you noticed this trend that many JavaScript developers don’t know how to solve pretty basic tasks in their web apps without using Redux?

It starts like this — a developer has two or more components in different parts of the UI and struggling to organize a communication channel between them. That’s the exact problem that Redux is great at solving, right? Well, it depends…

What if you’re app is using a Firebase or GraphQL client (Relay Modern), that already handling data management for you? All you have to do in this case is just to fetch new data from the server and render it. …


Image for post
Image for post

First of all, big thanks to Facebook developers for open sourcing and maintaining GraphQL.js library. It can’t express how well it works for me and my team (BTW, we’re hiring) and I like really how simple yet flexible it is. As Albert Einstein once said:

Everything should be as simple as it can be, but not simpler.

Below you can find a couple of code recipes demonstrating how to throw custom errors as well as log errors in an API project powered by Node.js (v8 or newer), JavaScript (using Babel compiler) and GraphQL.js.

Let’s assume, that you have videos top-level field in your GraphQL schema, that conditionally throws “Unavailable in your country” error depending on the user’s IP address visiting your website. You could just throw a normal error inside of the videos.resolve() method to handle that use case as…


It might be NOT that hard as you think! Let’s see you can you can call C/C++ code or use a native library from a Node.js app.

Image for post
Image for post
Node.js ❤ C/C++

Q: Why would I need to call C/C++ code? There is half a million NPM modules, why would I need native stuff at all?

A: It you don’t need any C/C++ interop right now, it doesn’t mean you won’t need it in the future. …


Image for post
Image for post

This tutorial assumes that you’re already familiar with Create React App (CRA) and a little bit of Relay, and just looking for some examples of how to use them together. Here you will learn:

  • How to modify Create React App setup to use “babel-plugin-relay” in its config
  • How to configure Relay Compiler
  • How to use Relay’s <QueryRenderer /> component
  • How to fetch data with Relay as the user navigates though the site

Note, that many tutorials on the Internet covering the previous version of Relay (aka Relay Classic). …


Image for post
Image for post

If you’re building a GraphQL data API, most likely you want to use lowerCamelCase names for all the fields in your GraphQL schema as recommended by the GraphQL specification. But, it’s likely that your database is using a different convention. For example, in case with PostgreSQL, the practical naming convention to use is snake_case (feel free to ask why in the comments bellow). Let’s see a couple of solutions to this problem.

Solution 1

You can use an ORM tool for Node.js such as Sequelize, Bookshelf, Objection.js, or another. Most of them are capable of converting field names to another case. …

About

Konstantin Tarkus

Bringing the technical edge to early-stage companies with advice on software architecture, best practices, database design, web infrastructure, and DevOps.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store