Skip to content

Instantly share code, notes, and snippets.

View hkemon's full-sized avatar
🙍‍♂️
Forever Learner

Humayoun Kabir Emon hkemon

🙍‍♂️
Forever Learner
View GitHub Profile
@hkemon
hkemon / Jenkinsfile
Created August 15, 2021 11:18 — forked from merikan/Jenkinsfile
Some Jenkinsfile examples
Some Jenkinsfile examples
@hkemon
hkemon / mongodb_cheat_sheet.md
Created November 1, 2020 09:24 — forked from bradtraversy/mongodb_cheat_sheet.md
MongoDB Cheat Sheet

MongoDB Cheat Sheet

Show All Databases

show dbs

Show Current Database

@hkemon
hkemon / ConsumerThread.java
Last active October 16, 2020 19:17
Kafka Consumer Using Thread.
package com.emon;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.errors.WakeupException;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@hkemon
hkemon / KafkaConsumerDemo01.java
Created June 10, 2020 18:03
Kafka Raw Consumer Demo
Properties properties = new Properties();
properties.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "127.0.0.1:9092");
properties.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
properties.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
properties.setProperty(ConsumerConfig.GROUP_ID_CONFIG, "my-first-application");
properties.setProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
try (KafkaConsumer<String, String> consumer = new KafkaConsumer<>(properties)) {
consumer.subscribe(Collections.singleton("first_topic"));
@hkemon
hkemon / KafkaProducer02.java
Last active June 11, 2020 17:33
Kafka Raw Producer Creation & Callback Return
// Create Producer Properties
Properties properties = new Properties();
properties.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "127.0.0.1:9092");
properties.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
properties.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
// Create Safe Producer
properties.setProperty(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, "true");
properties.setProperty(ProducerConfig.ACKS_CONFIG, "all");
properties.setProperty(ProducerConfig.RETRIES_CONFIG, Integer.toString(Integer.MAX_VALUE));
properties.setProperty(ProducerConfig.MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION, "5");
@hkemon
hkemon / KafkaProducer01.java
Created June 10, 2020 17:11
Kafka Raw Producer Creation
Properties properties = new Properties();
properties.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "127.0.0.1:9092");
properties.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
properties.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
try (KafkaProducer<String, String> producer = new KafkaProducer<>(properties)) {
ProducerRecord<String, String> record = new ProducerRecord<>("first_topic","hello world");
producer.send(record);
producer.flush();
}
@hkemon
hkemon / SplitStringUsingPattern.java
Created May 28, 2020 07:23
split string using pattern matching java
import java.util.regex.Pattern;
public class PatternDemo {
private static String REGEX = ":";
private static String INPUT = "boo:and:foo";
public static void main(String[] args) {
Pattern pattern = Pattern.compile(REGEX);
String[] result = pattern.split(INPUT);
@hkemon
hkemon / InfluxDbSpringBean.java
Last active January 7, 2022 05:39
Influx Db Spring Bean Configuration updated
@Bean
public InfluxDB influxDb() {
final String serverUrl = influxDbUrl;
final String username = influxDbUser;
final String password = influxDbPassword;
final InfluxDB influxDb = InfluxDBFactory.connect(serverUrl, username, password);
String databaseName = influxDbDatabase;
influxDb.setDatabase(databaseName);
influxDb.enableBatch(BatchOptions.DEFAULTS.actions(100).flushDuration(1000));
return influxDb;