Skip to content

Instantly share code, notes, and snippets.

View mmafrar's full-sized avatar

Afrar Malakooth mmafrar

View GitHub Profile
@mmafrar
mmafrar / simple-python-web-server.py
Last active January 30, 2023 00:17
simple-python-web-server
import socket
SERVER_ADDRESS = (HOST, PORT) = '', 8888
REQUEST_QUEUE_SIZE = 5
FILE_SERVER = 'www'
def http_header(code):
if(code == 200):
header = "HTTP/1.1 200 OK\n"
elif(code == 404):
@mmafrar
mmafrar / caeser.py
Created December 19, 2016 20:36
A simple demonstration of Caeser Cipher algorithm implemented using Python.
# Caesar Cipher
import sys
MAX_KEY_SIZE = 26
def getMode():
while True:
print('Do you wish to encrypt or decrypt a message?')
mode = input().lower()
@mmafrar
mmafrar / caeser-bruteforce.py
Created December 19, 2016 20:39
A simple demontration on running a brute force attack on Caeser Cipher encoded text.
# Caesar Cipher
MAX_KEY_SIZE = 26
def getTranslatedMessage(mode, message, key):
if mode[0] == 'd':
key = -key
translated = ''
for symbol in message:
@mmafrar
mmafrar / PrimaryDataSourceConfiguration.java
Created July 26, 2020 13:59
Configuring multiple data sources with Spring Boot 2 and Spring Data JPA
package com.example.demo;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
@mmafrar
mmafrar / SecondaryDataSourceConfiguration.java
Created July 26, 2020 13:59
Configuring multiple data sources with Spring Boot 2 and Spring Data JPA
package com.example.demo;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@mmafrar
mmafrar / FileConfiguration.java
Created January 15, 2021 15:29
Integrating your Spring Boot project with Amazon S3
package com.example.demo;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@mmafrar
mmafrar / FileService.java
Created January 15, 2021 15:38
Integrating your Spring Boot project with Amazon S3
package com.example.demo;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.services.s3.model.S3ObjectInputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@mmafrar
mmafrar / FileController.java
Created January 15, 2021 15:48
Integrating your Spring Boot project with Amazon S3
package com.example.demo;
import com.example.demo.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.CacheControl;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@mmafrar
mmafrar / FileControllerNew.java
Created March 24, 2021 15:46
Working with Amazon S3 presigned URLs in Spring Boot
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@mmafrar
mmafrar / FileServiceNew.java
Created March 24, 2021 15:49
Working with Amazon S3 presigned URLs in Spring Boot
package com.example.demo;
import com.amazonaws.HttpMethod;
import com.amazonaws.services.s3.AmazonS3;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;