Showing posts with label tricks and tips. Show all posts
Showing posts with label tricks and tips. Show all posts

Tuesday, September 12, 2023

Extract all URLs from a web page

Here is a quick JavaScript snippet to extract all URLs from a webpage, using Developer Tools. No Browser Extension is required!

Tuesday, January 3, 2023

Excel - Add and Remove Line Breaks in a Cell

Many time we struggle for the line break in a multiple excel cells. This article have some useful tricks that will help you to achive this easily.

1) Manully add line break in a cell using "Alt + Enter".
- Edit the cell with F2 or while typing in a cell when you press "Alt + Enter" it will create new line in a cell.
- To remove a line break, edit the cell with F2, go to the start of line break and press "Backspace" and enter.

2) Line break using formula:
- You can use line break character in CHAR(10) function. Here 10 is the line break character.
- example: CONCATENATE("Rakesh" , CHAR(10) , "Patel"), if you can't see the line break when you  press ENTER, then apply WRAP TEXT to the cell.

3) Replace "," or any other character with New Line:
- Press CTRL + H, this will open "Find and Replace" window. Under "Find what" you can put your text that you want to search. and under "Replace with" press CTRL + J (you won't able to see anything) just click on "Replace" or "Replace ALL". This will will add line break wherever it finds your text.
- The same way you can replace Line break with any of your text.

If "CTRL + J" does not work for you then you can also try Alt + type 0010

Tuesday, November 22, 2022

Javascript Tips and Best Practices

1. Check property exists in an object

The in operator returns the boolean value true/false.
The in operator returns true if a property exists in the object or its prototype chain.

2. String to a number using the plus (+) operator

The unary plus operator (+) is the fastest and preferred way of converting something into a number.

3. Mask numbers using slice and padStart

The slice() method returns selected elements in an array, as a new array. Negative numbers select from the end of the array.
The padStart() method pads the current string with another string until the resulting string reaches the given length. The padding is applied from the start of the current string.

4. Swap two variables

Use destructuring assignment approach because it is short and expressive. Swapping is performed in just one line statement. It works with any data type like numbers, strings, booleans, or objects.

5. Check every element of the array using Array.every

The Array every() method checks whether all the array elements pass the test implemented by the provided function.
It returns true if the function returns true for all elements.
It returns false if the function returns false for one element. When every() finds a false result, it will stop the loop and continue no more which improves the performance. The every() method does not change the original array.

6. Use of nullish coalescing operator with numbers

I have use lot of time || operator for the logical disjunction, but it ends when value is 0 in the variable. So found better way to handle this.

A Nullish value is a value that is either null or undefined.
The Nullish Coalescing Operator (??) is a logical operator that accepts two values and returns the second value if the first one is null or undefined and otherwise returns the first value.

7. Filter Array with only values

Many times we have an issue with array to have empty values and need to handle we write extra code. To avoid it just you have to use filter().

Pass the Boolean to Array.filter as the first argument.

Monday, May 2, 2022

2 Useful tricks in Windows for Screen Recording and Voice Typing

Recently found 2 useful tricks that help me a lot in my day-to-day work.

1) Instantly record your screen, just press (Win + Alt + R) 

2) Easy to voice type and detect your work, just press (Win + H), and a detecting bar will appear on top. now just talk to your system, and it will type for you.


Hope this will make your life easy.  😉

Monday, December 13, 2021

Few Javascript or JQuery Tricks for array and operators

 1) Empty an array

var arr = [10 , 20 , 30 ];
arr.length = 0; // arr will be equal to [].


2) Truncate an array using length

Like the previous example of emptying an array, we truncate it using the length property.

var arr = [10, 20, 30, 40, 50, 60, 70, 80, 90];
arr.length = 4; // arr will be equal to [10, 20, 30, 40].

As a bonus, if you set the array length to a higher value, the length will be changed and new items will be added with undefined as a value. The array length is not a read only property.

arr.length = 10; // the new array length is 10
arr[arr.length - 1] ; // arr [10, 20, 30, 40, 50, 60, 70, 80, 90, undefined];


3)Use logical AND/ OR for conditions

var foo = 10;
foo == 10 && doSomething(); // is the same thing as if (foo == 10) doSomething();
foo == 5 || doSomething(); // is the same thing as if (foo != 5) doSomething();


4) Comma operator

