Skip to content

Instantly share code, notes, and snippets.

View mmafrar's full-sized avatar

Afrar Malakooth mmafrar

  • NextLabs
  • Kuala Lumpur, Malaysia
  • LinkedIn in/mmafrar
View GitHub Profile
@mmafrar
mmafrar / sql_dataframe.py
Created April 30, 2025 10:10
Big Data Processing - Case Study 4 (Spark)
from pyspark.sql import SparkSession
# Initialize a Spark session
spark = SparkSession.builder.appName("sql_dataframe").getOrCreate()
# Read the CSV file into a DataFrame, with header and schema inference options enabled
productSales = spark.read.option("header", "true")\
.option("inferSchema", "true").csv("file:///Users/mmafrar/DataRetrieval/Salesstore.csv")
# Print the inferred schema of the DataFrame
@mmafrar
mmafrar / ratings_histogram.py
Created April 26, 2025 04:07
Big Data Processing - Case Study 3 (Spark)
import collections
from pyspark import SparkConf, SparkContext
# Set up the Spark configuration and context
cfg = SparkConf().setMaster("local").setAppName("ratings_histogram")
ctx = SparkContext(conf=cfg)
# Load the data from the specified file
lines = ctx.textFile("file:///Users/mmafrar/Partition/ml-100k/u.data")
print(type(lines)) # Print the type of 'lines' to verify it's an RDD
@mmafrar
mmafrar / wordCount.scala
Created April 23, 2025 23:25
Big Data Processing - Case Study 2 (Spark)
val input_file = sc. textFile("/Users/mmafrar/WordCount/input_file.txt")
input_file.collect
val word = input_file.flatMap(line => line.split(" "))
word.collect
val mapdata = word. map (word => (word, 1))
@mmafrar
mmafrar / Consumer.java
Created February 1, 2022 13:29
Getting Started with Apache Kafka and Spring Boot
package com.example.kafka;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.KafkaHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Service;
@Service
@mmafrar
mmafrar / Producer.java
Created February 1, 2022 13:28
Getting Started with Apache Kafka and Spring Boot
package com.example.kafka;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.SendResult;
import org.springframework.stereotype.Service;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureCallback;
@mmafrar
mmafrar / SpringBootWithKafkaApplication.java
Created February 1, 2022 13:27
Getting Started with Apache Kafka and Spring Boot
package com.example.kafka;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.kafka.config.KafkaListenerEndpointRegistry;
import org.springframework.kafka.listener.MessageListenerContainer;
@mmafrar
mmafrar / application.yaml
Created February 1, 2022 13:11
Getting Started with Apache Kafka and Spring Boot
spring:
kafka:
bootstrap-servers: <BOOTSTRAP_SERVER_URL>
properties:
security:
protocol: SASL_SSL
sasl:
jaas:
config: org.apache.kafka.common.security.plain.PlainLoginModule required username='<CLUSTER_API_KEY>' password='<CLUSTER_API_SECRET>';
mechanism: PLAIN
@mmafrar
mmafrar / ContactServiceTest.java
Created June 28, 2021 17:53
Writing unit tests in Spring Boot with JUnit 5
package com.example.demo.service;
import com.example.demo.model.Contact;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@mmafrar
mmafrar / DemoApplication.java
Created June 6, 2021 00:59
Deploying Spring Boot MVC with JSP project to AWS Elastic Beanstalk
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {
@mmafrar
mmafrar / config.yml
Created May 26, 2021 18:05
Setting up continuous integration in Spring Boot with GitHub and CircleCI
# Java Gradle CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-java/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/openjdk:8-jdk