Developers Notes

My Journey as Software Architect

ccxt Binance Futures Testnet Connection Example

I have some need to test the bot that i created on testnet Binance. i'm using ccxt library to connect. const ccxt = require('ccxt') const binance = new ccxt.binance({ apiKey: 'APIKEY', secret: 'SECRET', options: { defaultMarket: 'future' }…

Good Knex.js Tutorial

I can recommend this articles: Build your own REST API with Node, Express, Knex and PostgreSQLhttps://medium.com/javascript-in-plain-english/build-your-own-rest-api-with-node-express-knex-and-postgresql-aec98fe75e5 Build your own REST API …

In Search of Async Retry

my current method to retry if error occured is this: let tryCounter = 1;const retryCount = 99;let result = null;let error = [];while (tryCounter <= retryCount) { let errContainer = null; try { result = await executeAsyncMethod(); break; } …

My Sequelize Notes

It's been 1 years since i'm into NodeJS, and sequelize is my favorite ORM to works with database. 1.After create a new Row, you want to get the ID of the data, you must make some changes in the model, and add this. id: { allowNull: false, …

Recommended Terminal Application Replacement

1.exa A modern version of ‘ls’. https://the.exa.website/ Github Repo: https://github.com/ogham/exa Exa have a similar options like ls , my usual way to use exa is exa -lah 2.bat A cat(1) clone with wings. Github Repo: https://github.com/sh…

Generate Public Key using Private Key

Sometimes, you need to provide public key on some services, you can use this command to generate the public key $ ssh-keygen -y -f ~/pathToPrivateKey/private.pem > ~/.ssh/public.pub Enter passphrase:

Configure NodeJS and oracledb in Linux Server

There is many other ways, but this is my way to configure: Server: -Linux Ubuntu 18.04 Steps: Do upgrade repositoryapt-get update Install alien, wget and other dependency package by doing apt-get install alien wget libaio1 libaio-dev Creat…

PHP in macOS & Linux Server

If you have MAMP installed, and you want to use it for cli, you can add this to your bash profile export PATH=/usr/local/bin:$PATHexport PATH=/Applications/MAMP/bin/php/php5.5.10/bin:$PATH Make sure the order is correct. Put export PATH=/u…

React Native full Image width & height

sometimes, you want to make your image full , there is workaround. imageStyle: { height: 300, flex: 1, width: null} Using Image.getSize() class PostItem extends React.Component { state = { imgWidth: 0, imgHeight: 0, } componentDidMount() {…

Javascript Object Validation Library

i tried some of validation library, this is what i recommend, oussamahamdaoui/forgJs: ForgJs is a javascript lightweight object validator. Go check the Quick start section and start coding with lovehttps://github.com/oussamahamdaoui/forgJs…

React setState deep nested object/state

I have nested state something like this constructor(props) { super(props); this.state = { auth: false, isStartDateTimePickerVisible: false, isEndDateTimePickerVisible: false, form: { title: 'Lorem Ipsum dolor', startDate: moment(new Date()…

Sequelize Sync {alter:true} always creating new Indexes

i'm using sequelize for my project, and enable sync with alter table, when i run the project, sequelize always create a new indexes, usually, the code something like this. const User = this.sequelize.define('testSync', { email: { type: Seq…

React Native Android Error More than one file was found with OS independent path 'lib/x86/libusb.so'

sometimes, you will face error like this while using 3rd party plugin in react native, like android-jsc. you can set the build.gradle app level module with something like this. packagingOptions { pickFirst 'lib/armeabi-v7a/libblasV8.so' pi…

axios multiple way to set headers

while developing react / react-native , sometimes you will face some issue if you want to post images/files upload to backend server, or if the backend need some header for submit data. you can use one of this configuration for something l…

Git trailing whitespace error on commit

Git

sometimes, when you pull package from repo , or Pod, you will have error something rant about whitespace trailing whitespace after looking on some SO, i figured the easy way to fix this. git diff --cached --no-color > stage.diff && git app…

Let's Encrypt on Ubuntu 16.X / 18.X Cheat Sheet

If you want to integrate Let's Encrypt to make your website running on https & using nginx. This is simple sample config for reverse proxy expressjs apps i use server { client_max_body_size 56M; server_name example.com; location / { proxy_…

Unable to access 'git/attributes'

If you have this issue, usually, the first time you create EC2 / VPS, then git pull from repo. you can use this command cd ~/ sudo chown -R username /Users/username

React Lifting State Up

Sometimes, you need to communicate between Parent to Children Component, you can use props for this. But what if you want to communicate between Children to Parent Component, there is official method on React to do this, by using `Lifting …

'Multiple commands produce' error when building with new Xcode build system

Sometimes, when you try to archive ios apps, you will find Multiple commands produce errors, usually React & Yoga on React Native 0.59 you can add this to the Podfile post_install do |installer| installer.pods_project.targets.each do |targ…

React Native Async Storage with Expire

if you want to cache fetch result, you can use this library. react-native-expire-storage - npmhttps://www.npmjs.com/package/react-native-expire-storage How I can set expiration date for AsyncStorage - react native - Stack Overflowhttps://s…

React Native TextArea Custom Components

sometimes, you need to create textarea component, you can use this snippets. <View style={styles.textAreaContainer} > <TextInput style={styles.textArea} underlineColorAndroid="transparent" placeholder="Type something" placeholderTextColor="grey" numberOfLines={10} multiline={true} /> </View> ... con…

react-navigation, navigate to same screen with different params

If you have some screen like blog post, and you have a related news, you can navigate using this const navigateAction = NavigationActions.navigate({ routeName: 'APage', params: { title: title, name: 'APage', }, key: 'APage' + APageUUID });…

Fix react-native-html-view rendering image on Android

There is time i'm using this library to render html in my RN apps. https://github.com/jsdf/react-native-htmlview There is some issue in rendering image on Android, because the <img> tag is wrapped in <p> so i use this regex to replace the formatti</p>…

Reset React Native Packager

In case you need to clean cache of the packager, Ref: https://gist.github.com/jarretmoses/c2e4786fd342b3444f3bc6beff32098d#file-react-native-clear-cache RN < 0.50 - watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ &…

React Native init specific version

if you want to init RN by specific version, run this command react-native init newproject --version react-native@0.59.10 but first, install react-native-cli first

SQL, order by specific value first

You can order it by using order by case, the example is shown below using Postgres ORDER BY CASE WHEN( status > 6) THEN 0 WHEN(status > 3) THEN 1 END

Cold Boot Reset Android Emulator using Terminal

if you having some issue with emulator, and you cannot reset the Emulator using UI, you can run this command to reset the emulator emulator @avd_name -no-snapshot-load

Sequelize Migration Cast STRING to INTEGER

if you face this issue, you can make the migration like this queryInterface.changeColumn('table', 'column', { type: 'INTEGER USING CAST("column" as INTEGER)' });

Sequelize Migration to create Postgres Function

if you need to make some sql function, you can use something like this. const query = `CREATE OR REPLACE FUNCTION "public"."last_day"(date) RETURNS "pg_catalog"."date" AS $BODY$ SELECT (date_trunc('MONTH', $1) + INTERVAL '1 MONTH - 1 day')…

npm install Access Denied

If you face this issue Unhandled rejection Error: EACCES: permission denied, open '/home/ubuntu/.npm/_cacache/index-v5/04/82/83016d88317bc219a7ecb0d1ef655bed9bb26a45696ad38e2590e0486bef' Unhandled rejection Error: EACCES: permission denied…