Skip to content

Instantly share code, notes, and snippets.

View dhbalaji's full-sized avatar

D Balaji dhbalaji

View GitHub Profile
@dhbalaji
dhbalaji / backup-files.md
Created October 5, 2021 05:56
Files to backup when you change the OS

Files to backup when you change the OS

  1. .ssh folder and its contents
  2. .npmrc
  3. .gitignore
  4. .gitconfig
  5. other configuration files under home or users directory
  6. IDE settings (preferably on some private repo)
@dhbalaji
dhbalaji / bashAlias.md
Created December 25, 2020 05:18
Set multiple permanent & temporary aliases in Linux

I wrote about aliases and other linux concepts that you need to be famililar with. Aliases are used almost every day by expert programmers. But in the real world, its not easy to create an alias and let every user in your group use it. You may need a manager or VP permission to modify something in the prod boxes which could be a frustrating process in itself, remember raising tickets for someone?

Aliases can be created and removed. I called certain aliases permenent because they persist from user session to session. Whereas the temporary ones are lost.

Set permenant alias

For individual user, create an entry in ~/.bashrc

For group users or everyone on the linux OS /etc/profile.d/yourAliasFile.sh. Its important to set the extension to .sh. You need root access to perform this activity.

Capitalize first line

  function capitalizeFirstLetter(str) {
    return `${a.charAt(0).toUpperCase()}${a.slice(1)}`;
  }

Get selected text from DOM

@dhbalaji
dhbalaji / DebugChromeAndroid.md
Last active June 7, 2020 14:27
How to debug UI issues on chrome android

Debug mobile chrome UI screens on android

If you had done any responsive web development, you can verify your code on the mobile devices in 2 ways. It could be done on

  1. the chrome devtools with device emulator
  2. the real android or IOS device connected to your laptop via USB

Let us look into step 2 in this short article

Things you need

@dhbalaji
dhbalaji / tabIndex.md
Last active May 29, 2020 10:16
#Accessibility Keyboard focus and tabIndex

tabIndex and accessibility

Key points

  • Form elements and links are tabbable by default. It means we can use tab to navigate through them.
  • If you want any other element tabbable or to get focus on tab, you need to explicitly mention tabIndex=0
  • Once an element gets focus, it must respond to enter / space keypress
  • You can change tabOrder by using the tabIndex values
  • display:none means the tabbable element in that section wont get focus
@dhbalaji
dhbalaji / includes.md
Created April 16, 2020 17:29
Check if string contains substring, array has an item

includes in ES6 to search for string, item in array

TLDR: Of course from different prototypes.

   const str = 'We are Indians';
   const subStr = 'India'
   const hasSubStr = str.includes('India');
   
 
@dhbalaji
dhbalaji / reactHookAjaxCall.md
Last active April 16, 2020 17:17
Right way to do Ajax Call in React Hooks

React hooks Ajax Call - the right way

React hooks are used in functional components. It means, we no longer have componentWillMount or componentDidMount. Lets find out how to do ajax call in React hook useEffect.

const [animals, setAnimals] = React.useState([]);

React.useEffect(() => {
    const fetchAnimals = async () => {
 const response = await axios.get(`https://api.github.com/animals/`);
@dhbalaji
dhbalaji / JSArrayDeleteExample.md
Created April 13, 2020 17:41
Deleting item on array without leaving holes in the array

Using delete on an array works but there will be holes in the array, use splice instead.

Wrong

  const arr = ['dog', 'cat', 'pig']
 delete arr[arr.length - 1];
  console.log(arr); // ['dog', 'cat', '']