Skip to content

Instantly share code, notes, and snippets.

View tofusoup429's full-sized avatar

bongkow tofusoup429

View GitHub Profile
const valid_tokens_for_applications = [
"a147549773dfc1830f8568aef1",
"54977dfc1814755683dfaef773"
]
exports.handler = async (event) => {
let {headers:{authorization}} = event;
const response = {
"isAuthorized": valid_tokens_for_applications.includes(authorization)
}
return response;
let result_get = await axios.get(url, {params:params, headers:{Authorization:token}})
let result_post = await axios.post(url, params, {headers:{Authorization:token}});
import {useState, useEffect} from 'react'
export const useCountdown = (startFrom:number, startCountDown:boolean=false, timeoutFunction:any, stopCountingDown:boolean=false) =>{
/*
startFrom: number that the countdown starts from.
startCountDown: turnning this from false to true triggers countdown.
timeoutFunction: a function that will be triggered when countdown reaches 0
stopCountingDown: if it turns true, countdown stops
*/
const [counter, handleCounter] = useState(startFrom);
useEffect(()=>{
const AWS = require('aws-sdk');
AWS.config.update({region: 'us-east-1'}); //Set Region
exports.handler = (event) => {
return new Promise((res, rej)=>{
const sns = new AWS.SNS();
console.log('event', event);
let {phonenumber, message, requestContext} = JSON.parse(event.body);
let {http} = event.requestContext;
if(http.method ==='POST'){
import { useEffect, useState } from 'react';
type SubKey = 'Control'|'Alt'|'Tab'|'Shift'|'NN';
type NodeEnv = 'production'|'development'|'test'
const useKeydown = (nodeEnv:NodeEnv):{subKey:SubKey, mainKey:string} => {
const [subKey, handleSubKey] = useState<'Control'|'Alt'|'Tab'|'Shift'|'NN'>('NN')
const [mainKey, handleMainKey] = useState<string>('')
useEffect(() => {
window.addEventListener('keydown', handleKeydown);
return () => removeEventListener('keydown', handleKeydown)
}, []);
const KeyDown = () => {
useEffect(() => {
window.addEventListener('keydown', handleKeydown);
return () => removeEventListener('keydown', handleKeydown)
}, []);
const doSomething1 = () => {
console.log('doSomething1');
}
{
"body" : $input.json('$'),
"headers": {
#foreach($header in $input.params().header.keySet())
"$header": "$util.escapeJavaScript($input.params().header.get($header))" #if($foreach.hasNext),#end
#end
},
"method": "$context.httpMethod",
"params": {
import {useEffect, useState} from 'react';
import {useCamera} from '@tofusoup429/camera';
import { useWindowSize } from '@tofusoup429/use-window-size';
import LensSharpIcon from '@material-ui/icons/LensSharp';
import LoopIcon from '@material-ui/icons/Loop';
const FullScreenMobileView = () => {
let {width, height} = useWindowSize() // get window width and height as everytime screen resized.
const {captureImage ,imageData, switchCameraFacingMode} = useCamera(); // customHook that contains logics
const [imageDatas, handleImageDatas] = useState<string[]>([]) // capture imageUrls are saved in this state.
import {useEffect, useState} from 'react';
type CameraFacingMode = "environment"|"user"
export const useCamera = ()=> {
const [videoDem, handleVideoDem] = useState<{w:number, h:number}>({w:0, h:0})
const [cameraFacingMode, handleCameraFacingMode] = useState<CameraFacingMode>('environment')
const [imageData, handleImageData] = useState('');
let video:HTMLVideoElement;
let canvas:HTMLCanvasElement;
const months = ["Jan", "Mar", "Mar", "April"];
let febs = ["Feb", "Feb2", "Feb4"];
months.splice(1, 3, ...febs);
console.log(months);
//output: [Jan,Feb,Feb2,Feb4]