Skip to content

Instantly share code, notes, and snippets.

@OmarKhattab
OmarKhattab / sms-twilio.js
Created November 29, 2020 21:15
Lambda Functions For SMS Verification
export const sendSMSVerificationCode = async (event, context, callback) => {
try {
context.callbackWaitsForEmptyEventLoop = false;
await connectToDB();
const data = JSON.parse(event.body);
const { phone } = data;
console.log(phone);
const code = Math.floor(1000 + Math.random() * 9000);
let user;
@OmarKhattab
OmarKhattab / xrp-to-coinbase.js
Created November 25, 2020 04:04
send xrp to coinbase
"use strict";
const RippleAPI = require("ripple-lib").RippleAPI;
const address = "THE ADDRESS OF YOUR WALLET";
const secret = "THE SECRET KEY FOR YOUR WALLET";
const api = new RippleAPI({ server: "wss://s1.ripple.com:443" });
const instructions = { maxLedgerVersionOffset: 5 };
const payment = {
@OmarKhattab
OmarKhattab / charge-customer.js
Created November 19, 2020 06:43
charge customer and transfer money to connected account
const paymentMethods = await stripe.paymentMethods.list({
customer: stripeCustomerID,
type: "card",
});
const payment_method = paymentMethods.data[0].id;
const paymentIntent = await stripe.paymentIntents.create({
payment_method_types: ["card"],
amount: 1000,
customer: stripeCustomerID,
payment_method,
import React, { useState, useContext, useEffect } from "react";
import { DashboardContext } from "../../../../../shared/context";
import { WebView } from "react-native-webview";
import { CORE_API_URL } from "../../../../../shared/api";
import { PageLoading } from "../../../../../assets/animations/loading";
import axios from "axios";
const AddPaymentMethod = () => {
const context = useContext(DashboardContext);
const { user, setUser, setUserStripeAccount } = context;
const [sessionId, setSessionId] = useState(null);
@OmarKhattab
OmarKhattab / stripe-checkout-client.js
Created November 19, 2020 02:25
stripe and redirecToCheckout
import React, { useEffect } from "react";
import { useParams } from "react-router-dom";
import { loadStripe } from "@stripe/stripe-js";
const StripeCheckout = () => {
const params = useParams();
console.log(params);
const { id } = params;
useEffect(() => {
const asyncFunc = async () => {
@OmarKhattab
OmarKhattab / checkout.js
Created November 19, 2020 02:17
stripe checkout
const customer = await stripe.customers.create();
const { id } = customer
const session = await stripe.checkout.sessions.create({
customer: id,
payment_method_types: ["card"],
mode: "setup",
success_url: `${host}/stripe-checkout-status?success=true`,
cancel_url: `${host}/stripe-checkout-status?errors=true`,
[
{
"uid": "d435473e-5937-4c66-8694-688319057562",
"title": "Where do you want to stay?",
"type": "multipleChoice",
"answers": [
{
"uid": "bbb-1",
"label": "San Francisco"
},
package api
import (
"server/api/apierror"
"server/slog"
"server/store"
)
// VerifyUserIdentity allows a user to mark there identity verification method as skipped to allow booking in the ios app
// Products: ios app
@OmarKhattab
OmarKhattab / private_route.js
Last active July 21, 2020 01:00
Private Route React Router Dom
import React, { useEffect } from 'react';
import { Route, useHistory } from 'react-router-dom';
import jwt from 'jsonwebtoken';
const PrivateRoute = ({ children, ...rest }) => {
const history = useHistory();
useEffect(() => {
const onMount = async () => { // create an async function
let localStorageUser = localStorage.getItem('user'); // check if user exists in localstorage
let isValid = true; // is the json web token still valid?
if (localStorageUser) {
@OmarKhattab
OmarKhattab / gist:2d19983f64cd07472cda8e7d8a55a61a
Created May 1, 2020 23:44
Leet Code First Bad Version Javascript Solution
/**
* Definition for isBadVersion()
*
* @param {integer} version number
* @return {boolean} whether the version is bad
* isBadVersion = function(version) {
* ...
* };
*/