var a = 10;
var b = ( a++, 99 );
console.log(a);  // a will be equal to 10
console.log(b);  // b is equal to 99


5) Swap variables

let v1 = 'value 1';
let v2 = 'value 2';

[v1,v2] = [v2, v1];
console.log(v1, v2);


Thursday, January 30, 2020

Google Chrome Keyboard Shortcuts


Window and Tab Shortcuts
Ctrl+NOpen a new window
Ctrl+Shft+NOpen a new window in incognito mode
Press Ctrl, and click a linkOpen link in a new tab
Press Shft, and click a linkOpen link in a new window
Alt+F4Close current window
Ctrl+TOpen a new tab
Ctrl+Shft+TReopen the last tab you've closed. Google Chrome remembers the last 10 tabs you've closed.
Drag link to tabOpen link in specified tab
Drag link to space between tabsOpen link in a new tab in the specified position on the tab strip
Ctrl+1 through Ctrl+8Switch to the tab at the specified position number. The number you press represents a position on the tab strip.
Ctrl+9Switch to the last tab
Ctrl+Tab or Ctrl+PgDownSwitch to the next tab
Ctrl+Shft+Tab or Ctrl+PgUpSwitch to the previous tab
Ctrl+W or Ctrl+F4Close current tab or pop-up
Alt+HomeOpen your homepage
Ctrl+O, then select fileOpen a file from your computer in Google Chrome
Address Bar Shortcuts
Type a search termPerform a search using your default search engine
Type the part of the web address that's between 'www.' and '.com', then press Ctrl+EnterAdd www.and .com to your input in the address bar and open the web address
Type a search engine keyword or URL, press Tab, then type a search termPerform a search using the search engine associated with the keyword or the URL. Google Chrome prompts you to press Tab if it recognizes the search engine you're trying to use.
F6 or Ctrl+L or Alt+DHighlight content in the web address area
Type a web address, then press Alt+EnterOpen your web address in a new tab
Shortcuts to open Google Chrome features
Ctrl+BToggle bookmarks bar on and off
Ctrl+HView the History page
Ctrl+JView the Downloads page
Shft+EscapeView the Task manager
Webpage shortcuts
Ctrl+PPrint your current page
F5Reload current page
EscStop page loading
Ctrl+F5 or Shft+F5Reload current page, ignoring cached content
Press Alt, and click a linkDownload link
Ctrl+FOpen find-in-page box
Ctrl+G or F3Find next match for your input in the find-in-page box
Ctrl+Shft+G or Shft+F3Find previous match for your input in the find-in-page box
Ctrl+UView source
Drag link to bookmarks barBookmark the link
Ctrl+DBookmark your current webpage
Ctrl++Make text larger
Ctrl+-Make text smaller
Ctrl+0Return to normal text size
Text shortcuts
Highlight content, then press Ctrl+CCopy content to the clipboard
Place your cursor in a text field, then press Ctrl+V or Shft+InsertPaste current content from the clipboard
Place your cursor in a text field, then press Ctrl+Shft+VPaste current content from the clipboard without formatting
Highlight content in a text field, then press Ctrl+X or Shft+DeleteDelete the content and copy it to the clipboard
More shortcuts
Backspace, or press Alt and the left arrow togetherGo to the previous page in your browsing history for the tab
Shft+Backspace, or press Alt and the right arrow togetherGo to the next page in your browsing history for the tab
Ctrl+K or Ctrl+EPlaces a '?' in the address bar. Type a search term after the '?' to perform a search using your default search engine.
Place your cursor in the address bar, then press Ctrl and the left arrow togetherJump to the previous word in the address bar
Place your cursor in the address bar, then press Ctrl and the right arrow togetherJump to the next word in the address bar
Place your cursor in the address bar, then press Ctrl+BackspaceDelete the previous word in the address bar
Space barScroll down the web page
HomeGo to the top of the page
EndGo to the bottom of the page

Reference

Friday, July 26, 2019

Calculated Birth Date To Age

There are number of way to calculate age in excel, below are the example to do calculation:


A B C
1 8/18/1979
2

example 1:
=INT((today() - A1)/365)

example 2: Use DATEDIF() function
Note: Excel provides the DATEDIF function in order to support older workbooks from Lotus 1-2-3, possible in some case this does not work.

Syntex : DATEDIF(start_date,end_date,unit)

unit :
"Y" : The number of complete years in the period.
"M" : The number of complete months in the period.
"D" : The number of days in the period.
"MD": The difference between the days in start_date and end_date. The months and years of the dates are ignored.
Important: We don't recommend using the "MD" argument, as there are known limitations with it. See the known issues section below.
"YM": The difference between the months in start_date and end_date. The days and years of the dates are ignored
"YD": The difference between the days of start_date and end_date. The years of the dates are ignored.


Reference Link

=DATEDIF(A1,TODAY(),"Y") & " Years, " & DATEDIF(A1,TODAY(),"YM") & " Months, " & DATEDIF(A1,TODAY(),"MD") & " Days"

example 3: Use YEARFRAC()
SYNTEX : YEARFRAC(start_date, end_date, [basis])

YEARFRAC calculates the fraction of the year represented by the number of whole days between two dates (the start_date and the end_date). For instance, you can use YEARFRAC to identify the proportion of a whole year's benefits, or obligations to assign to a specific term.

Basis   Day count basis
: US (NASD) 30/360
1 : Actual/actual
2 : Actual/360
3 : Actual/365
4 : European 30/360

=ROUNDDOWN(YEARFRAC(A1, TODAY(), 1), 0)

Friday, July 12, 2019

Make all textbox on page as readonly using JQuery

This is life saving for the coder, as many time we have to make textbox readyonly, this also work with other controls.

1)single control
$('#TextBoxID').attr('readonly', 'true');

2)all text box with type text
$('input[type="text"]').attr('readonly','true');

3)all select control
$('select').attr('disabled','true');


Friday, July 5, 2019

Get all installed programs list using command prompt

Use Windows Management Instrumentation Command line tool (WMIC) in the Command Prompt window, that will help you to get List of Programs.

Step 1:
Open Command Prompt, Win + R (type "cmd")

Step 2:
type “wmic” and press Enter at command prompt.

You will get prompt as wmic:root\cli> 

Type following command that will create text file with the details.
wmic:root\cli> /output:C:\ListOfInstalledPrograms.txt product get name,version

Note: you can use any number of column at the end of command

once the command is executed, it will be back to command prompt, type "exit" to quite from wmic prompt.


Thursday, July 4, 2019

Merge multiple .csv files available in same folder using CMD command

This is a trick which can save you a lot of time when working with a dataset spread across multiple CSV files. Using a simple CMD command it is possible to combine all the CSV’s into a single .CSV file.

Command:
c:\> copy *.csv combine.csv

that's it. Hope this will save your time.

Thursday, March 28, 2019

Useful Windows Command Prompt Commands

1. Command History: You can track down your command history.
c:\> doskey /history

2. Run multiple commands:You just need to put “&&” between each command and save some time.
c:\>winword && notepad && msexcel

3. See PC driver list :You can see all the drivers installed on your computer.
c:\>driverquery

4. Send an output to clipboard: Save the output of a command.
c:\>ipconfig /all | clip

5. Create Wi-Fi hotspot right from the command prompt
Before opening the Command Prompt to execute the commands needed for this, you need to open Control Panel and find Change adapter settings in the Network and Sharing option. There, click on the connection you are using and click on Properties. Now find the sharing tab and check the option “Allow other network users to connect through this computer’s internet connection.”

-Open the Command Prompt with administrative privileges and enter the following command to enabled hotspot:
c:\> netsh wlan set hostednetwork mode=allow ssid=Youthotspotname key=yourpassword

-start the Wi-Fi hotspot
c:\>netsh wlan start hostednetwork

-To stop it, simply enter this command:
c:\>netsh wlan stop hostednetwork

Friday, November 30, 2018

10 Things That Require ZERO Talent



B+ with Yourself
  1. Being on Time
  2. Work Ethic
  3. Effort
  4. Body Language
  5. Energy
  6. Attitude
  7. Passion
  8. Being Coach-able
  9. Doing Extra
  10. Being Prepared

Monday, November 5, 2018

Best way to get FILE NAMES from any Folder in Excel


