NodeJS - Unit Test DynamoDB

May 10, 2019 2 min.

Introduction This page explains how to mock dynamodb client using Sinon and Proxyqurie Required dependencies Install the following dependencies npm install --save-dev sinon npm install --save-dev proxyquire Sample Project Setup a sample project # Create a sample project directory mkdir myproject cd myproject # Initalize npm npm init -y # Install project dependencies npm install aws-sdk # Install Unit test framework globally (if you have not already installed) npm install -g mocha # Install Test dependencies npm install --save-dev sinon npm install --save-dev proxyquire create a index.

How to Enable Disable Startup Services in Ubuntu

Mar 15, 2019 1 min.

Enable / Disable startup service # Disable a startup service sudo systemctl disable apache2 # Or sudo update-rc.d apache2 disable # Enable a startup service sudo systemctl enable apache2 # Or sudo update-rc.d apache2 enable Remove / Add # Delete sudo update-rc.d apache2 remove #Or sudo update-rc.d -f apache2 remove # To add it back sudo update-rc.d apache2 defaults

How to Clear Cloudfront Cache Using Aws Cli

Jan 9, 2019 1 min.

aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths '/*' Replace $DISTRIBUTION_ID with the cloudfront distributions ID Referece:

Extract Data From Json String

Jan 8, 2019 1 min.

myjson='{"somekey":"someval"}' v=`echo $myjson | jq '.somekey'` echo $v output: "someval" # Get the value wihout quotes v=`echo $myjson | jq -r '.somekey'` echo $v output: someval

Steps to create never expiring Facebook access token

Jul 4, 2018 1 min.

Open Graph API Explorer Select the application in the “Application” drop-down menu (Note: Not the “My Apps” menu) Click “Get Token” > “Get User Access Token” In the pop-up, under the “Extended Permissions” tab, check “manage_pages” and “publish_pages” Click “Get Access Token” In the popup, grant access from a Facebook account that has access to manage the target pages (This popup will flash and disappear if permissions are already granted) Copy the token that appears in the “Access Token” field (which is your short-lived access token) Invoke the following URL which gives long lived token (expires in 2 months): https://graph.

Enable grub boot menu from window 10

Dec 29, 2017 1 min.

Execute the following command from Windows 10 in command prompt (run as administrator) bcdedit /set {bootmgr} path \EFI\ubuntu\grubx64.efi Execution Logs for reference: Microsoft Windows [Version 10.0.14393] (c) 2016 Microsoft Corporation. All rights reserved. C:\WINDOWS\system32>bcdedit Windows Boot Manager -------------------- identifier {bootmgr} device partition=\Device\HarddiskVolume1 path \EFI\Microsoft\Boot\bootmgfw.efi description Windows Boot Manager locale en-US inherit {globalsettings} default {current} resumeobject {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} displayorder {current} toolsdisplayorder {memdiag} timeout 30 Windows Boot Loader ------------------- identifier {current} device partition=C: path \WINDOWS\system32\winload.

MySQL MariaDB Export and Import

Dec 26, 2017 1 min.

Export the database Use the following command to export the database mysqldump --user=root --password=mypassword \ --host=myhost1 --port=3306 \ --single-transaction --compress --routines \ --result-file=dump.sql \ --databases mydb; Note: Include –single-transaction –compress to export and import quickly. Check documentation for the use --rountines will include procedures/functions in the dump (triggers included by default) --result-file will be the output file (instead of this param, output redirection like mysqldump [options] > dump.

MySQL MariaDB Create User

Dec 26, 2017 1 min.

Create a user similar to root To create user with all the privileges similar to root. CREATE USER 'superuser'@'%' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON *.* TO 'superuser'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES; Create user for Backup A separate user with minimal privileges for taking database dump. CREATE USER 'backup'@'localhost' IDENTIFIED BY 'mypassword'; GRANT SELECT, SHOW VIEW, RELOAD, REPLICATION CLIENT, EVENT, TRIGGER, LOCK TABLES ON *.* TO 'backup'@'localhost'; Note:

MySQL MariaDB utf8 to utf8mb4

Dec 25, 2017 1 min.

Change server settings Refer: on AWS RDS a parameter group needs to be created to apply above settings: refer: Change database Run this SQL for each database: ALTER DATABASE mydb CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci; Change size of indexed columns Reduce the length of indexed columns with utf8mb4 from 256 to 190 because index with 4byte utf8mb4 have issues ALTER TABLE mydb.mytable MODIFY COLUMN mycolumn varchar(190) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; Change Tables Run this SQL for each table:

JEE Container Managed Transaction

Dec 25, 2017 1 min.

Transaction Attribute Client’s Transaction Business Method’s Transaction Required None T2 T1 T1 RequiresNew None T2 T1 T2 Mandatory None error T1 T1 NotSupported None None T1 None Supports None None T1 T1 Never None None T1 Error Container Manager Transaction