Skip to content

Instantly share code, notes, and snippets.

View nidhi-canopas's full-sized avatar

nidhi-canopas

View GitHub Profile
<script>
beforeUnmount() {
console.log("I'm beforeUnmount hook");
this.$refs.img.width = 0;
},
</script>
<script>
unmounted() {
console.log("I'm unmounted hook");
this.$refs.img.width = 0;
},
</script>
<template>
<div ref="greeting">Hello readers !</div>
<img ref="img" :src="img" alt="image" width="200" />
<span>comment/uncomment me to see beforeUpdate/updated hook's reactivity</span>
</template>
<script>
export default {
setup() {
console.log("I'm setup hook");
@nidhi-canopas
nidhi-canopas / array_methods.ts
Last active December 16, 2022 06:38
Typescript : Array methods
1. // check whether element exists in an array
function checkIndexOf() {
let emojis:string[] = ['😎️', '🤓️', '🤩️', '😇️']
console.log(emojis.indexOf('🤩️') !== -1)
}
// output:
true
func AddDays(t time.Time, days int) time.Time {
fmt.Println("currentTime: ", t)
// AddDate(years int, months int, days int)
newTime := t.AddDate(0, 0, days)
fmt.Println("newTime: ", newTime)
return newTime
}
func StartOfDay(t time.Time, timezone string) time.Time {
location, _ := time.LoadLocation(timezone)
year, month, day := t.In(location).Date()
fmt.Println("currentTime: ", t)
dayStartTime := time.Date(year, month, day, 0, 0, 0, 0, location)
fmt.Println("StartOfDay: ", dayStartTime)
func EndOfDay(t time.Time, timezone string) time.Time {
location, _ := time.LoadLocation(timezone)
year, month, day := t.In(location).Date()
fmt.Println("currentTime: ", t)
dayEndTime := time.Date(year, month, day, 23, 59, 59, 0, location)
fmt.Println("EndOfDay: ", dayEndTime)
func IsSameDay(first time.Time, second time.Time) bool {
return first.YearDay() == second.YearDay() && first.Year() == second.Year()
}
/* Check if given two days are same */
func main() {
location, _ := time.LoadLocation("Asia/Kolkata")
first := time.Date(2022, time.July, 01, 12, 30, 20, 0, location)
func DiffInDays(start time.Time, end time.Time) int {
return int(end.Sub(start).Hours() / 24)
}
/* difference between two timestamps */
func main() {
location, _ := time.LoadLocation("Asia/Kolkata")
start := time.Date(2022, time.July, 01, 12, 30, 20, 0, location)
end := time.Date(2022, time.July, 31, 15, 0, 50, 0, location)
fmt.Println("Days between start and end: ", DiffInDays(start, end))
func IsLeapYear(year int) bool {
return year%4 == 0 && year%100 != 0 || year%400 == 0
}
/* check for leap year */
fmt.Println("2020 is leap year: ", IsLeapYear(2020))
//output: