Posts

Showing posts from 2018

react-quill Integrate quill-image-resize-module

Image
React-qill  is a great free package which can be used for design editors. However, if you are using the image upload feature, there is a problem of integrating resize package. This was discussed in may treads and I was able to find the best approach integrate it with react-starter-app. https://www.npmjs.com/package/quill-image-resize-module If you use the following code, import Quill from ' quill ' ; import { ImageResize } from ' quill-image-resize-module ' ; Quill . register ( ' modules/imageResize ' , ImageResize); const quill = new Quill (editor, { // ... modules : { // ... imageResize : { // See optional "config" below } } }); The following error is common. TypeError: Cannot read property 'imports' of undefined var d = window.Quill.imports.parchment In order to overcome the issue , you have to update the node_modules/react-scripts/config/webpack.config.

xe.com api integrate with postman:authentication

Image
According to xe.com document we have to use the basic auth and they not provide information about the credentials. curl –i -u account_id:api_key "https://xecdapi.xe.com/v1/account_info/"  But in order to login you should provide the  Account ID   for username and the  Account API KEY   for password for login, which is given after creating the account. 

React JS Tabs Add and Close Tabs

https://ctxhou.github.io/react-tabtab/#add-close In order to use Tabtab we have to downgrade the version of the styled component  to 3.4.10 in order to use   "react-tabtab": "^1.8.2".

Firebase Storage - File upload to folder 403 Firebase Storage: User does not have permission to access

Image
When I was using firebase storage from the client side without admin sdk , I got the following error with the authenticated user, when I am uploading an image.   var temp = storage.ref().child("temp")                          .child(file.name);     temp.put(file)     .then(snap => { .... } Firebase Response  : Firebase Response  : FirebaseStorageError {code_: "storage/unauthorized", message_: "Firebase Storage: User does not have permission to access 'temp/50.png'.", serverResponse_: "{ ↵   "error": { ↵     "code": 403, ↵     "message": "Pe…n denied. Could not perform this operation" ↵   } ↵ }", name_: "FirebaseError"} The error is due to the issue in firebase storage rules. The document pages do not specify how to set permission to all the objects under the given folder . However , they have given an example, to resolve the issue. See the example at t

Google Storage set file permission when Save File or Write Stream

Image
The brackets in the Google cloud storage or Firebase storage have a permission set which is common to all files. However, we should have the capability to set the permission to each file as we need. Although I have discussed early in the post  Make Storage Public , the custom permission can correctly assign using  ALC. Refer the Doc:https://cloud.google.com/nodejs/docs/reference/storage/1.3.x/Acl#add If you are using a storage file you can access the file and do the modification.    const file = firebase.storage().bucket().file('originals/file.png');                                    const options = {                                     entity: 'allUsers',                                     role: storage.acl.READER_ROLE                                   };                             file.acl.add(options, function(err, aclObject) {}); If you are using a write stream, the process is a bit different. You have to create metadata variable a

Firebase Storage Make only Selected Basket (Folder) Public

Image
 One of the big issue I face with google cloud storage is when I go to build a site which has public as well as private sections. Defult rule  as follows make the whole basket open to read which is not necessary.  match /{allPaths=**} {       allow read;       allow write: if request.auth != null;     } If you make a basket (generated)  base rule and try to access the file without token like below , it will gives permission issue . https://firebasestorage.googleapis.com/v0/b/<project id>.appspot.com/o/generated%test_400*400.png?alt=media&token= {   "error": {     "code": 403,     "message": "Permission denied. Could not perform this operation"   } } The issue have to resolve in google cloud storate admin by giving access to perticular basket. Ref : https://cloud.google.com/storage/docs/access-control/making-data-public#objects Go to following URL : https://console.cloud.google.com/storage/browser?pr

Firebase Storage ApiError: Forbidden #299 ... ApiError: Forbidden at new util

Image
When, I want to utise firebstore for the frist time in the google cloud functions,  the main problem I had to face it the integration issue raise as follows.  The google firebase and the google cloud storage eveloved seperately and in order to use the clould storage in firebase functions, the special autherntication need to be grantted even you are using firebase admin sdk. ApiError: Forbidden at new util.ApiError (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:107:10) at Object.parseHttpRespMessage (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:149:33) I implemeted the firebase admin sdk as follows. const firebaseAdmin = require("firebase-admin"); firebaseAdmin.initializeApp(functions.config().firebase); And firebase cloud bucket implemented  as follows . const storageRoot = firebaseAdmin.storage().bucket() Google document also indicate authentication req

Homebrew Install Mysql and Connect to Workbentch

Install MySql in MacOS Seirra can be done as follows. brew install mysql brew services start mysql mysqladmin -u root password 'newpassword' Login ; mysql -u root -p  Get Config Location : mysql --help | grep cnf Config Path :  export MYSQL_PATH=/usr/local/Cellar/mysql/8.0.12  PATH=$MYSQL_PATH/bin:$PATH Connect Squrel if you filed to collect  with mysql as follows :   MySQL said: Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/lib/plugin/caching_sha2_password.so, 2): image not found https://stackoverflow.com/questions/51179516/sequel-pro-and-mysql-connection-failed Go to my.cnf file and in section   [mysqld]   add line: default-authentication-plugin=mysql_native_password . Then, login to mysql server from terminal and run   mysql -u root -p , then inside shell execute this command:   ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '<password>'; exit f

Migrate to php7 in Mac os Sierra with Apache Configurations

Image
Mac os Sierra defult comes with Apache as well as php 5.. Fi you want to start apache with defult settings The following articles gives short as well as comprehesive guideline. https://jason.pureconcepts.net/2016/09/install-apache-php-mysql-mac-os-x-sierra/ https://medium.com/@JohnFoderaro/how-to-set-up-apache-in-macos-sierra-10-12-bca5a5dfffba However , I wanted to setup firebase integration with laravel and it requires php 7. ( kreait/firebase-php ^ 4.0 ) You can eassy install php 7 using homebrew. brew tap homebrew/dupes brew tap homebrew/versions brew tap homebrew/homebrew-php brew unlink php56 brew install php70 Thin you can check the version as follows . $ php --version But if you have enabled defult php in Mac Os , you will see  it will return 5.6 In order to chanage this you have to edit the httpd.conf file of apache.  Stop apache -    sudo apachectl stop move to etc/ apache2. -    cd /etc/apache2 backup httpd.conf.   - sudo cp httpd.conf httpd.conf.er

Firebase Cloud Functions Triggers with Two varibles

Image
 Although firebase functions document not mentioned about how many varible values can be exhist in firebase onWrite() tirgger , I have used it upto 2 levles without any issue.  For an exaplen in the blow code , I have consider the change in list under the userId ,, The value will be wrriten under the varible of user.  exports.testFunctionName = functions.database.ref('/user-list/{user}/{pushId}').onWrite(( change,context) => {             const original =  change.after.val();             var pushId=context.params.pushId;                 var userId=context.params.user; ...

Covert firebase to Node Express Rest API

Image
 Firbase hosting and functions provide nice solution to develop a REST api .The following video from firebase provide more infromation than our simple REST API. https://www.youtube.com/watch?v=LOeioOKUKI8 I thought of detail the process  in to more depth. First , you need to go to desired folder and install firebase tools. You should have npm for do that. Then create a firebase account and project with desired name. After that, you have to use the command firebase init. The online authentication will be proceed there after .You have to copy and paste the URL displayed in the console to the web browser. Then there we have to create the local project with firebase hosting and firebase functions. In the project you can see the functions folder ,which used to create the functions. In order to use the express, you need to use express npm packge. Move to functions folder and then run npm install express, then firebase-functions. If you are using firebase database , you

How to user firebase Orderby Wisely

Image
There are number of ways  firebase order by can be used.Ferfer the following example.  It can be user as a where clause  to select values based on child attribute.You dont need to select items within the for loop.  todoRef.orderByChild("title").equalTo("test 1").once('value').then(function(snapshot) {     snapshot.forEach(function(childSnapshot) {         var todoID=childSnapshot.key; }) }).. We can use it as fallow,,

Use node which-country

Image
I  need to take the users country based on the geo-codinates provided by the mobile application. whlile doing some reaserch in node which-country , I found that ituseful,but need to pass value wisely.  https://www.npmjs.com/package/which-country  var whichCountry = require('which-country'); // pass it as  [latitudes,logitudes] var userCountry = whichCountry([6.795019389999998,79.88569332999997]); console.log('test userCountry :'+userCountry);  //return null // pass it as [logitudes,latitudes] var userCountry = whichCountry([79.88569332999997,6.795019389999998]); console.log('test userCountry :'+userCountry);  //return LKA I test the application with the given code of me in the test packges given by them. https://github.com/vkurchatkin/which-country/blob/master/package.json AUS -22.000825,132.889122 BLR 52.337547,24.080529 CAN 57.255393,-106.712553 CYP 35.315045,33.681395 DZA 23.184085,7.117638 ITA 39.926747,9.017427 JPN 43.771243,142.764986

Stripe Testing With 1 Day Plan - Subscription Not Cancel Automatically

Image
We normally use Stripe one day plan to test the scenarios. However we found a unexpected behavior  with stripe when we are using stripe one day plan. We created a subscription with the test card " 4000000000000341 " which make the payment unsuccessful when try to charge. According to dunning rules subscription have to cancel after 2 attempts. " It's likely that the Subscription hasn't cancelled because it doesn't have enough time to cancel as you have a daily Subscription. You see when a new invoice is created for a Subscription, it resets the retry logic (basically setting the retries back to zero).  For a daily Subscription you can't have more than 1 retry as it wouldn't give the retry logic enough time to carry out the final condition (i.e cancel the Subscription).  "

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory Different

Image
 This is a common error I found when I upgrade from node 8.8 to node 10.1 within my mac osx seirra. > node build.js || nodejs build.js xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance node 10.1 is not a stable release and I had to backdate it with the stable version. In addition, to fix the issue I had to run few commands to identify the location of command line tools. https://stackoverflow.com/questions/18533761/find-out-the-path-location-to-command-line-tools-for-xcode?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa /usr/ bin / clang -- version Apple LLVM version 9.0.0 (clang-900.0.39.2) Target: x86_64-apple-darwin16.7.0 Thread model: po

Firebase Cloud Functions TypeError: Cannot read property 'val' of undefined

Image
I have started using fire-base functions some time back and it was in beta release. When I try to update the functions within the production with the different node packages of firebase functions, following error occurred. TypeError: Cannot read property 'val' of undefined at exports.<>.functions.database.ref.onWrite.event (/user_code/index.js:467:38) at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:112:27) I have used number of  fire base functions  and all of them triggering based onWrite leads to the above error. After small search I found the following discussion , https://stackoverflow.com/questions/49746905/firebase-typeerror-cannot-read-property-val-of-undefined?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa I have moved  from     "firebase-functions": "^0.9.1", to  "firebase-functions": "^1.0.2", where there is a major cha