This is one of the easy way to get File Names from your Windows Folder via "Name Manager".


  • At first, create a new Excel worksheet.
  • Then, select Cell A1.
  • Next, go to “Formulas” tab and click “Name Manager” button.
  • In the popup dialog box, click “New” button.


  • Subsequently, in the next dialog box, input “Files” in “Name” field.
  • And change “=Sheet1!$A$1” to “=FILES(Sheet1!$A$1)” in “Refers to:” field.



  • Afterwards, click “OK” and close “Name Manager” dialog box.
  • Later, copy the Windows folder path in Cell A1 and add “\*” at the end of the path.
  • Next, select the Cell A3 and input the function “=INDEX(Files,ROW()-2)”.



At once, a file in this Windows folder will be listed, like the following image.

  • Finally, just copy this function down several rows to list the other files until you see the “#REF!” error. The error means that all files have been listed.




Tuesday, October 23, 2018

Export High Resolution Images Directly from Microsoft PowerPoint

We know that PowerPoint allow you to save side as JPEG, but default resolution of the image in 96. Here we have a trick where you can increase the resolution.
Follow below steps and will allow you to save JPEG with high resolution.



  1. Press "Window + R" and type "regedit"
  2. Go to "Computer\HKEY_CURRENT_USER\Software\Microsoft\Office\\PowerPoint\Options". (xx.xx is your Office version folder number)
  3. Find / Create new "ExportBitmapResolution" DWORD entry and set Decimal Value as per your required resolution. eg. 196
  4. Open your PowerPoint and save slide as JPEG.
You can now see all the slides were saved with high resolution. 

Wednesday, October 10, 2018

Enable the "Insert Rows" with mouse Right Click in Microsoft Excel

To fix this Issue, just follow below steps:

  1. Close all you Microsoft Excel files
  2. Goto "%appdata%\Microsoft\Excel" in Windows explorer and rename Excel15.xlb to Excel15.old
  3. Start Excel and you will see the 'Insert Row' function is now active.
Now you are able to find "Insert Rows" Enable. 

What is .xlb file ?
XLB is a settings file format created by Microsoft Excel. XLB files contain custom settings for the toolbars (or command bars). These settings can be edited or customized by selecting “toolbar” from the view options. XLB files can contain information such as which toolbars are visible, their position, and their function. XLB files allow for the transfer of customization information between computers and users.

Tuesday, September 5, 2017

Quickly create a dynamic drop down list in Excel

I have a request from friend to create a dynamic drop down list in excel and I would like to share with my blog reader...

Part  1: 
- Open Excel and we start by creating a defined name, 
- Select the Formulas Tab, then Define
- Enter "SomeRangeName" under the Name text box
- Enter =OFFSET(sheet1!$B$2,0,0,COUNTA(sheet1!$B:$B),1) under the Refers to text box

Note: You have to enter drop down items in single column you want here in above formula I have selected Sheet1 and column B, it will start filtering from Row B2.

Part 2:
To create a data validation list:

- Select the cell you want to show dropdown list eg. A1
- Select Data Validation under the Data Tab
- Select List under Allow
- Place the cursor in the Source text box and type formula "=SomeRangeName"

That's it.. now when ever you add items in "Column B" it will automatically populate in drop down list... 

Tuesday, August 22, 2017

Getting Geo-location with JSon and JQuery


$.getJSON("https://freegeoip.net/json/", function(data) {
    const countryCode = data.country_code;
    const countryName = data.country_name;
    const ip = data.ip;
    const timezone = data.time_zone;
    const latitude = data.latitude;
    const longitude = data.longitude;

    alert("Country Code: " + countryCode);
    alert("Country Name: " + countryName);
    alert("IP: " + ip); 
    alert("Time Zone: " + timezone);
    alert("Latitude: " + latitude);
    alert("Longitude: " + longitude);   
});
Credit goes to original coder..

Friday, July 14, 2017

Compare the Contents of Two Folders in Windows

This is a common problem with us, while we take the backup. We always create duplicate backup of backup... mean multiple backup for the same files.. as we don't know if that is already there or not.. so this is just a little trick to save some space by avoiding duplicate.. 

List the folder structure using TREE command:
TREE command can be extremely handy in this case. Suppose you want to compare the two folders (including file names) c:\SOURCE and c:\DEST, open a Command Prompt window and then type these commands:

d:\> TREE  D:\SOURCE /A /F >D:\SOURCE.TXT

d:\> TREE  D:\DEST /A /F >D:\DEST.TXT

This outputs each of the command results to separate text files in your d:\ drive’s root directory. The text files will have your directory structure in a tree format, which makes it easy for comparison work.

