Skip to content

Instantly share code, notes, and snippets.

View weisisheng's full-sized avatar

Vince Fulco--Bighire.tools weisisheng

View GitHub Profile
@weisisheng
weisisheng / try-catch.ts
Created March 31, 2025 11:11 — forked from t3dotgg/try-catch.ts
Theo's preferred way of handling try/catch in TypeScript
// Types for the result object with discriminated union
type Success<T> = {
data: T;
error: null;
};
type Failure<E> = {
data: null;
error: E;
};
@weisisheng
weisisheng / query_read_bsky_feed.duckdb.sql
Created November 11, 2024 13:27 — forked from sspaeti/query_read_bsky_feed.duckdb.sql
Reading bsky posts with DuckDB example.
-- Query the API directly and flatten the nested JSON structure
WITH raw_data AS (
SELECT * FROM read_json_auto('https://public.api.bsky.app/xrpc/app.bsky.feed.getAuthorFeed?actor=did:plc:edglm4muiyzty2snc55ysuqx&limit=10')
),
unnested_feed AS (
SELECT unnest(feed) as post_data FROM raw_data
)
SELECT
-- Post basics
post_data.post.uri as post_uri,
@weisisheng
weisisheng / gist:1063091936d01f0e218e787f6d23087c
Created September 19, 2024 14:14 — forked from jeroos/gist:c4336e8e177ab634a91968431d8af4cd
Streamlining AWS Lambda with DuckDB for Dynamic Data Handling
import json
import os
import duckdb
import boto3
import datetime
from typing import Any, Dict
def construct_prepared_sql_and_params(sql_template, bind_params):
single_value_params = {k: v for k, v in bind_params.items() if not isinstance(v, list)}
const AWS = require("aws-sdk");
const csv = require("csv-parser");
const { Readable } = require("stream");
const simpleParser = require("mailparser").simpleParser;
const s3 = new AWS.S3();
const documentClient = new AWS.DynamoDB.DocumentClient();
const TableName = process.env.TABLE;
@weisisheng
weisisheng / tinymce-react-nextjs.md
Created February 5, 2023 13:16 — forked from zhangshine/tinymce-react-nextjs.md
NextJs- React - Self hosted TinyMCE
  1. Install (TinyMCE 5.x)
npm install --save tinymce @tinymce/tinymce-react copy-webpack-plugin
  1. Copy static files(tinymce skins) to public folder. Edit file next.config.js
const path = require('path');
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
@weisisheng
weisisheng / dynamoExportAndConvert.js
Created January 31, 2023 02:15 — forked from mtliendo/dynamoExportAndConvert.js
Export and Convert Dynamo Table to JavaScript JSON
//! How to get all records from a Dynamo DB Table and store as regular JSON
// 1. Run the following command in the terminal
// * Note that the output will be in Dynamo JSON format
// aws dynamodb scan --region REGION --profile PROFILE_NAME --table-name TABLE_NAME > exports.json
// 2. Convert from Dynamo JSON to regular JSON.
const AWS = require('aws-sdk')
const fs = require('fs')
@weisisheng
weisisheng / jserv.py
Created November 23, 2022 08:09 — forked from kinoc/jserv.py
Simplest FastAPI endpoint for EleutherAI GPT-J-6B
# Near Simplest Language model API, with room to expand!
# runs GPT-J-6B on 3090 and TITAN and servers it using FastAPI
# change "seq" (which is the context size) to adjust footprint
#
# seq vram usage
# 512 14.7G
# 900 15.3G
# uses FastAPI, so install that
# https://fastapi.tiangolo.com/tutorial/
@weisisheng
weisisheng / sample-resume.json
Created October 18, 2022 23:29 — forked from ishu3101/sample-resume.json
Sample Resume in JSON Resume Format
{
"basics": {
"name": "Your first and last name",
"label": "",
"picture": "",
"email": "Your email address",
"phone": "A phone number, with any formatting you like. E.g. (555) 555-5555.",
"degree": "",
"website": "Your website URL",
"summary": "A one-sentence to one-paragraph overview text. Do not include any line-breaks.",
@weisisheng
weisisheng / !calling-lambda-cross-account.md
Created October 15, 2022 05:27 — forked from helephant/!calling-lambda-cross-account.md
Calling a lambda in another AWS account by assuming a cross-account IAM role

Set up a cross-account IAM role in the destination account

  • Add a new IAM role
  • For type of trusted entity select "another AWS account"
  • Specify the accountId of the account that will be using the resource in the destination account. You can find your AWS Account ID, which is available on the support homepage when you are logged in.
  • Create a policy that allows lambda:InvokeFunction for your function and attach it to this new role.

Create a lambda in the calling account.

  • Set up a role for your lambda that is allowed to assumeRole
  • Use the AWS SDK to assume the new role in the destination account.
  • Pass the credentials to the lambda object when you create it
@weisisheng
weisisheng / app.py
Created April 15, 2022 12:12 — forked from yashprakash13/app.py
FastApi example
import uvicorn
from fastapi import FastAPI
from model import SentimentModel, SentimentQueryModel
app = FastAPI()
model = SentimentModel()
@app.post('/predict')
def predict(data: SentimentQueryModel):
data = data.dict()