Skip to content

Instantly share code, notes, and snippets.

View kirshiyin89's full-sized avatar

Kirshi Yin kirshiyin89

View GitHub Profile
@kirshiyin89
kirshiyin89 / ServerRecordFinder.java
Last active April 27, 2023 07:53
Complete ServerRecordFinder class
import demo.entities.ServerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.persistence.EntityManager;
import javax.persistence.Tuple;
import javax.persistence.TupleElement;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
@kirshiyin89
kirshiyin89 / data.dart
Created June 11, 2021 12:32
Call to Datamuse api to retreive the data.
import 'dart:async';
import 'package:http/http.dart' as http;
import 'dart:convert' as convert;
class BackendService {
static Future<List<Map<String, String>>> getSuggestions(String query) async {
if (query.isEmpty && query.length < 3) {
print('Query needs to be at least 3 chars');
return Future.value([]);
}
@kirshiyin89
kirshiyin89 / material_app.dart
Last active March 20, 2023 15:17
MaterialApp class.
import 'package:flutter/material.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';
import 'data.dart';
class MyMaterialApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Datamuse Autocomplete Demo',
home: MyHomePage(),
@kirshiyin89
kirshiyin89 / qa.py
Last active February 9, 2023 20:02
Question Answering app with Python and Pinecone
import pandas as pd
import itertools
import pinecone
from sentence_transformers import SentenceTransformer
api_key = "YOUR API KEY FROM PINECONE CONSOLE"
pinecone.init(api_key=api_key, environment='us-west1-gcp')
index_name = "question-answering"
@kirshiyin89
kirshiyin89 / RandomNumberGenerator.java
Created November 18, 2022 17:43
Random number generator method
public static int generateNumberFromRange(int maxRange) throws NoSuchAlgorithmException {
Random rand = SecureRandom.getInstanceStrong();
int randomNum;
if (maxRange == 100) {
randomNum = rand.nextInt(maxRange / 2) * 2;
} else {
randomNum = rand.nextInt(maxRange / 2) * 2 + 1;
}
return randomNum;
}
@SpringBootApplication
public class KafkaErrorHandlingApplication {
public static void main(String[] args) {
SpringApplication.run(KafkaErrorHandlingApplication.class, args);
}
}
@kirshiyin89
kirshiyin89 / ProducerController.java
Created October 25, 2022 12:40
produce messages
@RestController
@RequiredArgsConstructor
@Slf4j
public class ProducerController {
private final KafkaTemplate<String, String> kafkaTemplate;
@Value("${topic}")
private String topic;
@kirshiyin89
kirshiyin89 / MyKafkaListener.java
Created October 25, 2022 12:28
the kafka listener implementation
@Component
@Slf4j
public class MyKafkaListener {
@RetryableTopic(
attempts = "5",
topicSuffixingStrategy = TopicSuffixingStrategy.SUFFIX_WITH_INDEX_VALUE,
backoff = @Backoff(delay = 1000, multiplier = 2.0),
exclude = {SerializationException.class, DeserializationException.class}
@kirshiyin89
kirshiyin89 / application.yml
Created October 25, 2022 12:24
app properties
topic: my-topic
server:
port: 8090
spring:
kafka:
bootstrap-servers: http://localhost:29092
properties:
spring.deserializer.value.delegate.class: org.springframework.kafka.support.serializer.JsonDeserializer
security.protocol: PLAINTEXT
@kirshiyin89
kirshiyin89 / docker-compose.yml
Created October 25, 2022 12:22
kafka docker compose
version: '2.1'
networks:
app-tier:
driver: bridge
services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_CLIENT_PORT: 2181