Skip to content

Instantly share code, notes, and snippets.

View toshvelaga's full-sized avatar
🔥
Koding

Tosh Velaga toshvelaga

🔥
Koding
View GitHub Profile
@toshvelaga
toshvelaga / main.go
Last active April 2, 2022 06:41
main.go for sending emails
package main
// these are the packages we are importing
// if you import it you gotta use it
import (
"fmt"
"log"
"net/smtp"
"os"
@toshvelaga
toshvelaga / useInterval.js
Created March 9, 2022 21:48
useInterval hook
useInterval(() => {
// Your custom logic here
if (isActive) {
youtubeLiveViewCount()
} else return null
}, timer)
@toshvelaga
toshvelaga / youtubeLiveViewCount.js
Created March 9, 2022 21:42
counts the youtube live view count using the google api on the client
const youtubeLiveViewCount = () => {
// https://developers.google.com/youtube/v3/docs/videos/list?apix=true#parameters
return gapi.client.youtube.videos
.list({
part: ['statistics'],
id: youtubeBroadcastId,
})
.then(
function (res) {
@toshvelaga
toshvelaga / youtubeViewCount.js
Created March 9, 2022 21:36
get youtube view count using Node JS
const express = require('express'),
router = express.Router(),
{ default: axios } = require('axios')
require('dotenv').config()
router.post('/api/youtube/view-count', async (req, res) => {
// https://developers.google.com/youtube/v3/docs/videos/list?apix=true&apix_params=%7B%22part%22%3A%5B%22statistics%2C%20status%22%5D%2C%22id%22%3A%5B%22_IrFoihwTUc%22%5D%7D#parameters
const youtubeBroadcastId = req.body.youtubeBroadcastId
@toshvelaga
toshvelaga / twitchViewCount.js
Created March 3, 2022 09:54
server side node function to get view count from twitch
const express = require('express'),
router = express.Router(),
{ default: axios } = require('axios')
require('dotenv').config()
router.post('/api/twitch/view-count', async (req, res) => {
// twitch forum: https://discuss.dev.twitch.tv/t/viewer-counter-help/24726/2
// https://discuss.dev.twitch.tv/t/getting-stream-viewer-count-webhook-notifications/20645/5
@toshvelaga
toshvelaga / twitchViewCount.js
Created March 3, 2022 09:47
using useInterval
useInterval(() => {
// Your custom logic here
if (isActive) {
API.post('/twitch/view-count', {
twitchUsername: twitchUsername,
twitchAccessToken: twitchAccessToken,
})
.then((res) => {
console.log(res.data.number)
if (res.data.number) settwitchViewCount(res.data.number)
@toshvelaga
toshvelaga / useInterval.js
Created March 3, 2022 09:42
custom react hook for polling
import React, { useEffect, useRef } from 'react'
// https://overreacted.io/making-setinterval-declarative-with-react-hooks/
function useInterval(callback, delay) {
const savedCallback = useRef()
// Remember the latest callback.
useEffect(() => {
savedCallback.current = callback
@toshvelaga
toshvelaga / register.js
Created February 16, 2022 03:52
passwordless register page
import React, { useState } from 'react'
import TextInput from '../../components/TextInput/TextInput'
import Button from '../../components/Buttons/Button'
import { Link, useHistory } from 'react-router-dom'
import API from '../../api/api'
import './Register.css'
import setCookie from '../../utils/setCookie'
function Register() {
const [email, setEmail] = useState('')
@toshvelaga
toshvelaga / login.js
Created February 16, 2022 03:47
Passwordless Login Container
import React, { useState, useEffect } from 'react'
import { Link, useHistory, useLocation } from 'react-router-dom'
import API from '../../api/api'
import TextInput from '../../components/TextInput/TextInput'
import Button from '../../components/Buttons/Button'
import setCookie from '../../utils/setCookie'
import './Login.css'
function Login() {
const [email, setEmail] = useState('')
@toshvelaga
toshvelaga / timeFromUserRegistration.js
Last active February 13, 2022 06:36
The time in days from when the user registered to today
const timeFromUserRegistration = (dateUserRegistered) => {
// example of dateUserRegistered = '2021-07-30T05:05:27.000Z'
const userDataRegistered = Date.parse(dateUserRegistered)
const currDate = Date.parse(new Date())
const dateDiff = currDate - userDataRegistered
console.log(dateDiff)
const days = dateDiff / (60 * 60 * 24 * 1000)
return days