Skip to content

Instantly share code, notes, and snippets.

View weisisheng's full-sized avatar

Vince Fulco--Bighire.tools weisisheng

View GitHub Profile
@guest271314
guest271314 / bench.js
Last active January 20, 2025 12:39
TypeScript .ts file execution benchmarks for Deno, Bun, Node.js
Deno.bench("Deno, Bun, Node.js TypeScript Benchmarks", async (b) => {
// Open a file that we will act upon.
// using file = await Deno.open("a_big_data_file.txt");
// Tell the benchmarking tool that this is the only section you want
// to measure.
b.start();
// Now let's measure how long it takes to read all of the data from the file.
// await new Response(file.readable).arrayBuffer();
@sspaeti
sspaeti / query_read_bsky_feed.duckdb.sql
Created October 30, 2024 09:13
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,
@robertvanhoesel
robertvanhoesel / form.ts
Last active March 26, 2025 05:19
Astro createForm implementation
import { getZodConstraint, parseWithZod } from "@conform-to/zod"
import type { HTMLAttributes } from "astro/types"
import { ZodAny, z, type ZodIssue } from "zod"
export type Constraint = ReturnType<typeof getZodConstraint>[0]
export type FieldAttributes = {
name: string
value: string
type: NonNullable<HTMLAttributes<"input">["type"]>
} & Partial<Record<Lowercase<keyof Constraint>, any>>
set -e
DB_FILE_FULL_PATHG=$1
DB_FILE_PARENT_FOLDER=$(dirname $DB_FILE_FULL_PATHG)
DB_FILE_NAME=$(basename $DB_FILE_FULL_PATHG)
ngrok http file://$DB_FILE_PARENT_FOLDER --log=stdout >/dev/null &
sleep 1
@jeroos
jeroos / gist:c4336e8e177ab634a91968431d8af4cd
Last active March 13, 2025 07:58
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)}
@gdagley
gdagley / EventStack.ts
Created November 8, 2023 13:48
Simplify adding EventBus rules to SST
import {Config, EventBus, EventBusRuleProps, Queue, Stack, StackContext, Table} from "@serverless-stack/resources";
const snakeToCamel = (s: string) => s.replace(/(_\w)/g, k => k[1].toUpperCase());
const addBusinessRule = (stack: Stack, bus: EventBus, dlq: Queue, eventType: string) => {
const ruleKey = eventType.replace(".", "_");
const queueName = `${ruleKey}_queue`;
const handlerLambda = `functions/events/${snakeToCamel(ruleKey)}/handler.main`;
const rules: Record<string, EventBusRuleProps> = {};
@zacwellmer
zacwellmer / datetime-picker.tsx
Last active January 7, 2025 22:53
shadcn datetime picker component
"use client"
import { CalendarDateTime, isToday as _isToday, } from "@internationalized/date";
import { format } from "date-fns";
import { CalendarIcon, ClockIcon } from "lucide-react";
import { useRef, useState } from "react";
import { DateValue, TimeValue, useDateSegment, useInteractOutside, useLocale, useTimeField } from "react-aria";
import { DateFieldState, DatePickerStateOptions, DateSegment as IDateSegment, useDatePickerState, useTimeFieldState } from "react-stately";
import { cn } from "../lib/utils";
// imports from shadcn/ui
import { Button } from "./ui/button";
@fnimick
fnimick / supabase_profile_sync.sql
Last active April 3, 2025 15:08
Create a `public.profile` table and keep it in sync with supabase `auth.users` for selected fields in both directions.
/**
* USERS
* Note: This table contains user data. Users should only be able to view and update their own data.
* Some data is synced back and forth to `auth.users` as described below.
*
* `full_name`: synced in both directions
* `email`: synced from user metadata to profile only
* `avatar_url`: synced from user metadata to profile only
* `terms_accepted_at`: synced from profile to user metadata only
*/
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;
@yuming-long
yuming-long / langchain_js_test.md
Last active April 8, 2025 18:13
langchain js test doc
  1. brew install npm
  2. npm install langchain
  3. make sure the package.json looks like
{
 "name": "your-project-name",
 "type": "module",
 "dependencies": {
"langchain": "^0.0.95"