Posts

Reading a pre-populated sqlite database using react native with expo..

Image
I recently needed to read an existing sqlite database, and return its contents to the react native front-end on an android emulator.  I  read several related posts on the subject but they all give examples of console logging, never returning.  I faced quite some difficulties, and hence decided to create this post as a blog. Hope it helps someone who comes here looking for a solution. Usually, there are two main issues that you would face. One, you would notice that simply opening a database and fetching won't work. You need to copy the local database to an internal document store and then use that database. Second, you would notice that there is no way of 'returning' the value of  a variable in the traditional sense of the term. You must handle it within the async function itself. So follow me for the solution.  Step 1. Create the root folder. From the terminal in the root folder, create the react native app with expo using : expo init newApp Choose the blank te...

Using custom Fonts and applying it globally across the application

More recently, I had the need to implement a custom font for my app, and also apply it globally to the entire app (Including fontFamily in every <Text> tag seemed such a chore. After overdosing on google, and stackoverflow(our common chum! for all things code), I found the cleanest way to do it. So, here goes:  Step 1. Include the custom Font in your app. Download the custom font. Note that it should have either the .ttf (TrueType font) or .otf (OpenType Font) extension. Both are supported by React Native. What is the difference? the OpenType font format (OTF) is the preferred choice for most professional designers because of its advanced typographic features and smaller file sizes. OTF files offer a much wider range of possibilities regarding type design. Plus, they provide better readability across multiple devices and platforms. They’re more modern-looking and offer a higher level of detail than TTF fonts. However, for average users, who do not need additional features lik...

React Hooks - useReducer - A simple explanation (hopefully...)

Image
In this blog, I hope to provide a simple explanation of how useReducer works! Atleast, the part that I found difficult to understand. Take a goal e.g. We require a functionality, where, everytime the Increment Button is pressed, the counter should increment by 100. The reducer code to do this is written as: const  [ new State ,  dispatchAction ]  =   useReducer (   counterIncrementer , initialState ) ; This line of code lets React know that: 1. When dispatch is triggered (e.g. on click of the Increment Button), it should use the  counterIncrementer (reducer) function. 2. It should run the  counterIncrementer (reducer) function using the initialState and the action type ('increment') provided. 3. It should then return the newState as a result o f the reducer function. Here is my attempt to present this process in the form of a flowchart. Hope this helps!!  

React Hooks - useState Vs useRef (An explanation)

Image
I have tried to provide a brief  flowchart representation of how useState, useEffect and useRef work. The source for this explanation is from  WebDev Simplified's you tube channel . Suppose you wanted to show a name field and a count field to count how many times you updated the name field.  The diagram below shows the code (not focussing too much on the syntax and stuff), how one would normally do it, and the challenges/details of how react will work in each case. In general, on the left part of the diagram, I have provided the code, the middle part displays the contents of the form as things happen, and have included some explanation on how it all works on the right part.  Hoping the picture is self-explanatory.  The biggest usecase for useRef is to refer to the elements inside of the HTML. Each element inside the focument has a 'ref' attribute which can be set to anything. Most common use is to set focus to a certain element in the DOM. In the pictorial below...

Getting Company URL from a list of Company Names using python

I have a list of company names in my excel sheet, and I want to get the corresponding website URL. After trying hard using WEBSERVICES and FILTERXML using excel VBA, I didn't get much of a result. I then switched to Python, for better results.  Turns out there is a library called googlesearch which helps achieve the same. I am providing the steps below: Save the list of companies in a text file. Here is the code that achieves the task from googlesearch import search file = open ( "your_file_name.txt" , "r" ) links = file. read (). split ( ' \n ' ) #print(links) with open ( "yourfilenamewithlinks.txt" , "w" ) as f:     for query in links:         print (query)         for results in search (query, tld = "co.in" , num = 1 , start = 1 , stop = 1 , pause = 10 ):                 f. write (query)                 f. write ( "," )     ...