Tuesday, October 22, 2019

8 Must Know JavaScript Array Methods

Working with arrays in JavaScript used to be a pain with barely any support for complex array operations. Fast forward to today, though, and there are tons of amazing JavaScript array methods available to us. In this video I will be covering the 8 most important array methods in JavaScript.


const items =[
{ name: 'Bike', price:100},
{ name: 'TV', price:200},
{ name: 'Album', price:10},
{ name: 'Book', price:5},
{ name: 'Phone', price:500},
{ name: 'Computer', price:1000},
{ name: 'Keyboard', price:25}
]

// create another array with filtered items
const filteredItems = items.filter((item) => {
return item.price <= 100
})

console.log(filteredItems);



// get element and create another array 
const itemNames = items.map((item) => {
     return item.name
});

console.log(itemNames)


//find element in array
const foundItem = items.find((item) =>{
return item.name === 'Album'
})
console.log(foundItem)


//forEach 
items.forEach((item) =>{
console.log(item.price)
})


// some -- return true if found
const hasInExpensiveItem = items.some((item) =>{
   return item.price <= 100
})
console.log(hasInExpensiveItem)

// calculate with variable initiate as 0
const total = items.reduce((currentTotal, item){
    return item.price + currentTotal
},0) // 0 is the initial value of CurrentTotal

console.log(total)

// include -- if item present in array return true.. this work fine with simple array...

const items =[1, 2, 3, 4, 5]
const includesTwo = items.includes(2)
console.log (includesTwo) // return True..

const includesTwo = items.includes(6)
console.log (includesTwo) // return false..


// distinct from array


var distinct = (value, index, self) =>{
   return self.indexOf(value) === index;
}

var years = [2016, 2017, 2017, 2020, 2016, 2019]
var distinctYears = years.filter(distinct)

output : [2016, 2017, 2020, 2019]



Thanks to Web Dev Simplified and codeburst

Friday, October 18, 2019

PrintQueue.Purge Method

Code help to Purge Network/Local Print .

Dim ps = New LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer)
Dim pq = New PrintQueue(ps, ps.DefaultPrintQueue.FullName, 

PrintSystemDesiredAccess.AdministratePrinter)

If pq.NumberOfJobs > 0 Then
pq.Purge()
End If

Tuesday, August 20, 2019

Convert JSON to CSV Format

This is common thing now a days we have all data in JSON and when we have to sent it as a csv file we need to convert. Following code found stackoverflow.com, and credit goes to developer. I am putting into my blog for easy access and reference to my blog reader.

//logData is the JSON object having json data, rest of the code do the job.

const items = logData
const replacer = (key, value) => value === null ? '' : value 
const header = Object.keys(items[0])
let csv = items.map(row => header.map(fieldName => JSON.stringify(row[fieldName], replacer)).join(','))
csv.unshift(header.join(','))
csv = csv.join('\r\n')

console.log(csv)


Thursday, August 8, 2019

The Fastest Way to Your Share Location from an iPhone


There are a couple ways to share your location, but this might be the quickest! Here's how to share your location from your iPhone in a text message using predictive text. For this tip, you'll have to have both Predictive Text and Location Services enabled. And if you're not connected to Wi-Fi, you'll have to enable Apple Maps too.

How to Share Directions in Apple & Google Maps

If you're meeting up with someone in a large area like a park or can't talk on the phone to give directions, sharing your location in a text message can really help! To do this:

Open a new or previously opened text chat with the person you want to share your location with.

  1. Type the phrase "I'm at" and press the spacebar after the word "at".
  2. In the predictive text area of the keyboard, tap Current Location.
  3. The other person will be sent your location via Apple Maps.
  4. Notice that only the map will show up in the text chat. You'll need to press the blue arrow to send the text message you've typed.

Reference from site : iphonelife.com

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.