Skip to content

Instantly share code, notes, and snippets.

View satomiichii's full-sized avatar
🍜

satomiichii

🍜
View GitHub Profile

Min Subarray Length

Prompt

Write a function called minSubArrayLen which accepts two parameters - an array of positive integers and a positive integer. This function should return the minimal length of a contiguous subarray of which the sum is greater than or equal to the integer passed to the function. If there isn't one, return 0 instead.

Example

@satomiichii
satomiichii / Push
Last active February 19, 2021 14:45
Push Route
const router = require('express').Router()
const {User, Subscription} = require('../db/models')
const webPush = require('web-push')
module.exports = router
router.post('/', async (req, res, next) => {
try {
// Our app has 4 defferent option for reminder, so depends on
// which reminder gets called, payload is changed.
@satomiichii
satomiichii / callSubfunc
Last active February 19, 2021 05:01
Home Component
import React from 'react'
import {connect} from 'react-redux'
import {handleSubscription} from '../../public/main'
export class UserHome extends React.Component {
//other code are omited
async componentDidMount() {
try {
await handleSubscription(this.props.user)
@satomiichii
satomiichii / subscriptionApi
Last active October 22, 2023 18:30
Subscribe route
const router = require('express').Router()
const {User, Subscription} = require('../db/models')
module.exports = router
router.post('/:userId', async (req, res, next) => {
try {
const userId = req.params.userId
const data = req.body
//subscription object has 3 properties and the value of the 'keys' property is a nested object, so
//to store the value in PostgreSQL, it has to be stringified.
@satomiichii
satomiichii / subscription
Last active October 22, 2023 18:10
Push subscription
export const handleSubscription = (user) => {
'use strict'
const axios = require('axios')
let isSubscribed = false
let swRegistration = null
let anyReminder = false
//user object holds the user's reminder opt-in status as boolean.
//checking if the user opted-in any of our reminder option
if (Object.values(user).some((val) => val === true)) anyReminder = true
@satomiichii
satomiichii / pushEvent.txt
Last active February 18, 2021 19:52
Push eventListner in SW
self.addEventListener('push', (event) => {
let body
if (event.data) {
//You can set an original message by passing it on the event.
body = event.data.text()
} else {
body = 'Default body'
}
const options = {