<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7442072150765022610</id><updated>2026-03-21T15:30:24.309+05:30</updated><category term="PHP"/><category term="JavaScript"/><category term="Android"/><category term="PHP Framework"/><category term="Sencha Touch"/><category term="Laravel"/><category term="iOS"/><category term="Android App"/><category term="Magento"/><category term="Sencha Touch 2"/><category term="Mobile Application"/><category term="Web Development"/><category term="Cordova"/><category term="Sencha"/><category term="Laravel 5.2"/><category term="ExtJs"/><category term="Web Application"/><category term="Apple"/><category term="Objective C"/><category term="iOS App"/><category term="Mobile"/><category term="Xcode"/><category term="Cross Platform Application Development"/><category term="Laravel 5.4"/><category term="iPhone"/><category term="HTML5"/><category term="Hybrid Application Development"/><category term="Magento API"/><category term="Magento Admin"/><category term="Phonegap"/><category term="CSS3"/><category term="Java"/><category term="eCommerce"/><category term="Amazon"/><category term="Android Application"/><category term="Android SDK"/><category term="Magento Mobile"/><category term="PHP Extensions"/><category term="React"/><category term="ReactJs"/><category term="API"/><category term="Cloud Computing"/><category term="iOS 10"/><category term="Amazon EC2"/><category term="AngularJs"/><category term="ArtificialIntelligence"/><category term="Developers"/><category term="MVC"/><category term="NodeJs"/><category term="Programmers"/><category term="iOS 7"/><category term="iPad"/><category term="jQuery"/><category term="AI"/><category term="Amazon AWS"/><category term="Business Applications"/><category term="CSS"/><category term="Google"/><category term="Information Technology"/><category term="MySql"/><category term="OSX"/><category term="Google API"/><category term="List"/><category term="Location Services"/><category term="Online Order"/><category term="Push Notification"/><category term="React Native"/><category term="Technology"/><category term="Web Service"/><category term="Channel Advisor PHP API"/><category term="Database"/><category term="Framework"/><category term="GPS"/><category term="IT Professionals"/><category term="Linux"/><category term="MAC"/><category term="Machine Learning"/><category term="Magento 2"/><category term="Mobile Cart"/><category term="Mobile Website."/><category term="Productivity Applications. Mobile Application"/><category term="Programming"/><category term="Server Admin"/><category term="TypeScript"/><category term="UI/UX"/><category term="Accordion"/><category term="Angular"/><category term="Apache"/><category term="Attendance Management"/><category term="Beginners"/><category term="Cocoa Application"/><category term="Command Line"/><category term="Composer"/><category term="Data Analysis"/><category term="Docker"/><category term="ExtJs Grid"/><category term="ExtJs editor grid"/><category term="Good Programmer"/><category term="Google Search"/><category term="Location aware apps"/><category term="MAMP"/><category term="Magento Mobile Site"/><category term="Mobile Commerce"/><category term="Mobile Website"/><category term="Order"/><category term="Socket"/><category term="Software Engineering"/><category term="Swift"/><category term="System Admin"/><category term="Terminal"/><category term="Ubuntu"/><category term="kubernetes"/><category term=".Net"/><category term="Animation"/><category term="Background Services"/><category term="Big Data"/><category term="Bootstrap"/><category term="Business"/><category term="Camera"/><category term="Configurable Products"/><category term="Data Scraping"/><category term="DataView"/><category term="Device Driver"/><category term="Dynamic Loading"/><category term="Eclipse"/><category term="Employee Tracking"/><category term="Ext.Direct"/><category term="ExtJs 4.0.2a"/><category term="ExtJs 4.1"/><category term="Facebook"/><category term="FireBase"/><category term="GCM"/><category term="Getting Started"/><category term="Great Programmers"/><category term="IOT"/><category term="IT"/><category term="Image"/><category term="Indexing"/><category term="Internet of Things"/><category term="JSON"/><category term="Magento Commands"/><category term="Magento Mobile Store"/><category term="Magento Mobile Theme"/><category term="Magento Synchronization"/><category term="Maps API"/><category term="MediaRecorder"/><category term="Models"/><category term="NLP"/><category term="Natural Language Processing"/><category term="OOP"/><category term="Page Size"/><category term="Paging"/><category term="Paperless"/><category term="PhpMyAdmin"/><category term="Product Page"/><category term="Programmatically"/><category term="Python"/><category term="SOAP"/><category term="SQL"/><category term="SSH"/><category term="Service"/><category term="TinyMCE"/><category term="Tips"/><category term="Touch Events"/><category term="Tracking"/><category term="Windows Azure"/><category term="XML"/><category term="cURL"/><category term="container"/><category term="kubectl"/><category term="mCommerce"/><category term=".Net Framework"/><category term=".Net Versioning"/><category term="Abstraction"/><category term="Ad Hoc"/><category term="Agile"/><category term="Ajax"/><category term="Amazon RDS"/><category term="Amazon S3"/><category term="Amazon SES"/><category term="Angular 7"/><category term="Angular 9"/><category term="Artisan"/><category term="Asp.Net Web Service"/><category term="Assembly"/><category term="Associations"/><category term="Audio"/><category term="Automation"/><category term="Axes"/><category term="Big Commerce"/><category term="Brochures"/><category term="Browser Resize"/><category term="Button"/><category term="CA"/><category term="CRUD"/><category term="Carousel"/><category term="Category Import"/><category term="Chatbots"/><category term="Coding"/><category term="Compile"/><category term="Computer"/><category term="Computer Engineers"/><category term="Constraint"/><category term="Copy Paste"/><category term="Customer Engagement"/><category term="DLL Hell"/><category term="Data Encapsulation"/><category term="Data Hiding"/><category term="Data Mining"/><category term="Database Administrator"/><category term="Decision Making"/><category term="Deep Learning"/><category term="Design Patter"/><category term="Digital Marketing"/><category term="Digitization"/><category term="Directions API"/><category term="Directive"/><category term="Docs"/><category term="Driver"/><category term="E-Commerce"/><category term="EI"/><category term="Eating Habits"/><category term="Eco Friendly"/><category term="Error 150"/><category term="Expense Management System"/><category term="Express"/><category term="Ext Designer"/><category term="ExtJs Grid Panel HTML controls"/><category term="ExtJs MVC"/><category term="ExtJs Panel"/><category term="ExtJs data store"/><category term="FMCG"/><category term="FTP"/><category term="Fiction"/><category term="Field Services"/><category term="Foods"/><category term="Force.com"/><category term="Foreign Key Primary Key"/><category term="Form Panel"/><category term="Format"/><category term="FrameLayout"/><category term="Funny"/><category term="GAC"/><category term="GIF"/><category term="GetStream"/><category term="GetStream.io"/><category term="Getting Started."/><category term="Google Play Services"/><category term="Google Play."/><category term="Google Rank"/><category term="Grid"/><category term="Grid Layout"/><category term="HR Industry"/><category term="HR Software"/><category term="HTTP"/><category term="HTTPS"/><category term="Height"/><category term="Hiring"/><category term="Home"/><category term="Image Gallery"/><category term="Image Sequences."/><category term="In-app"/><category term="India"/><category term="Inheritance"/><category term="Innovation"/><category term="Installation"/><category term="Instant"/><category term="Inventory"/><category term="JAR"/><category term="JSTree"/><category term="Joining"/><category term="Joomla"/><category term="Knockout JS"/><category term="Language"/><category term="Leaders"/><category term="Location aware apps."/><category term="Lumen"/><category term="MEAN"/><category term="MERN"/><category term="MS SQL"/><category term="MVVM"/><category term="Magento Salesforce"/><category term="Marketing"/><category term="Menu"/><category term="Messaging"/><category term="MongoDB"/><category term="Mouse Events"/><category term="Native Application"/><category term="Navigation"/><category term="Non Fiction"/><category term="OOPS"/><category term="Object Oriented Programming"/><category term="Offline Support"/><category term="Operating System"/><category term="PDF"/><category term="Panel"/><category term="Payment"/><category term="Paypal"/><category term="Payroll"/><category term="Pear"/><category term="Peer"/><category term="Photoshop"/><category term="Pioneers"/><category term="Pivot Table"/><category term="Plist"/><category term="Plugin"/><category term="Polymorphism"/><category term="PrestaShop"/><category term="Project Manager"/><category term="Proxies"/><category term="Query String"/><category term="R&amp;D"/><category term="REST API"/><category term="Ratchet"/><category term="Recording"/><category term="Redis"/><category term="Refactoring"/><category term="Refresh row"/><category term="Remote Staff"/><category term="Research"/><category term="Restaurant"/><category term="Routes"/><category term="RowDetails"/><category term="SEO"/><category term="SFTP"/><category term="SSL"/><category term="Salesforce"/><category term="Scripts"/><category term="Scrollbar"/><category term="Security"/><category term="Serverless"/><category term="Shopping cart"/><category term="Silverlight"/><category term="SlideMenu"/><category term="Smart Devices"/><category term="Socket.io"/><category term="Softwares"/><category term="Sound Quality"/><category term="Splash Screen"/><category term="Sqlite"/><category term="Steve Jobs"/><category term="Stores"/><category term="Story Telling"/><category term="Strong Name"/><category term="Submit"/><category term="Success Story"/><category term="Supply Chain Management"/><category term="Table Pivoting"/><category term="TapHold"/><category term="Task. Alarm."/><category term="Template"/><category term="TensorFlow"/><category term="Testing"/><category term="TomatoCart"/><category term="Touch Charts"/><category term="Translation"/><category term="Tree"/><category term="UnitTest"/><category term="Update"/><category term="Vehicle Tracking"/><category term="Video"/><category term="Vim"/><category term="VirtueMart"/><category term="Wearables"/><category term="WebRTC"/><category term="WebSocket"/><category term="WhatsApp"/><category term="Window Resize"/><category term="Windows"/><category term="Windows 7"/><category term="Wordpress"/><category term="Writing"/><category term="Xco"/><category term="Z-index"/><category term="ZenCart"/><category term="ZeusCart"/><category term="auto suggest text box"/><category term="billing"/><category term="combo box"/><category term="horizontal"/><category term="iPA"/><category term="iTunes"/><category term="kublet"/><category term="multilingual"/><category term="opencart"/><category term="osCommerce"/><category term="osTicket"/><category term="quickfix"/><category term="sortable"/><category term="vertical"/><category term="xampp"/><title type='text'>Hiren&#39;s Technical Blog</title><subtitle type='html'>I am a developer and I know how hard it is to solve difficult issues while programming in case you did not get any help. I have faced this so many times. That&#39;s why I started this blog so that I can share problems and solutions with developer community. In case if you face any issue in programming do check my blog once, it will surely save your time. </subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.hiren.dev/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>336</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-5120016747187113441</id><published>2022-10-02T16:45:00.003+05:30</published><updated>2022-10-02T16:45:35.772+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Express"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="NodeJs"/><category scheme="http://www.blogger.com/atom/ns#" term="XML"/><title type='text'>NodeJs Read XML file and Parse Data</title><content type='html'>&lt;p&gt;Hello,&lt;/p&gt;&lt;p&gt;Few days back I worked on task to read XML file in NodeJs and parse the data and convert data to the JSON format. Here in this blog I am going explain how I did achieved this.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Following is our sample XML file.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;lt;root&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;lt;parent&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;firstchild&amp;gt;First Child Content 1&amp;lt;/firstchild&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;secondchild&amp;gt;Second Child Content 1&amp;lt;/secondchild&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/parent&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;lt;parent&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;firstchild&amp;gt;First Child Content 2&amp;lt;/firstchild&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;secondchild&amp;gt;Second Child Content 2&amp;lt;/secondchild&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/parent&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;lt;/root&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;Step 1 : Install necessary NPM packages&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;First install following packages in your NodeJs application.&lt;/p&gt;&lt;p&gt;npm install --save&amp;nbsp;xmldom&lt;/p&gt;&lt;p&gt;mpm install --save&amp;nbsp;hashmap&lt;/p&gt;&lt;p&gt;Here xmldom is the package we are going to use to parse the XML data and hasmap package we are going to use to convert and save data in JSON format.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;Step 2 : Import necessary packages in script&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;const { readFile } = require(&#39;fs/promises&#39;);&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;const xmldom = require(&#39;xmldom&#39;);&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;const HashMap = require(&#39;hashmap&#39;);&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;We are going to use readFile from fs/promises. Also we will use xmldom to parse the string data. xmldom is a&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;A JavaScript implementation of W3C DOM for Node.js, Rhino and the browser. Fully compatible with W3C DOM level2; and some compatible with level3. Supports DOMParser and XMLSerializer interface such as in browser.&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;b style=&quot;font-size: large;&quot;&gt;Step 3 : Read the XML file&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;const readXMLFile = async()=&amp;gt; {&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;var parser = new xmldom.DOMParser();&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; const result = await readFile(&#39;./data.xml&#39;,&quot;utf8&quot;);&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; const dom = parser.parseFromString(result, &#39;text/xml&#39;);&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Here we are using async function to read the XML file as we want to wait till XML file is completely finished. Also we created a&amp;nbsp;&lt;span style=&quot;font-size: large;&quot;&gt;xmldom.DOMParser which we will use to parse the string data of the file. This parser will give you all the TAGs of the XML file just like we access standard HTML tags. With this we can use&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;getElementsByTagName to get XML tags.&amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b style=&quot;font-size: large;&quot;&gt;Step 4 : Convert XML data to hasmap&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;const readXMLFile = async()=&amp;gt; {&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;var parser = new xmldom.DOMParser();&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;const dataMap = new HashMap();&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; const result = await readFile(&#39;./data.xml&#39;,&quot;utf8&quot;);&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; const dom = parser.parseFromString(result, &#39;text/xml&#39;);&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;var parentList = dom.getElementsByTagName(&quot;&lt;/span&gt;parent&lt;span style=&quot;font-size: medium;&quot;&gt;&quot;);&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;for(var i =0; i &amp;lt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: large;&quot;&gt;parentList&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;.length; i++) {&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;const parent =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: large;&quot;&gt;parentList&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;[i];&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;const firstchild =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: large;&quot;&gt;parent&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;.getElementsByTagName(&quot;&lt;/span&gt;firstchild&lt;span style=&quot;font-size: medium;&quot;&gt;&quot;)[0].textContent;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;const secondchild =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: large;&quot;&gt;parent&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;.getElementsByTagName(&quot;&lt;/span&gt;secondchild&lt;span style=&quot;font-size: medium;&quot;&gt;&quot;)[0].textContent;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;const parentMap = new HashMap();&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: large;&quot;&gt;parentMap&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;.set(&quot;&lt;/span&gt;&lt;span style=&quot;font-size: large;&quot;&gt;firstchild&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&quot;,&lt;/span&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;firstchild&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;);&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: large;&quot;&gt;parentMap&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;.set(&quot;&lt;/span&gt;&lt;span style=&quot;font-size: large;&quot;&gt;secondchild&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&quot;,&lt;/span&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;secondchild&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;);&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;dataMap.set(i,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: large;&quot;&gt;parentMap&lt;/span&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;);&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;}&lt;/span&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;In the above function we got list of parents by&amp;nbsp;getElementsByTagName method and then we are iterating&amp;nbsp;&amp;nbsp;through it and accessing the child tags and getting it&#39;s text content. Then we are simply storing it in hasmap with unique key.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;Hope this helps you.&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/5120016747187113441/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2022/10/nodejs-read-xml-file-and-parse-data.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/5120016747187113441'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/5120016747187113441'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2022/10/nodejs-read-xml-file-and-parse-data.html' title='NodeJs Read XML file and Parse Data'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-3525442227240468629</id><published>2022-07-03T11:25:00.001+05:30</published><updated>2022-07-05T16:08:04.178+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="NodeJs"/><category scheme="http://www.blogger.com/atom/ns#" term="Testing"/><category scheme="http://www.blogger.com/atom/ns#" term="UnitTest"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Development"/><title type='text'>Mock node-fetch with JEST</title><content type='html'>&lt;p&gt;Recently I tried my hands on Jest - the popular JavaScript Testing Library. In my application we were using node-fetch to make API calls. I used Jest to mock and test this API calls. Here in this blog I will explain on how to mock node-fetch with Jest.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Following is my function to call the GET API.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;fetch_get.js&lt;/b&gt;&lt;/p&gt;&lt;p&gt;const fetch = require(&#39;node-fetch&#39;);&lt;/p&gt;&lt;p&gt;module.exports = async () =&amp;gt; {&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; return await fetch(&#39;http://YOUR_GET_URL&#39;).then(res =&amp;gt; res.json());&lt;/p&gt;&lt;p&gt;};&lt;/p&gt;&lt;div&gt;Now to test this create a test file with name &lt;b&gt;test.fetch_get.js&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Step 1: First import the function.&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;const fetch_get = require(&#39;../fetch_get&#39;);&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Step 2 : Mock the node-fetch with Jest&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;const fetch = require(&#39;node-fetch&#39;);&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;jest.mock(&#39;node-fetch&#39;, ()=&amp;gt;jest.fn())&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Step 3: Create Mock response&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;const mockedRes = {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &quot;success&quot;: true,&lt;/div&gt;&lt;div&gt;&amp;nbsp; &quot;data&quot;: [&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; id: 1,&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; text: &#39;Test Data 1&#39;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; },&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; id: 1,&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; text: &#39;Test Data 2&#39;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div&gt;&amp;nbsp; ]&lt;/div&gt;&lt;div&gt;};&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Step 4: Add Test&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;describe(&quot;Test get fetch&quot;, () =&amp;gt; {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; let data;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; it(&#39;It should return the data&#39;, () =&amp;gt; {&lt;/div&gt;&lt;div&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;const response = Promise.resolve({&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ok: true,&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; status: 200,&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; json: () =&amp;gt; {&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return mockedRes;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; },&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; });&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fetch.mockImplementation(()=&amp;gt; response)&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; data = await fetch_get();&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; expect(data).toEqual(mockedRes);&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; });&lt;/div&gt;&lt;div&gt;});&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In above code we have created a rest and mocked the response to return our response when we call .json() method for response. Then we are simply comparing the response. This is a very simple test. Here in stead of comparing data, you may have other tests like checking length of data or checking specific data etc.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Step 5: Run Test&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Run the test with npm test or npm run test and you will see the following result.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;Test get fetch&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; ✓ It should return the data (17 ms)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Test Suites: 1 passed, 1 total&lt;/div&gt;&lt;div&gt;Tests:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 passed, 1 total&lt;/div&gt;&lt;div&gt;Snapshots:&amp;nbsp; &amp;nbsp;0 total&lt;/div&gt;&lt;div&gt;Time:&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.313 s, estimated 1 s&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Hope this helps you.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/3525442227240468629/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2022/07/mock-node-fetch-with-jest.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/3525442227240468629'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/3525442227240468629'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2022/07/mock-node-fetch-with-jest.html' title='Mock node-fetch with JEST'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-6346488118811494455</id><published>2022-01-29T16:32:00.001+05:30</published><updated>2022-01-29T16:33:17.256+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="container"/><category scheme="http://www.blogger.com/atom/ns#" term="Docker"/><category scheme="http://www.blogger.com/atom/ns#" term="kubectl"/><category scheme="http://www.blogger.com/atom/ns#" term="kubernetes"/><title type='text'>How to Execute Shell Script from Dockerfile</title><content type='html'>&lt;p&gt;Recently I faced a problem with Docker build. Before we build the image there was a requirement to cleanup something from MongoDB. For that we tried to create shell script and execute it from Dockerfile before we start the service. Here in this blog I will explain how you can execute the shell script from Dockerfile.&amp;nbsp;&lt;/p&gt;&lt;p&gt;For that first create the shell script in the same context of Dockerfile. That means the file should be in the same folder or subfolder where Dockerfile is there.&amp;nbsp;&lt;/p&gt;&lt;p&gt;We can not access file outside the Docker build context so file has to be in the same folder.&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 21px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;nano test.sh&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 21px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 21px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;span style=&quot;font-family: Times; font-size: medium; font-variant-ligatures: normal;&quot;&gt;You can put your content in this file for the tasks you want to do with this file.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 21px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;span style=&quot;font-family: Times; font-size: medium; font-variant-ligatures: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 21px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;span style=&quot;font-family: Times; font-size: medium; font-variant-ligatures: normal;&quot;&gt;Now first we will copy the file in docker build context. So that it can be executed. This step is mandatory or else it will not find file. Add following lines of code in your Dockerfile.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 21px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;span style=&quot;font-family: Times; font-size: medium; font-variant-ligatures: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 21px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;FROM alpine3.15&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 21px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 21px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;COPY test.sh ./test.sh&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 21px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;Next step we have to change access rights of the script so it can be executed.&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 21px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;RUN chmod +x ./test.sh&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 21px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;Now since we have file in the Docker build context and it has proper access rights we can execute the file.&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 21px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;RUN sh ./test.sh&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 21px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 21px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;That&#39;s it and now when to service starts it will execute the file and do all the actions which you have added in shell script.&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;Hope this helps you.&amp;nbsp;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/6346488118811494455/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2022/01/how-to-execute-shell-script-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/6346488118811494455'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/6346488118811494455'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2022/01/how-to-execute-shell-script-from.html' title='How to Execute Shell Script from Dockerfile'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-9102778756180916034</id><published>2022-01-03T21:44:00.003+05:30</published><updated>2022-01-03T21:44:29.811+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="container"/><category scheme="http://www.blogger.com/atom/ns#" term="Docker"/><category scheme="http://www.blogger.com/atom/ns#" term="kubectl"/><category scheme="http://www.blogger.com/atom/ns#" term="kubernetes"/><category scheme="http://www.blogger.com/atom/ns#" term="kublet"/><title type='text'>Kubernetes ImagePullBackOff error</title><content type='html'>&lt;p&gt;Recently I faced an issue while working&amp;nbsp;Kubernetes cluster. I was trying to build docker image from local repository to test some changes in production before we merge the code. After building the docker image and recreating the container it was showing&amp;nbsp;ImagePullBackOff error when I check the status with&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;kubectl get pods&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;In this blog I am going to mention the possible cause for this error and will explain the resolution which worked for me.&lt;/p&gt;&lt;p&gt;In a Kubernetes, there’s an agent on for node which is called kubelet. This is responsible for running containers in the nodes. For some reason if image can&#39;t be pulled the kublet will throw ImagePullBackOff error.&amp;nbsp;&lt;/p&gt;&lt;p&gt;There are some possible reasons for this when kubectl is not able to pull image from mentioned registry.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Either image or tag is not available.&amp;nbsp;&lt;/p&gt;&lt;p&gt;The name of the image or tag is wrong in deployment yaml file&lt;/p&gt;&lt;p&gt;kubectl does not have access to image registry.&amp;nbsp;&lt;/p&gt;&lt;p&gt;In my case there was no such issues mentioned above. The image with tag was there. I have specified the correct name in deployment yaml file and because it was a local registry, there was no need of authentication.&amp;nbsp;&lt;/p&gt;&lt;p&gt;So here is how I solved this issue. I set image pull policy to following value in my deployment yaml file.&lt;/p&gt;&lt;p&gt;&lt;b&gt;imagePullPolicy: IfNotPresent&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The reason it worked is, the kubectl was trying to find image in registry but it was not present because it was local registry so then it tried to find image in local repository and caches it.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This solution worked for me because I was using local registry. If you are facing such issue try setting above value to imagePullPolicy and it may work. Hope this helps you.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/9102778756180916034/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2022/01/kubernetes-imagepullbackoff-error.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/9102778756180916034'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/9102778756180916034'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2022/01/kubernetes-imagepullbackoff-error.html' title='Kubernetes ImagePullBackOff error'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-4832817456041167415</id><published>2021-07-31T15:14:00.002+05:30</published><updated>2021-07-31T15:14:49.565+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="React"/><category scheme="http://www.blogger.com/atom/ns#" term="React Native"/><category scheme="http://www.blogger.com/atom/ns#" term="ReactJs"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Application"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Development"/><title type='text'>Wait for State Changes with Redux Saga</title><content type='html'>&lt;p&gt;Hello,&lt;/p&gt;&lt;p&gt;As we know Redux saga allows us to respond to actions outside Redux store. It&#39;s kind of middleware library to handle side effects with ease. This side effect could be anything like calling APIs, doing some IO operations or anything. While working with Saga sometime it happens that we also want to detect state changes and do some actions after it. In this blog I am going to explain how you can wait or detect Redux state changes with Saga.&lt;/p&gt;&lt;p&gt;Let&#39;s understand with an example. For example there is an API call to get access token and as soon as you have access toke available in state you want to call some other actions like background sync etc.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;function* waitForLoginToken(selector) {&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; if (yield select(selector)) return;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; while (true) {&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; yield take(&#39;*&#39;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if (yield select(selector)) return;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; }&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;export function* postSignInAction(payload) {&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;cost loginTokenSelector = state =&amp;gt; state.auth.loginToken;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;yield call(waitForLoginToken, loginTokenSelector);&lt;/p&gt;&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;yield put({ type: &#39;BACKGROUND_SYNC&#39; });&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;function* mySaga(){&lt;/p&gt;&lt;p&gt;&amp;nbsp; yield takeEvery(&#39;SIGN_IN&#39;, postSignInAction);&lt;/p&gt;&lt;p&gt;}&lt;br /&gt;&lt;/p&gt;&lt;p&gt;As you can see in above code, we take every sign in action and call postSignInAction which will wait for state change.&lt;/p&gt;&lt;p&gt;We defined state selector as state.auth.loginToken. Till the time loginToken is not set in state.auth it will wait as we are using while loop to wait for state change. Once we get it in state we call next action.&amp;nbsp;&lt;/p&gt;&lt;p&gt;This way you can &amp;amp; detect state change with Redux Saga. Hope this helps you.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/4832817456041167415/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2021/07/wait-for-state-changes-with-redux-saga.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/4832817456041167415'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/4832817456041167415'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2021/07/wait-for-state-changes-with-redux-saga.html' title='Wait for State Changes with Redux Saga'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-467066595072417986</id><published>2021-07-17T16:08:00.003+05:30</published><updated>2021-07-17T16:08:25.476+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="React"/><category scheme="http://www.blogger.com/atom/ns#" term="ReactJs"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Application"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Development"/><title type='text'>React-Draft-Wysiwyg - Find Text Option</title><content type='html'>&lt;p&gt;Hello,&lt;/p&gt;&lt;p&gt;Recently I was working on POC for rich text editor using&amp;nbsp;&lt;a href=&quot;https://github.com/jpuri/react-draft-wysiwyg&quot; target=&quot;_blank&quot;&gt;React-Draft-Wysiwyg&lt;/a&gt; editor.&amp;nbsp;&lt;/p&gt;&lt;p&gt;There we have a requirement to add find &amp;amp; replace dialog box which should find the matching text from all the blocks and height it with background color. For the POC we added find text functionality. Here in this blog I will explain how to do it.&amp;nbsp;&lt;/p&gt;&lt;p&gt;For this I have created separate React component and add it as custom option to editor toolbar. Let&#39;s understand it step by step.&amp;nbsp;&lt;/p&gt;&lt;p&gt;If you want to know how to add custom option you can find reference from here.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://jpuri.github.io/react-draft-wysiwyg/#/docs&quot;&gt;https://jpuri.github.io/react-draft-wysiwyg/#/docs&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;1) Create Modal with Text input and Button&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Please note I have used grommet UI library to build the POC. So text input and button was imported from Grommet.&lt;/p&gt;&lt;p&gt;&amp;lt;TextInput&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; data-cy=&quot;find-text&quot;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; autoFocus&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; onChange={this.onChangeFindText}&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; value={this.state.findText}&lt;/p&gt;&lt;p&gt;/&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;lt;Button&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; id=&quot;find&quot;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; label=&quot;Find&quot;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; onClick={this.onFindClick}&lt;/p&gt;&lt;p&gt;/&amp;gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;2) Handle Find Click Event&lt;/b&gt;&lt;/p&gt;&lt;p&gt;onFindClick = () =&amp;gt; {&lt;/p&gt;&lt;p&gt;&amp;nbsp; const search = this.state.findText;&lt;/p&gt;&lt;p&gt;&amp;nbsp; let contentState = convertToRaw(this.props.editorState.getCurrentContent());&lt;/p&gt;&lt;p&gt;&amp;nbsp; contentState.blocks.forEach(block =&amp;gt; {&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; const text = block.text;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; const matches = [...text.matchAll(search)];&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; if(matches.length &amp;gt; 0) {&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; matches.forEach(match =&amp;gt;{&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; block.inlineStyleRanges.push({length: match[0].length,&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; offset: match.index,&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; style: &quot;bgcolor-rgb(247,218,100)&quot;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; })&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; });&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; }&lt;/p&gt;&lt;p&gt;&amp;nbsp; });&lt;/p&gt;&lt;p&gt;&amp;nbsp; let newEditorState = {&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; editorState: EditorState.createWithContent(convertFromRaw({blocks: contentState.blocks,entityMap: {}})),&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; contentState: null&lt;/p&gt;&lt;p&gt;&amp;nbsp; }&lt;/p&gt;&lt;p&gt;&amp;nbsp; this.props.onChange(EditorState.createWithContent(convertFromRaw({blocks: contentState.blocks,entityMap: {}})));&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;In above code we are getting search text from the state and matching it with texts of all custom blocks. Where ever it matches we are setting inline styles in blocks with yellow color background. and then setting state of editor again with new blocks.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Hope this helps you.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/467066595072417986/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2021/07/react-draft-wysiwyg-find-text-option.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/467066595072417986'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/467066595072417986'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2021/07/react-draft-wysiwyg-find-text-option.html' title='React-Draft-Wysiwyg - Find Text Option'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-1857685877421545733</id><published>2021-07-04T15:55:00.000+05:30</published><updated>2021-07-04T15:55:21.938+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Docker"/><category scheme="http://www.blogger.com/atom/ns#" term="kubernetes"/><category scheme="http://www.blogger.com/atom/ns#" term="MongoDB"/><category scheme="http://www.blogger.com/atom/ns#" term="NodeJs"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Development"/><title type='text'>Docker MongoDB terminates when it runs out of memory</title><content type='html'>&lt;p&gt;When you have multiple services running in docker container it&#39;s quite possible that you have an issues with certain services when your docker container runs out of memory. MongoDB is one such service.&amp;nbsp;&lt;/p&gt;&lt;p&gt;On docker container when you have MongoDB running and when it starts storing huge data it starts consuming lots of memory and that&#39;s where you have an issue. MongoDB will crash after sometime where isn&#39;t much memory left.&amp;nbsp;&lt;/p&gt;&lt;p&gt;The reason behind this is the IO model of MongoDB, it tries to keep as much data as possible in cache so read and write operations are much faster. But this creates an issue with docker as we have limited memory and lots of services are sharing that.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Starting from MongoDB 3.2 on words WiredTiger storage engine is the default one for MongoDB and it&#39;s recommended.&amp;nbsp;&lt;/p&gt;&lt;p&gt;There are various advantages of WiredTiger storage engine. For example,&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Document Level Concurrency&lt;/li&gt;&lt;li&gt;Snapshots and Checkpoints&lt;/li&gt;&lt;li&gt;Journal&lt;/li&gt;&lt;li&gt;Compression&lt;/li&gt;&lt;li&gt;Memory Use&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;One of most useful feature is Memory use.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;With WiredTiger, MongoDB utilizes both the WiredTiger internal cache and the filesystem cache.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;You can control it with&amp;nbsp;&lt;b&gt;--wiredTigerCacheSizeGB&lt;/b&gt; configuration.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;The --wiredTigerCacheSizeGB limits the size of the WiredTiger internal cache. The operating system will use the available free memory for filesystem cache, which allows the compressed MongoDB data files to stay in memory. In addition, the operating system will use any free RAM to buffer file system blocks and file system cache.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;With this setting you can enhance memory usage. MongoDB will not use excessive memory and with heavy data usage on docker container MongoDB will not crash on excessive memory usage.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Hope this helps you.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/1857685877421545733/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2021/07/docker-mongodb-terminates-when-it-runs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/1857685877421545733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/1857685877421545733'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2021/07/docker-mongodb-terminates-when-it-runs.html' title='Docker MongoDB terminates when it runs out of memory'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-7659002702231806170</id><published>2021-07-04T15:15:00.001+05:30</published><updated>2021-07-04T15:15:41.585+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="NodeJs"/><category scheme="http://www.blogger.com/atom/ns#" term="Peer"/><category scheme="http://www.blogger.com/atom/ns#" term="ReactJs"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Development"/><category scheme="http://www.blogger.com/atom/ns#" term="WebRTC"/><title type='text'>ReactJs Peer to Peer Communication</title><content type='html'>&lt;p&gt;Recently I evaluated peer to peer communication approach for one of my project so here I am going to share it and how you can use it in your project in case you want to implement peer to peer communication in your project.&amp;nbsp;&lt;/p&gt;&lt;p&gt;We used library called &lt;a href=&quot;https://peerjs.com/&quot; target=&quot;_blank&quot;&gt;PeerJS&lt;/a&gt;&amp;nbsp;, it&#39;s simple peer to peer built on top of webRTC. For this first you have to create a server, which will act as only connection broker. No peer to peer data goes through this server. Let&#39;s just create a simple server.&lt;/p&gt;&lt;p&gt;Let&#39;s first install peer from npm.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;npm install peer&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Now let&#39;s create NodeJs script.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;const { PeerServer } = require(&#39;peer&#39;);&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;const peerServer = PeerServer({ port: 9000, path: &#39;/server&#39; });&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;peerServer.on(&#39;connection&#39;, (client) =&amp;gt; {&amp;nbsp;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;console.log(client);&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;});&lt;/b&gt;&lt;/p&gt;&lt;p&gt;That&#39;s is now you can run this script through terminal and it will run your server on 9000 port.&lt;/p&gt;&lt;p&gt;Now let&#39;s connect to server from our ReactJS component.&amp;nbsp;&lt;/p&gt;&lt;p&gt;First lets install peerjs npm which is peer client.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;npm install&amp;nbsp;peerjs&lt;/b&gt;&lt;/p&gt;&lt;p&gt;We can connect to server in componentDidMount method and add some callbacks function.&lt;/p&gt;&lt;p&gt;&lt;b&gt;import Peer from &#39;peerjs&#39;;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;componentDidMount = () =&amp;gt; {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.peer = new Peer(&quot;USERNAME&quot;, {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; host: &#39;localhost&#39;,&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; port: 9000,&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; path: &#39;/server&#39;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; });&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;this.peer.on(&quot;error&quot;, err =&amp;gt; {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; console.log(&quot;error: &quot;, err)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; })&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.peer.on(&quot;open&quot;, id =&amp;gt; {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; console.log(id)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; })&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.peer.on(&quot;connection&quot;, (con) =&amp;gt; {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; console.log(&quot;connection opened&quot;);&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; con.on(&quot;data&quot;, i =&amp;gt; {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; console.log(i)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; });&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; })&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;}&lt;/b&gt;&lt;/p&gt;&lt;p&gt;In above code first function is the error callback function. Second once is when peer connection is opened. Third one is when you receive connection from some other peer and get some data.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Now let&#39;s take an example of how you can connect to other peer and send data.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;const conn = this.peer.connect(&#39;REMOTE_PEER&#39;);&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;conn.on(&#39;open&#39;, () =&amp;gt; {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; conn.send(&#39;DATA&#39;);&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;});&lt;/b&gt;&lt;/p&gt;&lt;p&gt;In above code we are connecting to some remote peer and sending some data to it.&lt;/p&gt;&lt;p&gt;Please note here peer to peer data goes through ICE server which you can setup and assign when you create peer server or else it will use PeerCloud server by default. For the development purpose that&#39;s ok but for the production you should create your on TURN or STUN server.&lt;/p&gt;&lt;p&gt;Hope this helps you in setting up&amp;nbsp;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/7659002702231806170/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2021/07/reactjs-peer-to-peer-communication.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/7659002702231806170'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/7659002702231806170'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2021/07/reactjs-peer-to-peer-communication.html' title='ReactJs Peer to Peer Communication'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-335957637193132228</id><published>2021-06-26T18:13:00.001+05:30</published><updated>2021-06-26T18:13:22.915+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ArtificialIntelligence"/><category scheme="http://www.blogger.com/atom/ns#" term="Data Analysis"/><category scheme="http://www.blogger.com/atom/ns#" term="Machine Learning"/><category scheme="http://www.blogger.com/atom/ns#" term="NLP"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="TensorFlow"/><title type='text'>Create Question And Answer NLP Model With Bert</title><content type='html'>&lt;p&gt;Hello,&lt;/p&gt;&lt;p&gt;Recently I worked on POC for chatbot where I evaluated Question Answering with Bert. Here in this blog we will see how you can create Question, Answering with Bert.&lt;/p&gt;&lt;p&gt;&lt;b&gt;What is Bert?&lt;/b&gt;&lt;/p&gt;&lt;p&gt;According to team, who developed Bert&lt;/p&gt;&lt;p&gt;&lt;b&gt;BERT stands for Bidirectional Encoder Representations from Transformers. It is designed to pre-train deep bidirectional representations from unlabelled text by jointly conditioning on both left and right context. As a result, the pre-trained BERT model can be fine-tuned with just one additional output layer to create state-of-the-art models for a wide range of NLP tasks.”&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Bert is pertained on massive dataset and large corpus of unlabelled text. That&#39;s the hidden power of Bert as it uses knowledge gained from pre-training and apply it to dataset given.&amp;nbsp;&lt;/p&gt;&lt;p&gt;For this POC we used HuggingFace&#39;s transformers. So first you have to install transformers. Using this model you can get advantage of pre trained data and then you can pass your reference text to it and this model will try to find answers from it.&lt;/p&gt;&lt;p&gt;&lt;b&gt;pip install transformers&lt;/b&gt;&lt;/p&gt;&lt;p&gt;or&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;pip3 install transformers&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Because this models are very big and it takes time to load and download. Let&#39;s first save it. Create model.py file and add following code.&lt;/p&gt;&lt;p&gt;&lt;b&gt;from transformers import BertForQuestionAnswering&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;from transformers import BertTokenizer&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;BertForQuestionAnswering.from_pretrained(&#39;bert-large-uncased-whole-word-masking-finetuned-squad&#39;).save_pretrained(&#39;./trainedModel&#39;)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;BertTokenizer.from_pretrained(&#39;bert-large-uncased-whole-word-masking-finetuned-squad&#39;).save_pretrained(&#39;./trainedModel&#39;)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Now execute it with python command. It will create trainedModel directory and save model there with all required files. Now we can load this pertained saved model.&lt;/p&gt;&lt;p&gt;&lt;b&gt;from transformers import BertForQuestionAnswering&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;from transformers import BertTokenizer&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;import torch&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;bertPreTrainedModel = BertForQuestionAnswering.from_pretrained(&#39;./trainedModel&#39;)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;tokenizer = BertTokenizer.from_pretrained(&#39;./trainedModel&#39;)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;encoded = tokenizer.encode(&#39;YOUR_QUESTION&#39;, &#39;YOUR_REFERENCE_TEXT&#39;)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;tokens = tokenizer.convert_ids_to_tokens(encoded)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;sepLocation = encoded.index(tokenizer.sep_token_id)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;first_seg_len, second_seg_len = sepLocation + 1, len(encoded) - (sepLocation + 1)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;seg_embedding = [0] * first_seg_len + [1] * second_seg_len&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;modelScores = bertPreTrainedModel(torch.tensor([encoded]), token_type_ids=torch.tensor([seg_embedding]))&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;ans_start_loc, ans_end_loc = torch.argmax(modelScores[0]), torch.argmax(modelScores[len(modelScores)-1])&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;result = &#39; &#39;.join(tokens[ans_start_loc:ans_end_loc + 1])&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;result = result.replace(&#39; ##&#39;, &#39;&#39;)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Here you will get your answer in result. This way you can develop your model using BERT and transformers.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/335957637193132228/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2021/06/create-question-and-answer-nlp-model.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/335957637193132228'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/335957637193132228'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2021/06/create-question-and-answer-nlp-model.html' title='Create Question And Answer NLP Model With Bert'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-7840538758089910482</id><published>2021-06-26T17:33:00.003+05:30</published><updated>2021-06-26T17:33:31.807+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CSS"/><category scheme="http://www.blogger.com/atom/ns#" term="CSS3"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="React"/><category scheme="http://www.blogger.com/atom/ns#" term="ReactJs"/><category scheme="http://www.blogger.com/atom/ns#" term="UI/UX"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Development"/><title type='text'>How to Create Custom Theme for UI using Grommet V2</title><content type='html'>&lt;p&gt;&amp;nbsp;Hello,&lt;/p&gt;&lt;p&gt;In this blog we will understand how you can create custom theme for your using Grommet V2 in your React app.&lt;/p&gt;&lt;p&gt;Using Grommet v2, you can leverage the theme capabilities and define a customTheme as a JS object with your desired colors, margin padding etc. Let&#39;s see how we can do this.&amp;nbsp;&lt;/p&gt;&lt;p&gt;First define your custom theme as JS object. As you can see we have defined some existing grommet color like background, brand. Also we have defined our own color like custom-1, custom-2 etc and then used it in button.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;const customTheme = {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; global: {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; colors: {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; background: &quot;#fff&quot;,&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; brand: &quot;#000&quot;,&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;custom-1&quot;: &quot;#aaaaaa&quot;,&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;custom-2&quot;: &quot;#bbbbbb&quot;,&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;custom-3&quot;: &quot;#444444&quot;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; },&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; button: {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; default: {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; background: &quot;brand&quot;,&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; color: &quot;white&quot;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; },&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; primary: {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; background: &quot;custom-1&quot;,&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; color: &quot;white&quot;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; },&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; secondary: {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; background: &quot;custom-3&quot;,&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; color: &quot;dark-2&quot;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; }&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;}&lt;/b&gt;&lt;/p&gt;&lt;p&gt;For more information on theme customisation and JSON structure you can visit &lt;a href=&quot;https://v2.grommet.io/grommet&quot; target=&quot;_blank&quot;&gt;Official Grommet site&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Now you can apply this theme to your application as below.&lt;/p&gt;&lt;p&gt;&lt;b&gt;import { Grommet, Box } from &#39;grommet&#39;;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;const DemoGrommet = () =&amp;gt; (&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;lt;Grommet theme={customTheme}&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;Box background=&quot;custom-1&quot; &amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;/Box&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;lt;/Grommet&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;);&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;export default DemoGrommet;&lt;/b&gt;&lt;/p&gt;&lt;div&gt;In case you want to keep default values of Grommet theme and want to override only few things with your theme, you can use deepMerge function provided by grommet v2 utils.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;import { deepMerge } from &#39;grommet/utils&#39;;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;import { generate } from &#39;grommet/themes/base&#39;;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;const mergedTheme = deepMerge(generate(16),&amp;nbsp;&lt;/b&gt;&lt;b&gt;customTheme&lt;/b&gt;&lt;b&gt;);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Here generate function generates default theme with 16 pixel font size and then it merge it with your custom theme and provide you updated theme.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/7840538758089910482/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2021/06/how-to-create-custom-theme-for-ui-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/7840538758089910482'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/7840538758089910482'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2021/06/how-to-create-custom-theme-for-ui-using.html' title='How to Create Custom Theme for UI using Grommet V2'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-5949908319695761048</id><published>2021-06-26T16:32:00.000+05:30</published><updated>2021-06-26T16:32:11.881+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CSS3"/><category scheme="http://www.blogger.com/atom/ns#" term="HTML5"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="Mobile Website"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Application"/><title type='text'>How to Get Video Thumbnails with Javascript</title><content type='html'>&lt;p&gt;Hello,&lt;/p&gt;&lt;p&gt;In this blog we will see how you can generate thumbnail of video using JavaScript.&amp;nbsp; Let&#39;s assume you have file upload in your HTML as following.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;lt;input type=&quot;file&quot; id=&quot;uploadVideo&quot; accept=&quot;video/mp4&quot; /&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Now let&#39;s add an onChange listener for this.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;document.querySelector(&quot;#uploadVideo&quot;).addEventListener(&#39;change&#39;, function() {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; var inputFile =&amp;nbsp;&lt;/span&gt;document.querySelector(&quot;#&lt;/b&gt;&lt;b&gt;uploadVideo&lt;/b&gt;&lt;b&gt;&quot;).files[0];&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;b&gt;getVideoThumbnail(inputFile)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;});&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Now when you upload video it will call this function and you can access this video by using files property. Now we got the file. First step we will do is get blob URL of video so we can access metadata of video. Check below function.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here first what we are doing is creating video element and assigning blob URL to it from input file using URL.createObjectURL method.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Then we have added event listener for meta data. This is necessary as we can&#39;t get video data till them time meta data is loaded.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Then we seek video to 0.0 second. You can add your own time here in case if you need. Then we have added seeked listener. By this time we have video data is available. Now we are using canvas to drawImage from video frame data.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Then using toDataURL method we get the base64Data. Here 0.60 is value of quality. If you don&#39;t want to compromise quality of image then you can pass 1 here.&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;function getVideoThumbnail(&lt;/b&gt;&lt;b&gt;inputFile&lt;/b&gt;&lt;b&gt;) {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; try {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; let video = document.createElement(&#39;video&#39;);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; let blobSrc = URL.createObjectURL(&lt;/b&gt;&lt;b&gt;inputFile&lt;/b&gt;&lt;b&gt;);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; video.setAttribute(&#39;src&#39;, blobSrc);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; video.addEventListener(&#39;error&#39;, () =&amp;gt; {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; console.log(&quot;Error&quot;)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; });&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; video.addEventListener(&#39;loadedmetadata&#39;, () =&amp;gt; {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; setTimeout(() =&amp;gt; {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; video.currentTime = 0.0;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }, 200);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; video.addEventListener(&#39;seeked&#39;, () =&amp;gt; {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; let canvas = document.createElement(&#39;canvas&#39;);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; video.pause();&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; canvas.width = 400&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; canvas.height = 400;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; let ctx = canvas.getContext(&#39;2d&#39;);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ctx.drawImage(video, 0, 0, canvas.width, canvas.height);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var base64Data = ctx.canvas.toDataURL(&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;image/png&#39;,&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.60&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; );&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; // SET this data in SRC of image tag or you can add your own logic.&lt;/span&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; });&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; });&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&amp;nbsp;video.load();&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; } catch (err) {&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;}&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Hope this helps you.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/5949908319695761048/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2021/06/how-to-get-video-thumbnails-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/5949908319695761048'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/5949908319695761048'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2021/06/how-to-get-video-thumbnails-with.html' title='How to Get Video Thumbnails with Javascript'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-1154396626072300233</id><published>2021-03-19T18:29:00.004+05:30</published><updated>2021-03-19T18:29:53.063+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Apache"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP Framework"/><category scheme="http://www.blogger.com/atom/ns#" term="Server Admin"/><category scheme="http://www.blogger.com/atom/ns#" term="Ubuntu"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Development"/><title type='text'>How to solve proxy_fcgi:error AH01071: Got error &#39;Unable to open primary script</title><content type='html'>&lt;p&gt;&amp;nbsp;Hello,&lt;/p&gt;&lt;p&gt;Recently I got stuck with strange bug on centOS server. After I updated document root for my primary domain which has Laravel App installed.&amp;nbsp;&lt;/p&gt;&lt;p&gt;When we try to access app through domain, we got following error.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;No input file specified.&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;I initially thought it&#39;s the permission issue on .htaccess issue. Tried changing permissions and adding some rewrite rules but it didn&#39;t work. When I checked apache error logs. I got following error.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;proxy_fcgi:error AH01071: Got error &#39;Unable to open primary script&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;I had no idea how to solve this error. So tried few things like&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Restart apache&lt;/li&gt;&lt;li&gt;Restart php-fpm&lt;/li&gt;&lt;li&gt;Restart VPS&lt;/li&gt;&lt;li&gt;Removed and added account few times.&lt;/li&gt;&lt;li&gt;Disabling php-fpm&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;But nothing worked. I spent almost entire night in solving this issue but no luck. But finally I was able to solve the issue by following steps. It was actually the issue with php fpm, as it was not able to find out root folder for the domain. So here is what you have to do.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;First go to userdata directory&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;/var/cpanel/userdata/&amp;lt;USERNAME&amp;gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here you will find one file.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;yourdomain.com.php-fpm.yaml&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Open this file with nano or vim editor and add following line at the end of it.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;php_admin_value_doc_root: { name: &#39;php_admin_value[doc_root]&#39;, value: /home/&amp;lt;USERNAME&amp;gt;/public_html/&amp;lt;DOCUMENT_ROOT&amp;gt; }&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Save the file and then execute following commands one by one.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;/scripts/php_fpm_config --rebuild&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;/scripts/restartsrv_apache_php_fpm&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;/scripts/restartsrv_httpd&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This will rebuild php fpm config and restart php fpm service for apache. Now in the same folder open&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;YOURDOMAIN.com&amp;nbsp;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;YOURDOMAIN.com_SSL&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Change document root here as well and run following commands.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;/scripts/rebuildhttpdconf&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;/scripts/restartsrv_httpd&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This will rebuild apache config file and restart apache.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This is it and now if you visit your domain, you will not have the issue of file missing.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Hope this saves your time&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/1154396626072300233/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2021/03/how-to-solve-proxyfcgierror-ah01071-got.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/1154396626072300233'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/1154396626072300233'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2021/03/how-to-solve-proxyfcgierror-ah01071-got.html' title='How to solve proxy_fcgi:error AH01071: Got error &#39;Unable to open primary script'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-1097793130146183227</id><published>2020-12-09T17:48:00.004+05:30</published><updated>2020-12-09T17:48:41.960+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Database"/><category scheme="http://www.blogger.com/atom/ns#" term="Database Administrator"/><category scheme="http://www.blogger.com/atom/ns#" term="MySql"/><category scheme="http://www.blogger.com/atom/ns#" term="PhpMyAdmin"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><title type='text'>Restore MySql Database From Just frm and idb File</title><content type='html'>&lt;p&gt;Hello,&lt;/p&gt;&lt;p&gt;Few days back, I encountered a situation where we needed to restore MySql Database but we only had frm and idb file. Didn&#39;t have .sql file or log file from MySql server which is very much needed when you want to restore. So here in this blog I am going to explain how you can still restore MySql Database from only frm and idb file.&lt;/p&gt;&lt;p&gt;First you will need a tool called&amp;nbsp;dbsake which you can install with following command.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-family: Menlo; font-size: 36px; font-variant-ligatures: no-common-ligatures;&quot;&gt;curl -s http://get.dbsake.net &amp;gt; dbsake&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Once installed, run following command to check if it&#39;s installed properly or not.&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;chmod u+x dbsake&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;./dbsake --version&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;span style=&quot;font-family: Times; font-size: medium; font-variant-ligatures: normal;&quot;&gt;If it shows version and all, it&#39;s installed. Now first by using this tool we will get schema of table from frm file. Run following command.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;span style=&quot;font-family: Times; font-size: medium; font-variant-ligatures: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;./dbsake frmdump /PATH_TO_FRM/file.frm&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: Times; font-size: medium;&quot;&gt;It will give you create table schema like this.&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span style=&quot;font-family: Times; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;CREATE TABLE `table_name` (&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;&amp;nbsp; `column1` int(11) NOT NULL AUTO_INCREMENT,&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;&amp;nbsp; `column2` varchar(255) DEFAULT NULL,&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;&amp;nbsp; `column3` varchar(255) DEFAULT NULL,&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;&amp;nbsp; PRIMARY KEY (`column1`)&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;) ENGINE=InnoDB DEFAULT CHARSET=utf8;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;Copy it and run it in your sql editor. If you are migrating it from MySql 5 to 6 you may want to add ROW_FORMAT&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;CREATE TABLE `table_name` (&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;&amp;nbsp; `column1` int(11) NOT NULL AUTO_INCREMENT,&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;&amp;nbsp; `column2` varchar(255) DEFAULT NULL,&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;&amp;nbsp; `column3` varchar(255) DEFAULT NULL,&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;&amp;nbsp; PRIMARY KEY (`column1`)&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=compact;&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;Now it will create table. It&#39;s time to load data into it.&amp;nbsp;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;First we will delete the table space which is idb file created. Run following command.&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;ALTER TABLE table_name DISCARD TABLESPACE&lt;/b&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;Now copy the old idb file and replace the existing one in your MySql server.&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;Now attach table space again.&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;ALTER TABLE table_name IMPORT TABLESPACE&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;That&#39;s it and now if you browse the data in table, you can see all your old rows.&amp;nbsp;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/1097793130146183227/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2020/12/restore-mysql-database-from-just-frm.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/1097793130146183227'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/1097793130146183227'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2020/12/restore-mysql-database-from-just-frm.html' title='Restore MySql Database From Just frm and idb File'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-6744890510981078951</id><published>2020-09-29T11:17:00.002+05:30</published><updated>2021-02-13T16:13:05.244+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="MAMP"/><category scheme="http://www.blogger.com/atom/ns#" term="MySql"/><category scheme="http://www.blogger.com/atom/ns#" term="PhpMyAdmin"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><title type='text'>MySql Export / Import Large Database</title><content type='html'>&lt;p&gt;Hello,&lt;/p&gt;&lt;p&gt;In this blog I am going to explain a trick which I recently used for Export / Import large database.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Let me first explain the issue I faced. The database was over 250 MB. I was using MySql WorkBench to export in single self contained file. But it was breaking in between as some tables were really huge.&amp;nbsp;&lt;/p&gt;&lt;p&gt;So here is what I did. First in MySql WorkBench, in stead of exporting it to self contained single file, export it to Dump project folder. Here it will create sql file for each table in the folder. So in my case it created approximately 180 sql files.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Now open terminal and go to that folder. First step here is we will concat all those files and make a single file.&lt;/p&gt;&lt;p&gt;Run the following command in terminal from folder where you have all the sql files.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;cat *.sql&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp; &lt;/span&gt;&amp;gt; .single_file.sql&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;span style=&quot;font-family: Times; font-size: medium; font-variant-ligatures: normal;&quot;&gt;Above command will concat all the files into one file and create that file in same folder. Now we will use this file to import into our database.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;span style=&quot;font-family: Times; font-size: medium; font-variant-ligatures: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;/Applications/MAMP/Library/bin/mysql -u DB_USER -p DB &amp;lt; .single_file.sql&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: Menlo; font-size: 36px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;span class=&quot;s1&quot; style=&quot;font-variant-ligatures: no-common-ligatures;&quot;&gt;&lt;span style=&quot;font-family: Times; font-size: medium; font-variant-ligatures: normal;&quot;&gt;That&#39;s it. With this trick you can Import / Export large database. Please note that, for this you should have terminal access to your MySql server.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/6744890510981078951/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2020/09/mysql-export-import-large-database.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/6744890510981078951'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/6744890510981078951'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2020/09/mysql-export-import-large-database.html' title='MySql Export / Import Large Database'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-2510506803143641313</id><published>2020-09-07T11:41:00.002+05:30</published><updated>2020-09-07T11:41:40.816+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Android"/><category scheme="http://www.blogger.com/atom/ns#" term="Android App"/><category scheme="http://www.blogger.com/atom/ns#" term="Android Application"/><category scheme="http://www.blogger.com/atom/ns#" term="Android SDK"/><category scheme="http://www.blogger.com/atom/ns#" term="Socket"/><category scheme="http://www.blogger.com/atom/ns#" term="WebSocket"/><title type='text'>Connect to Web Socket From Your Android App using OkHttp</title><content type='html'>&lt;p&gt;Hello,&lt;/p&gt;&lt;p&gt;In this blog I am going to explain how you can connect with Web Socket from your Android App using OkHttp. This will be useful when you want to send some data real time from your Android app to Web app.&amp;nbsp;&lt;/p&gt;&lt;p&gt;First add following line in your build.gradle file dependencies.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;implementation &#39;com.squareup.okhttp3:okhttp:3.11.0&#39;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Now let the gradle build and sync. Next we will make a class which extends&amp;nbsp;WebSocketListener from OkHttp3 and a new class and name it MyWebSocketListener.java and add following code to it.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;import okhttp3.Response;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;import okhttp3.WebSocket;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;import okhttp3.WebSocketListener;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;import okio.ByteString;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;public final class MyWebSocketListener extends WebSocketListener {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; private static final int NORMAL_CLOSURE_STATUS = 5000;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; public MyWebSocketListener() {&amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; @Override&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; public void onOpen(WebSocket webSocket, Response response) {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; webSocket.close(NORMAL_CLOSURE_STATUS, &quot;Exit&quot;);&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; @Override&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; public void onMessage(WebSocket webSocket, String text) {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //String Meesage received&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; @Override&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; public void onMessage(WebSocket webSocket, ByteString bytes) {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Meesage received in form of binary data&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; @Override&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; public void onClosing(WebSocket webSocket, int code, String reason) {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; webSocket.close(NORMAL_CLOSURE_STATUS, null);&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Closing socket&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; @Override&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; public void onFailure(WebSocket webSocket, Throwable t, Response response) {&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; t.printStackTrace();&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; }&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;}&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Now we have listener created. Let&#39;s create client and attach it to Web Socket and Listener.&lt;/p&gt;&lt;p&gt;&lt;b&gt;val listener =&amp;nbsp;MyWebSocketListener()&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;val webSocket =&amp;nbsp; &amp;nbsp;OkHttpClient.Builder().build().newWebSocket(request, listener)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;That&#39;s it, now you can use this instance to send or receive message.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/2510506803143641313/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2020/09/connect-to-web-socket-from-your-android.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/2510506803143641313'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/2510506803143641313'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2020/09/connect-to-web-socket-from-your-android.html' title='Connect to Web Socket From Your Android App using OkHttp'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-4311390403293044766</id><published>2020-09-05T12:55:00.002+05:30</published><updated>2020-09-05T12:55:16.917+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><category scheme="http://www.blogger.com/atom/ns#" term="Ratchet"/><category scheme="http://www.blogger.com/atom/ns#" term="Socket"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Development"/><title type='text'>Create Secure Web Socket (WSS) with Ratchet PHP </title><content type='html'>&lt;p&gt;Hello,&lt;/p&gt;&lt;p&gt;Recently I was working on PHP project where we I was create secure web socket which is accessible with wss:// protocol. For this I struggled for couple of hours so here in blog I am going to explain how to do that so it can save your time.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Earlier version was not supporting WSS but later it introduced React socket server which allows SSL connection. So here are steps you need to follow.&amp;nbsp;&lt;/p&gt;&lt;p&gt;First add all the required classed in your php file.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;use Ratchet\Server\IoServer;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;use Ratchet\Http\HttpServer;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;use Ratchet\WebSocket\WsServer;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;use MyApp\Socket;&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In above example Socket is my class file which has all listeners. After this add auto load file.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;require dirname( __FILE__ ) . &#39;/vendor/autoload.php&#39;;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Next we will create our socket app.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;$app = new \Ratchet\Http\HttpServer(&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; new \Ratchet\WebSocket\WsServer(&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; new \MyApp\Socket()&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; )&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;);&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Now next step is to create React Secure server.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;$loop = \React\EventLoop\Factory::create();&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;$webSock = new \React\Socket\Server(&#39;0.0.0.0:8080&#39;, $loop);&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;We are using 0.0.0.0&amp;nbsp; so this socket can be connected from anywhere.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now lets create secure server by adding path to certificate and key&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;$webSock = new \React\Socket\SecureServer($webSock, $loop, [&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&#39;local_cert&#39; =&amp;gt; &#39;CRT_PATH&#39;,&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&#39;local_pk&#39;=&amp;gt; &#39;KEY_PATH&#39;,&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&#39;allow_self_signed&#39; =&amp;gt; true,&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&#39;verify_peer&#39; =&amp;gt; false&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;]);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Now finally we will run our server.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;$webSock = new \Ratchet\Server\IoServer($app, $webSock, $loop);&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;$webSock-&amp;gt;run();&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;That&#39;s it. It will start your server to which you can connect with WSS protocol. To test you can use WebSocket ECHO test.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href=&quot;https://www.websocket.org/echo.html&quot;&gt;https://www.websocket.org/echo.html&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Hope this helps you.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/4311390403293044766/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2020/09/create-secure-web-socket-wss-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/4311390403293044766'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/4311390403293044766'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2020/09/create-secure-web-socket-wss-with.html' title='Create Secure Web Socket (WSS) with Ratchet PHP '/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-76004663673923913</id><published>2020-08-20T16:04:00.001+05:30</published><updated>2020-08-20T16:04:07.450+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Laravel"/><category scheme="http://www.blogger.com/atom/ns#" term="Laravel 5.2"/><category scheme="http://www.blogger.com/atom/ns#" term="Laravel 5.4"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP Framework"/><title type='text'>AWS PHP SDK - Create an Entry in Route53 - Laravel</title><content type='html'>&lt;p&gt;&amp;nbsp;Hello,&lt;/p&gt;&lt;p&gt;In this blog I will explain you how to you can create an entry in Route53 hosted zone using AWS PHP SDK. Solution I mentioned here is particularly for Laravel app, but you can still use it in any of the PHP project.&amp;nbsp;&lt;/p&gt;&lt;p&gt;This solution is pretty much useful when you want to make a dynamic entry in your hosted. For example a dynamic sub domain creation.&amp;nbsp;&lt;/p&gt;&lt;p&gt;First of all your need install couple of packages using composer. Following are the packages.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&quot;aws/aws-sdk-php&quot;: &quot;^3.148&quot;,&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&quot;aws/aws-sdk-php-laravel&quot;: &quot;~3.0&quot;,&lt;/b&gt;&lt;/p&gt;&lt;p&gt;You can either install it by adding it in composer.json file or you can install it using composer require.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Once the installation is done, follow the steps mentioned in below URL.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: x-large;&quot;&gt;&lt;a href=&quot;https://github.com/aws/aws-sdk-php-laravel&quot;&gt;https://github.com/aws/aws-sdk-php-laravel&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Once installation is done. You need to add following keys in your env file.&lt;/p&gt;&lt;p&gt;AWS_ACCESS_KEY_ID&lt;/p&gt;&lt;p&gt;AWS_SECRET_ACCESS_KEY&lt;/p&gt;&lt;p&gt;AWS_REGION (default = us-east-1)&lt;/p&gt;&lt;p&gt;Set the values in above keys from your AWS account. That&#39;s it your AWS SDK is ready. Now add following line your controller where you want to have logic for adding value in Route53&lt;/p&gt;&lt;p&gt;use Aws\Route53\Route53Client;&lt;/p&gt;&lt;p&gt;use Aws\Common\Credentials\Credentials;&lt;/p&gt;&lt;p&gt;Now next step is to create a client&lt;/p&gt;&lt;p&gt;$client = Route53Client::factory(array(&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;credentials&#39; =&amp;gt; config(&#39;aws.credentials&#39;),&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;region&#39; =&amp;gt; config(&#39;aws.region&#39;),&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;version&#39; =&amp;gt; config(&#39;aws.version&#39;),&lt;/p&gt;&lt;p&gt;));&amp;nbsp;&lt;/p&gt;&lt;p&gt;After client is created we will use&amp;nbsp;changeResourceRecordSets to create an entry.&lt;/p&gt;&lt;p&gt;$result = $client-&amp;gt;changeResourceRecordSets(array(&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // HostedZoneId is required&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;HostedZoneId&#39; =&amp;gt; &#39;YOUR_HOSTED_ZONE_ID&#39;,&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // ChangeBatch is required&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;ChangeBatch&#39; =&amp;gt; array(&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;Comment&#39; =&amp;gt; &#39;string&#39;,&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Changes is required&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;Changes&#39; =&amp;gt; array(&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; array(&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Action is required&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;Action&#39; =&amp;gt; &#39;CREATE&#39;,&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // ResourceRecordSet is required&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;ResourceRecordSet&#39; =&amp;gt; array(&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Name is required&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;Name&#39; =&amp;gt; &#39;YOUR_VALUE&#39;,&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Type is required&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;Type&#39; =&amp;gt; &#39;CNAME&#39;, //A, CANME&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;TTL&#39; =&amp;gt; 600,&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;ResourceRecords&#39; =&amp;gt; array(&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; array(&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Value is required&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;Value&#39; =&amp;gt; &#39;YOUR_VALUE&#39;, //IP address or load balancer.&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ),&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ),&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ),&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ),&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ),&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ),&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ));&lt;/p&gt;&lt;div&gt;That&#39;s it and it will create an entry in Route53 hosted zone.&amp;nbsp;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/76004663673923913/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2020/08/aws-php-sdk-create-entry-in-route53.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/76004663673923913'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/76004663673923913'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2020/08/aws-php-sdk-create-entry-in-route53.html' title='AWS PHP SDK - Create an Entry in Route53 - Laravel'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-7202062603290500057</id><published>2020-08-04T15:45:00.005+05:30</published><updated>2020-08-04T15:45:59.774+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Android"/><category scheme="http://www.blogger.com/atom/ns#" term="Android App"/><category scheme="http://www.blogger.com/atom/ns#" term="Android Application"/><category scheme="http://www.blogger.com/atom/ns#" term="Android SDK"/><category scheme="http://www.blogger.com/atom/ns#" term="FireBase"/><title type='text'>Android Build Error - The Crashlytics build ID is missing</title><content type='html'>Hello,&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Recently I faced a very strange issue in one of my android app. We were using Fabric IO for crash analytics earlier in the app and since now it&#39;s already merged with Firebase Analytics. we need to update the app.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I removed Firebase maven repository and removed all plugins from build gradle file and removed Fabric code from everywhere. And build was successful. After that I followed all the instructions on getting started page of Firebase and crash analytics and build was successful.&amp;nbsp; And then problem started. Once we run the app, it crashes and shows following error in Logcat.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&quot;&lt;b&gt;The Crashlytics build ID is missing. This occurs when Crashlytics tooling is absent from your app&#39;s build configuration. Please review Crashlytics onboarding instructions and ensure you have a valid Crashlytics account&lt;/b&gt;&quot;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now it seems there is an issue with Firebase crash analytics account so I regenerated the google service json file add updated in project. But it didn&#39;t help.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Searched on Google, answers suggest to put back Fabric plugin again in gradle file. Which does not make any sense to me. Since Fabric is out dated, why do we need to add it again.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Finally after 2 days I was able to solve the problem. Here is the solution&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class=&quot;css-1dbjc4n r-a1ub67&quot; style=&quot;-webkit-box-align: stretch; -webkit-box-direction: normal; -webkit-box-orient: vertical; align-items: stretch; background-color: white; border: 0px solid black; box-sizing: border-box; display: flex; flex-basis: auto; flex-direction: column; flex-shrink: 0; margin: 11px 0px 0px; min-height: 0px; min-width: 0px; padding: 0px; position: relative; z-index: 0;&quot;&gt;&lt;div class=&quot;css-901oao r-hkyrab r-1qd0xha r-1x35g6 r-16dba41 r-ad9z0x r-bcqeeo r-bnwqim r-qvutc0&quot; dir=&quot;auto&quot; lang=&quot;en&quot; style=&quot;border: 0px solid black; box-sizing: border-box; color: #14171a; display: inline; font-family: system-ui, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, Ubuntu, &amp;quot;Helvetica Neue&amp;quot;, sans-serif; font-size: 24px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: 1.3125; margin: 0px; min-width: 0px; overflow-wrap: break-word; padding: 0px; position: relative; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;css-901oao css-16my406 r-1qd0xha r-ad9z0x r-bcqeeo r-qvutc0&quot; style=&quot;border: 0px solid black; box-sizing: border-box; color: inherit; display: inline; font-family: system-ui, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, Ubuntu, &amp;quot;Helvetica Neue&amp;quot;, sans-serif; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: 1.3125; margin: 0px; min-width: 0px; overflow-wrap: break-word; padding: 0px; white-space: inherit;&quot;&gt;Remove google service json file. Use Firebase assistant and connect with your account again. Select the project and it again generate google service json file. Keep link to fabric io repository in top level gradle file.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;css-901oao r-hkyrab r-1qd0xha r-1x35g6 r-16dba41 r-ad9z0x r-bcqeeo r-bnwqim r-qvutc0&quot; dir=&quot;auto&quot; lang=&quot;en&quot; style=&quot;border: 0px solid black; box-sizing: border-box; color: #14171a; display: inline; font-family: system-ui, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, Ubuntu, &amp;quot;Helvetica Neue&amp;quot;, sans-serif; font-size: 24px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: 1.3125; margin: 0px; min-width: 0px; overflow-wrap: break-word; padding: 0px; position: relative; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;css-901oao css-16my406 r-1qd0xha r-ad9z0x r-bcqeeo r-qvutc0&quot; style=&quot;border: 0px solid black; box-sizing: border-box; color: inherit; display: inline; font-family: system-ui, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, Ubuntu, &amp;quot;Helvetica Neue&amp;quot;, sans-serif; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: 1.3125; margin: 0px; min-width: 0px; overflow-wrap: break-word; padding: 0px; white-space: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;css-901oao r-hkyrab r-1qd0xha r-1x35g6 r-16dba41 r-ad9z0x r-bcqeeo r-bnwqim r-qvutc0&quot; dir=&quot;auto&quot; lang=&quot;en&quot; style=&quot;border: 0px solid black; box-sizing: border-box; display: inline; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: 1.3125; margin: 0px; min-width: 0px; overflow-wrap: break-word; padding: 0px; position: relative;&quot;&gt;&lt;span class=&quot;css-901oao css-16my406 r-1qd0xha r-ad9z0x r-bcqeeo r-qvutc0&quot; style=&quot;border: 0px solid black; box-sizing: border-box; display: inline; font-size: 24px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: 1.3125; margin: 0px; min-width: 0px; overflow-wrap: break-word; padding: 0px; white-space: pre-wrap;&quot;&gt;&lt;font color=&quot;#14171a&quot; face=&quot;system-ui, -apple-system, system-ui, Segoe UI, Roboto, Ubuntu, Helvetica Neue, sans-serif&quot;&gt;maven {
            url &#39;https://maven.fabric.io/public&#39;
}&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;css-901oao r-hkyrab r-1qd0xha r-1x35g6 r-16dba41 r-ad9z0x r-bcqeeo r-bnwqim r-qvutc0&quot; dir=&quot;auto&quot; lang=&quot;en&quot; style=&quot;border: 0px solid black; box-sizing: border-box; display: inline; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: 1.3125; margin: 0px; min-width: 0px; overflow-wrap: break-word; padding: 0px; position: relative;&quot;&gt;&lt;span class=&quot;css-901oao css-16my406 r-1qd0xha r-ad9z0x r-bcqeeo r-qvutc0&quot; style=&quot;border: 0px solid black; box-sizing: border-box; display: inline; font-size: 24px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: 1.3125; margin: 0px; min-width: 0px; overflow-wrap: break-word; padding: 0px; white-space: pre-wrap;&quot;&gt;&lt;font color=&quot;#14171a&quot; face=&quot;system-ui, -apple-system, system-ui, Segoe UI, Roboto, Ubuntu, Helvetica Neue, sans-serif&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;css-901oao css-16my406 r-1qd0xha r-ad9z0x r-bcqeeo r-qvutc0&quot; style=&quot;border: 0px solid black; box-sizing: border-box; color: inherit; display: inline; font-family: system-ui, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, Ubuntu, &amp;quot;Helvetica Neue&amp;quot;, sans-serif; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: 1.3125; margin: 0px; min-width: 0px; overflow-wrap: break-word; padding: 0px; white-space: inherit;&quot;&gt;&lt;span style=&quot;font-family: Times; font-size: medium;&quot;&gt;I don&#39;t know how it worked but it works and I really don&#39;t know the reason of why it didn&#39;t work and why it started working after above solution. But it does solve the problem.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;css-901oao css-16my406 r-1qd0xha r-ad9z0x r-bcqeeo r-qvutc0&quot; style=&quot;border: 0px solid black; box-sizing: border-box; color: inherit; display: inline; font-family: system-ui, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, Ubuntu, &amp;quot;Helvetica Neue&amp;quot;, sans-serif; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: 1.3125; margin: 0px; min-width: 0px; overflow-wrap: break-word; padding: 0px; white-space: inherit;&quot;&gt;&lt;span style=&quot;font-family: Times; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;css-901oao css-16my406 r-1qd0xha r-ad9z0x r-bcqeeo r-qvutc0&quot; style=&quot;border: 0px solid black; box-sizing: border-box; color: inherit; display: inline; font-family: system-ui, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, Ubuntu, &amp;quot;Helvetica Neue&amp;quot;, sans-serif; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: 1.3125; margin: 0px; min-width: 0px; overflow-wrap: break-word; padding: 0px; white-space: inherit;&quot;&gt;&lt;span style=&quot;font-family: Times; font-size: medium;&quot;&gt;If anyone who is reading this blog, knows the reason please put in comment.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;css-1dbjc4n r-1r5su4o&quot; style=&quot;-webkit-box-align: stretch; -webkit-box-direction: normal; -webkit-box-orient: vertical; align-items: stretch; background-color: white; border: 0px solid black; box-sizing: border-box; display: flex; flex-basis: auto; flex-direction: column; flex-shrink: 0; font-size: 16px; margin: 16px 0px; min-height: 0px; min-width: 0px; padding: 0px; position: relative; z-index: 0;&quot;&gt;&lt;div class=&quot;css-1dbjc4n r-1awozwy r-18u37iz r-1wtj0ep&quot; style=&quot;-webkit-box-align: center; -webkit-box-direction: normal; -webkit-box-orient: horizontal; -webkit-box-pack: justify; align-items: center; border: 0px solid black; box-sizing: border-box; display: flex; flex-basis: auto; flex-direction: row; flex-shrink: 0; justify-content: space-between; margin: 0px; min-height: 0px; min-width: 0px; padding: 0px; position: relative; z-index: 0;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/7202062603290500057/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2020/08/android-build-error-crashlytics-build.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/7202062603290500057'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/7202062603290500057'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2020/08/android-build-error-crashlytics-build.html' title='Android Build Error - The Crashlytics build ID is missing'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-3251491142122012904</id><published>2020-03-22T11:36:00.000+05:30</published><updated>2020-03-22T11:36:57.433+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Angular"/><category scheme="http://www.blogger.com/atom/ns#" term="Angular 7"/><category scheme="http://www.blogger.com/atom/ns#" term="Angular 9"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="TypeScript"/><title type='text'>Angular 7 App ng build Works But ng build --prod Gives Error</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hello,&lt;br /&gt;
&lt;br /&gt;
Recently I was trying to generate production build of one of our older Angular app which was built on Angular 6 and later upgraded to Angular 7. When we run ng build it works fine but when we run&amp;nbsp;ng build --prod it gives so many errors.&lt;br /&gt;
&lt;br /&gt;
Here in this blog I am going to explain what are those errors and how I solved it.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Problem 1 : Strict Parameter checking for function.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
There were few events and handler defined in the app where there were parameter mismatch. For example in html file we have following event.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;componentName (event)=&quot;eventHandler($event)&quot;&amp;gt;&amp;lt;/componentName &amp;gt;&lt;br /&gt;
&lt;br /&gt;
And in component TS file event handler was defined like this&lt;br /&gt;
&lt;br /&gt;
eventHandler() {&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
As you can see from html file it was passing $event param but on handler param was not mentioned. So make sure that your function signature and function declaration matches.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Problem 2 : Duplicate Declaration of Components&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
By mistake we have duplicate declaration of components in both App module and and other child modules of the app. Make sure you either declare all your components to app module or if you are defining it into sub module then make sure you remove it from app module.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Problem 3 :&amp;nbsp;Cannot read property &#39;moduleType&#39; of undefined&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
When you face above issue please check your app module by mistake you may have defined following line twice in your app module.&lt;br /&gt;
&lt;br /&gt;
platformBrowserDynamic().bootstrapModule(AppModule);&lt;br /&gt;
&lt;br /&gt;
It&#39;s like you are trying to bootstrap your Angular app twice and it gives above error. So try to avoid it.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Problem 4 :&amp;nbsp;Enable IVY&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
In Angular 7 by default IVY is disabled hence even if you generate production build you app size it bit large. To enable IVY add following line to your tsconfig.json file.&lt;br /&gt;
&lt;br /&gt;
&quot;angularCompilerOptions&quot;: {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &quot;enableIvy&quot;: true&lt;br /&gt;
}&lt;br /&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
Hope this blog post helps you.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/3251491142122012904/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2020/03/angular-7-app-ng-build-works-but-ng.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/3251491142122012904'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/3251491142122012904'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2020/03/angular-7-app-ng-build-works-but-ng.html' title='Angular 7 App ng build Works But ng build --prod Gives Error'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-1842007073643073187</id><published>2020-03-22T11:12:00.000+05:30</published><updated>2020-03-22T11:13:40.650+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Laravel"/><category scheme="http://www.blogger.com/atom/ns#" term="Laravel 5.4"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP Extensions"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP Framework"/><title type='text'>Laravel App Connect and Emit to Socket.io</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hello,&lt;br /&gt;
&lt;br /&gt;
Recently in one of the project I was working on we have socket.io server created using NodeJS and there were couple of Angular applications and android applications connects with it. However there was a requirement to connect with socket from Laravel app and emit the event.&lt;br /&gt;
&lt;br /&gt;
Actually there was a form in Laravel app on submit of Form we have to notify the socket and socket further notify all the clients connected to it. In this blog I am going to mention how we solved this.&lt;br /&gt;
&lt;br /&gt;
We all know Laravel by default comes with integration of Pusher we could have used it. But since Socket.io is free so we consider to use Socket.io.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s go step by step and understand how to connect with Socket.io&lt;br /&gt;
&lt;br /&gt;
Step 1&lt;br /&gt;
&lt;br /&gt;
Create new folder socket in your app directory of Laravel app.&lt;br /&gt;
&lt;br /&gt;
Step 2&lt;br /&gt;
&lt;br /&gt;
Copy following class in to app/Socket folder and rename it to SocketIO.php&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://github.com/psinetron/PHP_SocketIO_Client&quot;&gt;https://github.com/psinetron/PHP_SocketIO_Client&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
There are many PHP socket IO client is available but we used above one. You can choose either one of your choice.&lt;br /&gt;
&lt;br /&gt;
Step 3&lt;br /&gt;
&lt;br /&gt;
Connect and emit to socket. In your controller file where you want to emit the event. Add following code.&lt;br /&gt;
&lt;br /&gt;
$socketIO = new SocketIO();&lt;br /&gt;
$returnValue =&amp;nbsp;$socketIO-&amp;gt;send(&#39;YOUR_URL&#39;, YOUR_PORT, &#39;YOUR_EVENT&#39;,json_encode(YOUR_PHP_ARRAY))&lt;br /&gt;
&lt;br /&gt;
For this add following line to top of your controller.&lt;br /&gt;
&lt;br /&gt;
use App\socket\SocketIO;&lt;br /&gt;
&lt;br /&gt;
That&#39;s it and now you can connect with socket and emit event to it.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/1842007073643073187/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2020/03/laravel-app-connect-and-emit-to-socketio.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/1842007073643073187'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/1842007073643073187'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2020/03/laravel-app-connect-and-emit-to-socketio.html' title='Laravel App Connect and Emit to Socket.io'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-460082405028475782</id><published>2020-03-22T10:56:00.000+05:30</published><updated>2020-03-22T10:57:29.665+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Android"/><category scheme="http://www.blogger.com/atom/ns#" term="Android App"/><category scheme="http://www.blogger.com/atom/ns#" term="Android Application"/><category scheme="http://www.blogger.com/atom/ns#" term="Android SDK"/><category scheme="http://www.blogger.com/atom/ns#" term="Socket"/><category scheme="http://www.blogger.com/atom/ns#" term="Socket.io"/><title type='text'>Socket.io Not Working on Android 9 (API 28)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hi,&lt;br /&gt;
&lt;br /&gt;
Recently in one of the project we faced a situation where we have used socket.io on backend and Android app connects to it. Socket.io was using http protocol for testing. It worked fine in older android versions but faced an issue in Android 9 and above where socket was connected but emit was not getting on server.&lt;br /&gt;
&lt;br /&gt;
After couple of hours struggle finally found the problem. The problem was socket io was using http protocol and it&#39;s clearText HTTP request and it is banned in recent android version considering security reasons.&lt;br /&gt;
&lt;br /&gt;
In earlier android version by default clearText is set as true but in later version default value is false. That means android components like&amp;nbsp;HTTP and FTP and classes DownloadManager, and MediaPlayer can not use HTTP.&lt;br /&gt;
&lt;br /&gt;
To over come this issue and allow socket to connect with HTTP protocol you have to allow clearText traffic on app level and for that you have to add following attribute in Application tag of your AndroidManifest.xml&lt;br /&gt;
&lt;br /&gt;
&amp;lt;application&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; android:usesCleartextTraffic=&quot;true&quot;&amp;gt;&lt;br /&gt;
.....&lt;br /&gt;
&amp;lt;/application&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you add this to your manifest file, your socket emit will start working and you can still use HTTP with your socket.&lt;br /&gt;
&lt;br /&gt;
Please note that since it was testing app we used HTTP based socket. However in production you should always use HTTPs protocol.&lt;br /&gt;
&lt;br /&gt;
Hope this helps you.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/460082405028475782/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2020/03/socketio-not-working-on-android-9-api-28.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/460082405028475782'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/460082405028475782'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2020/03/socketio-not-working-on-android-9-api-28.html' title='Socket.io Not Working on Android 9 (API 28)'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-3097455151846364231</id><published>2019-08-21T09:49:00.000+05:30</published><updated>2019-08-21T09:49:08.473+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="API"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="MySql"/><category scheme="http://www.blogger.com/atom/ns#" term="NodeJs"/><category scheme="http://www.blogger.com/atom/ns#" term="TypeScript"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Development"/><title type='text'>NodeJs MySQL Observer</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hello,&lt;br /&gt;
&lt;br /&gt;
In this blog we are going to learn how to use NodeJs to observe changes in MySql databases. This is useful when you want to track MySQL changes and based on that want to send some events to frontends or want to do any other actions.&lt;br /&gt;
&lt;br /&gt;
For this first of all you have to enable binary logging in you database. Binary logging is very much useful for real time MySQL replication. In Amazon RDS, it&#39;s by default available and you can switch on it from configurations. For your local database if you are using MAMP, you can do following trick.&lt;br /&gt;
&lt;br /&gt;
Create a file with name my.cnf and add following content to it.&lt;br /&gt;
&lt;br /&gt;
[mysqld]&lt;br /&gt;
server-id = 1&lt;br /&gt;
default-storage-engine = InnoDB&lt;br /&gt;
log-bin=bin.log&lt;br /&gt;
log-bin-index=bin-log.index&lt;br /&gt;
max_binlog_size=100M&lt;br /&gt;
expire_logs_days = 10&lt;br /&gt;
binlog_format=row&lt;br /&gt;
socket=mysql.sock&lt;br /&gt;
&lt;br /&gt;
Add this file to conf folder of your MAMP directory and restart MySQL server. This will enable binary logging in your database.&lt;br /&gt;
&lt;br /&gt;
Now to observe this changes we use npm package called&amp;nbsp;zongji . Install it with NPM.&lt;br /&gt;
&lt;br /&gt;
Add following code to your NodeJs script.&lt;br /&gt;
&lt;br /&gt;
var ZongJi = require(&#39;zongji&#39;);&lt;br /&gt;
var _underScore = require(&#39;underscore&#39;);&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
var zongji = new ZongJi({&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; user : &#39;YOUR_USERNAME&#39;,&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; password : &quot;YOUR_PASSWORD&quot;,&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; database: &#39;YOUR_DATABASE&#39;,&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; socketPath : &#39;/Applications/MAMP/tmp/mysql/mysql.sock&#39;&lt;/div&gt;
&lt;div&gt;
});&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
Now add event on binlog.&lt;br /&gt;
&lt;br /&gt;
zongji.on(&#39;binlog&#39;, function(evt) {&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
});&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
This event is triggered whenever there is a change in any of your database tables.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Inside this event you can have logic of checking new rows, updates rows, deleted rows.&lt;/div&gt;
&lt;div&gt;
zongji.on(&#39;binlog&#39;, function(evt) {&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
if (evt.getEventName() === &#39;writerows&#39; || evt.getEventName() === &#39;updaterows&#39; || evt.getEventName() === &#39;deleterows&#39;) {&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;var database = evt.tableMap[evt.tableId].parentSchema;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var table =&amp;nbsp; evt.tableMap[evt.tableId].tableName;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var columns = evt.tableMap[evt.tableId].columns;&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _underScore.each(evt.rows, function(row) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; });&lt;br /&gt;
}&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
At last start the process and pass the events you want to watch.&lt;br /&gt;
zongji.start({&lt;br /&gt;
&amp;nbsp; includeEvents: [&#39;tablemap&#39;, &#39;writerows&#39;, &#39;updaterows&#39;, &#39;deleterows&#39;]&lt;br /&gt;
});&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/3097455151846364231/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2019/08/nodejs-mysql-observer.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/3097455151846364231'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/3097455151846364231'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2019/08/nodejs-mysql-observer.html' title='NodeJs MySQL Observer'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-3461075620396189425</id><published>2019-08-20T09:08:00.000+05:30</published><updated>2019-08-20T09:08:29.043+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="React"/><category scheme="http://www.blogger.com/atom/ns#" term="React Native"/><category scheme="http://www.blogger.com/atom/ns#" term="ReactJs"/><category scheme="http://www.blogger.com/atom/ns#" term="TypeScript"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Application"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Development"/><title type='text'>ReactJs Material UI Table Infinite Scroll</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hello,&lt;br /&gt;
&lt;br /&gt;
Recently in one of my ReactJs project, I faced a challenge in implementing infinite scroll in Material UI table. In this blog I am going to mention trick I have used.&lt;br /&gt;
&lt;br /&gt;
First of all I was really surprised to see that Material UI table does not have infinite scroll function out of the box. It&#39;s very much needed. Sometimes something can not be achieved with frameworks, can be achieved via basics of JavaScript. In this I have done something similar.&lt;br /&gt;
&lt;br /&gt;
I tried adding on scroll events on Table, Table Body but it didn&#39;t work. I also tried adding refs to body and then bind the Scroll event but that also did not work. After struggling for couple of hours, I finally decided to it with Pure JavaScript.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 1 : Wrap material UI table inside the container with fixed height and set overflow = scroll to container.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
import styled from &quot;styled-components&quot;;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
export const Table = props =&amp;gt; (&lt;br /&gt;
&amp;nbsp; &amp;lt;TableWrapper id={props.id}&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;MuiTable {...props}/&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/TableWrapper&amp;gt;&lt;br /&gt;
&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
const TableWrapper = styled.div`&lt;br /&gt;
&amp;nbsp; max-height: 500px;&lt;br /&gt;
&amp;nbsp; overflow: scroll;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ::-webkit-scrollbar {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; width: 3px;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; height: 3px;&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
`;&lt;br /&gt;
&lt;br /&gt;
As you can see I created a wrapper of table and set max height to it. You can make it dynamic as well depending on window height.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 2: Import Table to your component&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
import {&lt;br /&gt;
&amp;nbsp; Table&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;} from &#39;./components/Table&#39;;&lt;br /&gt;
&lt;br /&gt;
return (&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;Table id={&quot;tableID&quot;}/&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; );&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 3: Bind scroll event to wrapper&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
let me = this;&lt;br /&gt;
document.getElementById(&#39;tableID&#39;).onscroll = function(event){&lt;br /&gt;
&amp;nbsp; &amp;nbsp;if(this.scrollTop == (this.scrollHeight - this.clientHeight)){&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//User reached bottom of table after scroll&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//Logic to call web services to get next set of data&lt;br /&gt;
&amp;nbsp; &amp;nbsp;}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
Hope this helps you.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/3461075620396189425/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2019/08/reactjs-material-ui-table-infinite.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/3461075620396189425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/3461075620396189425'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2019/08/reactjs-material-ui-table-infinite.html' title='ReactJs Material UI Table Infinite Scroll'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-2668876086344995262</id><published>2019-08-19T08:15:00.000+05:30</published><updated>2019-08-19T08:15:28.024+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="MEAN"/><category scheme="http://www.blogger.com/atom/ns#" term="MERN"/><category scheme="http://www.blogger.com/atom/ns#" term="NodeJs"/><category scheme="http://www.blogger.com/atom/ns#" term="Redis"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Application"/><category scheme="http://www.blogger.com/atom/ns#" term="Web Development"/><title type='text'>Accessing Data From Redis Using NodeJs</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hello,&lt;br /&gt;
&lt;br /&gt;
When you are working with business applications, it&#39;s sometimes need to cache the data. At this point Redis can be very useful, it can be used as database or cache database. You can store any kind of data like strings, JSON objects etc. in Redis.&lt;br /&gt;
&lt;br /&gt;
Problem we face while working with NodeJs and Redis, get data operation from Redis is Asynchronous operations so it gives you callback and your code execution will continue. This may create a problem when you want to handle it in Synchronous way. For example you may have loops inside that you are trying to access data from Redis.&lt;br /&gt;
&lt;br /&gt;
In this blog I am going to explain how you can have Synchronous operations. In nutshell we got to promisify the redis module.&lt;br /&gt;
&lt;br /&gt;
There is a library called bluebird, that can be used for this. Lets go step by step.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 1&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Install bluebird and redis in your NodeJs app.&lt;br /&gt;
&lt;br /&gt;
npm install bluebird&lt;br /&gt;
npm install redis&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 2&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Import it in NodeJs app.&lt;br /&gt;
&lt;br /&gt;
var redis = require(&#39;redis&#39;);&lt;br /&gt;
var bluebird = require(&quot;bluebird&quot;);&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Step 3&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
Promisify Redis.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
bluebird.promisifyAll(redis.RedisClient.prototype);&lt;/div&gt;
&lt;div&gt;
bluebird.promisifyAll(redis.Multi.prototype);&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Step 4&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
Connect to Redis client.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
var client = redis.createClient();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; client.on(&#39;connect&#39;, function() {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; console.log(&#39;Redis client connected&#39;);&lt;/div&gt;
&lt;div&gt;
});&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Step 5&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
Use Async version of get function to get data.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
client.getAsync(&quot;MY_KEY&quot;).then(function(res) {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; //Access Data&lt;/div&gt;
&lt;div&gt;
});&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
This is how you can have Sync operations with Redis.&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/2668876086344995262/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2019/08/accessing-data-from-redis-using-nodejs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/2668876086344995262'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/2668876086344995262'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2019/08/accessing-data-from-redis-using-nodejs.html' title='Accessing Data From Redis Using NodeJs'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7442072150765022610.post-253791504109967606</id><published>2019-08-15T15:43:00.001+05:30</published><updated>2019-08-15T15:43:20.280+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Angular"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="React"/><category scheme="http://www.blogger.com/atom/ns#" term="React Native"/><category scheme="http://www.blogger.com/atom/ns#" term="ReactJs"/><category scheme="http://www.blogger.com/atom/ns#" term="TypeScript"/><title type='text'>ReactJs / Angular - Override Material UI Theme</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hello,&lt;br /&gt;
&lt;br /&gt;
While working with React or Angular Applications we normally uses Material UI themes and components and it&#39;s great choice because it has nice set of themes and colors and ready to use components. That makes our life easy.&lt;br /&gt;
&lt;br /&gt;
One challenge we face is, in case if we want to change or override the theme. For example Material ui has dark blue theme. What if you want to change colors or dark blue theme with your own color. One option is you can declare the class with same name and give your own property. However the better solution is to use theme override. In this blog I am going to mention how to this.&lt;br /&gt;
&lt;br /&gt;
Please note the method I am going to mention here is specific to React application.&lt;br /&gt;
&lt;br /&gt;
First of all create theme.js file in your app and add following code to it.&lt;br /&gt;
&lt;br /&gt;
import React from &quot;react&quot;;&lt;br /&gt;
import { MuiThemeProvider, createMuiTheme } from &quot;@material-ui/core/styles&quot;;&lt;br /&gt;
import CssBaseline from &quot;@material-ui/core/CssBaseline&quot;;&lt;br /&gt;
import blueGrey from &quot;@material-ui/core/colors/blueGrey&quot;;&lt;br /&gt;
import lightBlue from &quot;@material-ui/core/colors/lightBlue&quot;;&lt;br /&gt;
import &quot;typeface-roboto&quot;;&lt;br /&gt;
&lt;br /&gt;
import { ThemeProvider as ScThemeProvider } from &quot;styled-components&quot;;&lt;br /&gt;
&lt;br /&gt;
export default props =&amp;gt; (&lt;br /&gt;
&amp;nbsp; &amp;lt;ScThemeProvider theme={muiTheme}&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;MuiThemeProvider theme={muiTheme}&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;CssBaseline&amp;gt;{props.children}&amp;lt;/CssBaseline&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/MuiThemeProvider&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/ScThemeProvider&amp;gt;&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
const theme = {&lt;br /&gt;
&amp;nbsp; overrides: {&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
&amp;nbsp; },&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; palette: {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; primary: {&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; main: &#39;#MAIN_COLOR&#39;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; },&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; secondary: {&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; main: &#39;#SECONDARY_COLOR&#39;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; },&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; background: {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; default: &#39;#BACKGROUND_COLOR&#39;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; },&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; type: &quot;dark&quot;&lt;/div&gt;
&lt;div&gt;
};&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
const muiTheme = createMuiTheme(theme);&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Now here in overrides you can add code to override. For example if you want to change panel header. If you inspect html element you will find it has a class&amp;nbsp;MuiPaper-root&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Here is how you can override base CSS of it.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp;overrides: {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; MuiPaper: {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; root: {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; background: &#39;#YOUR_COLOR&#39;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; },&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; rounded: {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;background: &#39;#YOUR_COLOR&#39;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Same way for any other components you can do it. Inspect the HTML structure, find out Class Name and override it.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.hiren.dev/feeds/253791504109967606/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.hiren.dev/2019/08/reactjs-angular-override-material-ui.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/253791504109967606'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7442072150765022610/posts/default/253791504109967606'/><link rel='alternate' type='text/html' href='http://www.hiren.dev/2019/08/reactjs-angular-override-material-ui.html' title='ReactJs / Angular - Override Material UI Theme'/><author><name>Hiren Dave</name><uri>http://www.blogger.com/profile/03332234242233370508</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSTrKrW2hF0Kl2lmUdqLsKOP9A_ozB4Obt1iH0UDqVNggVbKZwhS3WIP900JH6-bD2w543VZB3_d86_0Qc1ALAdCzEzctBOl5Lc1ahty0JtXza0rgpVEkId2j0KAF4-w/s220/hirendave12.png'/></author><thr:total>0</thr:total></entry></feed>