Skip to content

Instantly share code, notes, and snippets.

View marttp's full-sized avatar
🙇‍♂️
Let's improve equality of developer and make the world better together

Thanaphoom Babparn marttp

🙇‍♂️
Let's improve equality of developer and make the world better together
View GitHub Profile
package dev.tpcoder.application.service;
import dev.tpcoder.application.dto.GetNewsByPreferenceResponse;
import dev.tpcoder.application.dto.GetNewsRequest;
import dev.tpcoder.application.dto.GetNewsResponse;
import dev.tpcoder.application.util.AgentUtil;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@marttp
marttp / AiAgentConfig.java
Created February 10, 2025 06:43
Setup Agent by Spring AI
package dev.tpcoder.application.agent;
import dev.tpcoder.application.dto.GetNewsByPreferenceRequest;
import dev.tpcoder.application.dto.GetNewsByPreferenceResponse;
import dev.tpcoder.application.dto.UserPreferenceRequest;
import dev.tpcoder.application.dto.UserPreferenceResponse;
import dev.tpcoder.application.repository.UserPreferencesRepository;
import dev.tpcoder.application.service.NewsService;
import dev.tpcoder.application.service.agent.GetNewsByUserPreferences;
import dev.tpcoder.application.service.agent.UserPreferencesService;
package dev.tpcoder.application.controller;
import dev.tpcoder.application.agent.AiAgentConfig;
import dev.tpcoder.application.dto.NewSummarized;
import dev.tpcoder.application.util.AgentUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.model.Generation;
@marttp
marttp / application.yaml
Created February 10, 2025 06:30
Spring configurations
spring:
application:
name: spring-ai-function-calling
ai:
openai:
api-key: ${OPEN_API_KEY:}
sql:
init:
mode: always
@marttp
marttp / data.sql
Created February 10, 2025 06:26
Initial data just for demo purpose
INSERT INTO USER_PREFERENCES (id, category) VALUES
(1,'science'),
(2,'technology');
class Solution {
private static final int[][] DIRS = new int[][] {
new int[] {-1,0},
new int[] {1,0},
new int[] {0,-1},
new int[] {0,1}
};
public int[][] updateMatrix(int[][] mat) {
class Solution {
private static final int[][] DIRS = new int[][] {
new int[] {-1,0},
new int[] {1,0},
new int[] {0,-1},
new int[] {0,1}
};
public int maxAreaOfIsland(int[][] grid) {
class Solution {
private static final int[][] DIRS = new int[][] {
new int[] {-1,0},
new int[] {1,0},
new int[] {0,-1},
new int[] {0,1}
};
public int numIslands(char[][] grid) {
@marttp
marttp / Playground.java
Created December 28, 2024 03:23
Binary Search - Iterative - Java
import java.util.List;
public class Playground {
public static void main(String[] args) {
var nums = List.of(1, 2, 3, 15, 35, 53, 81);
System.out.println("Element 35 exists: " + binarySearch(nums, 35));
System.out.println("Element 40 exists: " + binarySearch(nums, 40));
}
@marttp
marttp / cfp-deploy.yml
Created August 19, 2024 02:15
workflow for deploying Leptos to Cloudflare Pages
name: Release to Cloudflare Page
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: write
pages: write