Skip to content

Instantly share code, notes, and snippets.

View alvinslee's full-sized avatar

Alvin Lee alvinslee

View GitHub Profile
@alvinslee
alvinslee / logging-primes.py
Last active March 21, 2024 21:29
Demonstrate Logging with Python Primes Example
import logging
from pythonjsonlogger import jsonlogger
from datetime import datetime
import time
import sympy
class JsonFormatter(jsonlogger.JsonFormatter):
def add_fields(self, log_record, record, message_dict):
super(JsonFormatter, self).add_fields(log_record, record, message_dict)
if not log_record.get("timestamp"):
@alvinslee
alvinslee / index.js
Created September 16, 2022 03:21
Salesforce Function - Caching Example
export default async function (event, context, logger) {
logger.info(`Invoking Datafunction with payload ${JSON.stringify(event.data || {})}`);
const redis = await redisConnect();
let cached = {};
// Check Redis for cached entry first
let big_biz_count = await redis.get(`big_biz`);
if (big_biz_count) {
@alvinslee
alvinslee / company.sql
Created September 16, 2022 03:17
Sample dataset for psql
-- This is the file to create COMPANY table and to populate it with 500 records.
-- Just copy and paste this into the psql prompt.
DROP TABLE COMPANY;
CREATE TABLE COMPANY(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
EMPLOYEES INT NOT NULL,
ADDRESS CHAR(50),
MONEY REAL
);
@alvinslee
alvinslee / chatbot-dialogs.csv
Last active May 19, 2022 18:00
Chatbot Dialogs Table
Our dialog name Description
Default The default dialog when a user sends a message. We’ll modify it to greet the user and forward them to “Send location”, “Send menu”, or “Send rewards info” based on user input.
Send location Sends the user a Google Maps link and address, then proceeds to the “Ask to end chat” dialog.
Send menu Sends the user a link to an online menu, then proceeds to the “Ask to end chat” dialog.
Send rewards info Sends the user a link to create a rewards account, then proceeds to the “Ask to end chat” dialog.
Ask to end chat Asks the user if they need anything else, then ends chat or forwards to “User wants more info” based on user input.
User wants more info Asks the user “How else can I help?” then forwards them to “Send location”, “Send menu”, or “Send rewards info” based on user input.
@alvinslee
alvinslee / jit-gateway-create-initial-data.sh
Created February 10, 2022 21:46
Marqeta JIT Gateway demonstration: bash script with curl requests for creating initial data
#!/bin/sh
# From your Marqeta Developer dashboard page
MQ_APPLICATION_TOKEN="INSERT YOUR APPLICATION TOKEN HERE"
MQ_ADMIN_ACCESS_TOKEN="INSERT YOUR ADMIN ACCESS TOKEN HERE"
# Create a mockbin at https://mockbin.org, then insert mockbin URL here
MOCKBIN_URL="INSERT YOUR MOCKBIN URL HERE"
# Make sure to remove trailing slash from the URL
@alvinslee
alvinslee / index.js
Last active January 28, 2022 21:15
Email Sending Example Using SendGrid Node.js SDK
// Make sure you have added @sendgrid/mail to your Node.js project.
//
// Example Usage:
// API_KEY=SG.123456789 CUSTOM_URL=https://www.example.com?campaign_id=my-campaign RECIPIENT_EMAIL=johndoe@gmailx.com node index.js
const sgMail = require('@sendgrid/mail')
sgMail.setApiKey(process.env.API_KEY)
const text = `Please click this link for my email campaign: ${process.env.CUSTOM_URL}`
const html = `Please click <a href="${process.env.CUSTOM_URL}"}this link</a> for my email campaign.`
{
"first_name": "Mike",
"last_name": "John",
"token": "mike_john",
"email": "example@example.com",
"password": "P@ssw0rd",
"identifications": [
{
"type": "SSN",
"value": "111234444"
@alvinslee
alvinslee / marqeta-core-api-demo.py
Last active November 3, 2021 17:37
Demonstration of Marqeta Core API Python SDK
#
# USAGE: APPLICATION_TOKEN=<insert app token> ADMIN_ACCESS_TOKEN=<insert admin token> python3 marqeta-core-api-demo.py
#
import os
from marqeta import Client
application_token = os.environ.get('APPLICATION_TOKEN')
admin_access_token = os.environ.get('ADMIN_ACCESS_TOKEN')
base_url = "https://sandbox-api.marqeta.com/v3/"
@alvinslee
alvinslee / mq-card-product-01
Last active October 21, 2021 08:08
Payload for Create Card Product (no funding source)
{
"token":"card-product-01",
"name":"Card Product (no funding source)",
"start_date": "2021-10-01",
"config": {
"card_life_cycle": {
"activate_upon_issue": true
},
"fulfillment": {
"shipping": {
@alvinslee
alvinslee / marqeta-11.json
Created September 14, 2021 23:48
Marqeta Sample Data payload 11
{
"token":"pepper_j_card_1",
"user_token":"pepper_j",
"fulfillment":{
"card_personalization":{
"text":{
"name_line_1":{
"value":"Johnny P"
},
"name_line_2":{