Quick Tip: To compare only the directories, remove the "/F" flag.

Next, fire up your text comparison utility like WinDiff, WinMerge or DiffMerge. Don’t have any of those? No problem! You can compare the two text files online via diffchecker.com.

Go to DiffChecker.com and paste the contents of d:\source.txt in one column, and D:\DEST.txt in another column. Click Find differences.

Enjoy little trick to same space in your disk...

Thursday, June 15, 2017

Pen drive show empty even when data exists

A friend of my have problem with his pen drive, he was not able to see any folders or file even data was there. He scan with antivirus but no virus detected.
Use following command to see if folders or files got hidden somehow...

1) Go to command prompt using "cmd" command 
2) Type command "attrib -h -r -s /s /d e:\*.*"

Note: "e:" is the pendrive folder.

Wait for few seconds, and you will get your files and folder visible.

Monday, April 24, 2017

What the 'Win' Key Does - Shortcuts!

You might think that the little windows or ‘win’ key  on your keyboard only has one function – to bring up the start menu – but it in fact can be used in conjunction with other keys for a vast number of simple shortcuts. These ‘win’ key  shortcuts will save you those precious minutes and help you perform tasks you never knew you could with your PC.
Enjoy the following listed shortcuts, according to alphabetical order.


  1. Win — opens the Start Menu (but in Windows 8.1 it opens the previous window)
  2. Win + A — opens Windows 10’s Action Center
  3. Win + B — chooses the first icon in the Notification Area (then use the arrow keys to switch icons)
  4. Win + Ctrl + B — switches to a new message in the Notification Area
  5. Win + C —brings up the Charm Bar (in Windows 8 and 8.1). In Windows 10 it opens Cortana
  6. Win + D — shows the desktop and minimizes all windows
  7. Win + E — opens Windows Explorer. In Windows 10 opens Quick Launch
  8. Win + F — starts ’Find files and folders’
  9. Win + Ctrl + F — opens ’Find computers’
  10. Win + G — brings all gadgets to the foreground (in Windows 7 and Vista); opens Windows 10’s Game bar
  11. Win + K — opens a new Start menu (only Windows 8 and 8.1)
  12. Win + L — changes user or can lock the workstation
  13. Win + M — minimizes all your windows
  14. Win +  Shift + M — restores windows that have been minimized
  15. Win + O — locks device orientation (and disables gyroscope function on tablets);
  16. Win + P — switches operating modes to an outside monitor or projector
  17. Win + Q — opens Search charm for installed apps (in Windows 8)
  18. Win + R — opens the ’Run dialog’ box
  19. Win + T — opens the Taskbar
  20. Win + U — opens the Utility Manager
  21. Win + W — opens Windows Ink Workspace
  22. Win + X — opens the Windows Mobile Application Center (only mobile computers in Windows Vista and 7);
  23. Win + Y — starts Yahoo! Messenger
  24. Win + Pause — opens My Computer
  25. Win + F1 — opens Windows Help
  26. Win + 1 ... 0 — runs or switches to the program pinned to the Taskbar with a specific sequence number 
  27. Win +  Shift + 1 ... 0 — starts a new program pinned to the Taskbar with a specific sequence number 
  28. Win + Ctrl + 1 ... 0 — switches to the last active window of the program that’s pinned to the Taskbar with the specific sequence number 
  29. Win + Alt +1 ... 0 — opens the transitions list for the program pinned to the Taskbar with the specific sequence number 
  30. Win + ↑ — maximizes the active window
  31. Win + ↓ — restores the default window size or minimizes active windows
  32. Win + ← or → — switches the window deployment mode
  33. Win +  Shift + ← or → — switches a window between monitors in multi-monitor set-ups 
  34. Win +  Shift + ↑ or ↓ — stretches the active window from the top to the bottom of the screen and restores the window size
  35. Win + Home — minimizes or restores all non-closed windows, except active ones (only Windows 7), goes to the top of the web page
  36. Win + Space — looks at the desktop (only Windows 7). Changes the layout (only Windows 8 and 10)
  37. Win + + — activates the Magnifier Utility or zooms the image by 100%
  38. Win + — — if the Magnifier Utility is active, the image is reduced by 100%
  39. Win + Esc — disables the Magnifier Utility
Fill free to add more shortcuts, I know there are many more !!