Skip to content

Instantly share code, notes, and snippets.

View toluolatubosun's full-sized avatar

John Olatubosun toluolatubosun

View GitHub Profile
@toluolatubosun
toluolatubosun / expo_notification.js
Last active March 11, 2023 19:11
React Native Expo, Expo notification implementation
import React from "react";
import { Text } from "react-native";
import * as Device from "expo-device";
import * as Notifications from "expo-notifications";
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: true,
shouldSetBadge: true,
@toluolatubosun
toluolatubosun / firebase_cloud_message_with_node.ts
Last active March 11, 2023 13:37
Send Firebase Cloud Message with Node.js
import FirebaseAdmin from "firebase-admin"
const usersNotificationTokens = ["..."]
const serviceAccount = await import("./firebase.json");
FirebaseAdmin.initializeApp({
credential: FirebaseAdmin.credential.cert({
projectId: serviceAccount.project_id,
clientEmail: serviceAccount.client_email,
@toluolatubosun
toluolatubosun / google_authorization_with_GSI.ts
Created December 27, 2022 09:59
Get authorization for users scopes with the new Google Identity Service (GSI) - React Frontend - Node.JS Backend
// Backend with Node.JS
import { google } from "googleapis";
const GOOGLE_CLIENT_ID = process.env.GOOGLE_CLIENT_ID;
const GOOGLE_CLIENT_SECRET = process.env.GOOGLE_CLIENT_SECRET;
const oauth2Client = new google.auth.OAuth2(GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, "http://localhost:3000");
const googleAuthorization = async (response: any) => {
@toluolatubosun
toluolatubosun / google_authentication_with_GSI.ts
Last active December 27, 2022 09:44
Authenticate users with the new Google Identity Service (GSI) - React Frontend - Node.JS Backend
// Backend with Node.JS
import { OAuth2Client } from "google-auth-library";
const googleAuthentication = async (response: any) => {
const { credential } = response;
const client = new OAuth2Client(process.env.GOOGLE_CLIENT_ID);
const ticket = await client.verifyIdToken({
@toluolatubosun
toluolatubosun / buildspec.yml
Created September 23, 2022 21:05
This is my AWS Code Build -> AWS Elastic Beanstalk, build configuration file
version: 0.2
phases:
install:
runtime-versions:
nodejs: latest
commands:
- npm install -g yarn typescript
- yarn install
build:
@toluolatubosun
toluolatubosun / cursor-pagination.ts
Last active September 16, 2022 21:21
This is an Implementation of cursor pagination using Typescript and Mongoose
async getAll(pagination: PaginationInput) {
/* Note:
* - if sorting in descending order then use $lt
* - if sorting in ascending order then use $gt
*/
const { limit = 5, next } = pagination;
var query = {};
const total = await User.countDocuments(query);
const { createAdapter } = require("@socket.io/mongo-adapter");
const MONGODB_URI = "mongodb://localhost:27017/app";
const params = {
useNewUrlParser: true,
useUnifiedTopology: true
};
mongoose.connect(MONGODB_URI, params, async (err, data) => {
if (err) {
@toluolatubosun
toluolatubosun / aws.js
Created June 15, 2022 12:58
AWS File Upload
const AWS = require("aws-sdk");
const { nanoid } = require("nanoid");
const { AWS_S3_BUCKET, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY } = require("./config");
class AWSUtil {
constructor() {
this.s3 = new AWS.S3({
accessKeyId: AWS_ACCESS_KEY_ID,
secretAccessKey: AWS_SECRET_ACCESS_KEY
});
@toluolatubosun
toluolatubosun / linked-list.js
Created May 27, 2022 17:36
Linked List In JavaScript. This is a full implementation of linked lists in JavaScript; Insert to the left or right or at an index, get data at an index, remove by index, reverse list, clear list, print list
// Node Class
class Node {
constructor(data, next = null) {
this.data = data;
this.next = next;
}
}
// Linked List Class
class LinkedList {