Skip to content

Instantly share code, notes, and snippets.

View aksOps's full-sized avatar
:octocat:
Working from home

Amit Kumar aksOps

:octocat:
Working from home
View GitHub Profile
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version> <!-- Use a recent Spring Boot 3 version -->
<relativePath/> <!-- lookup parent from repository -->
</parent>
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;
@Component
public class ProxyHandler {
private final RoutingService routingService;
@aksOps
aksOps / ChatMessageStoredEntity.ts
Last active May 24, 2025 18:44
TypeORM Langchain
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, Index } from 'typeorm';
import { StoredMessage } from '@langchain/core/messages';
@Entity('chat_messages_lc') // Using '_lc' suffix to denote Langchain specific table
export class ChatMessageStoredEntity {
@PrimaryGeneratedColumn('uuid')
id!: string;
@Index() // Index sessionId for faster querying
@Column()
Connecting to Azure SQL Database from a Next.js application using DefaultAzureCredential and an ORM in TypeScript allows for passwordless, secure, and environment-aware authentication. This approach is highly recommended as DefaultAzureCredential automatically handles various authentication scenarios, such as using your Azure CLI or Visual Studio Code credentials during local development, or a Managed Identity when deployed to Azure services.
This guide will primarily focus on TypeORM, which offers more straightforward integration for this authentication method with Azure SQL. We will also briefly discuss considerations for Prisma.
Current Date: May 19, 2025
Key Technologies:
Next.js: React framework for server-rendered applications.
TypeScript: For type safety.
import React, { CSSProperties, forwardRef, ReactNode, useEffect, useMemo } from 'react'; // Added useMemo
import { motion, useAnimation } from 'framer-motion';
import { Sparkles as ButtonIcon } from 'lucide-react';
// --- Define Types and Props ---
// Define possible button sizes, including x-small
type ButtonSize = 'x-small' | 'small' | 'normal' | 'large'; // Added 'x-small'
// Props for the underlying custom button (remains the same)
@aksOps
aksOps / Curly Braces regex
Last active October 23, 2024 16:25
Curly Braces regex
const escapeCurlyBraces = (text) => {
// This regex matches any number of consecutive curly braces
return text.replace(
/({{+)((?:[^{}]|{{|}})*)(}})+/g,
(match, openBraces, content, closeBraces) => {
const escapedOpen = openBraces.replace(/{{/g, "{$");
const escapedClose = closeBraces.replace(/}}/g, "$}");
return `${escapedOpen}${content}${escapedClose}`;
}
);
import { useState, useEffect } from "react"
export const useBaseStorageState = (
storage,
storageKey,
defaultValue,
live = false
) => {
// Get value from storage, if not use default value
const [state, setState] = useState(() => {