Skip to content

Instantly share code, notes, and snippets.

View susimsek's full-sized avatar
🎯
Focusing

Şuayb Şimşek susimsek

🎯
Focusing
View GitHub Profile
@susimsek
susimsek / BaseEntity.java
Last active November 20, 2020 10:31
Lombok Builder Extends with Jpa
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@MappedSuperclass
public class BaseEntity {
@Id
@GeneratedValue(generator = "UUID")
@susimsek
susimsek / BaseEntity.java
Created November 20, 2020 13:27
Using Basenin Entity in Jpa With Dto Pattern
@SuperBuilder
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@MappedSuperclass
public class BaseEntity {
@Id
@GeneratedValue(generator = "UUID")

Install Virtualbox && Vagrant for MacOSX

Vagrant uses Virtualbox to manage the virtual dependencies. You can directly download virtualbox and install or use homebrew for it.

$ brew cask install virtualbox

Now install Vagrant either from the website or use homebrew for installing it.

@susimsek
susimsek / vagrant-important-commands.md
Created December 4, 2020 11:10
Vagrant Important Commands

Typing vagrant from the command line will display a list of all available commands.

Be sure that you are in the same directory as the Vagrantfile when running these commands!

Creating a VM

  • vagrant init -- Initialize Vagrant with a Vagrantfile and ./.vagrant directory, using no specified base image. Before you can do vagrant up, you'll need to specify a base image in the Vagrantfile.
  • vagrant init <boxpath> -- Initialize Vagrant with a specific box. To find a box, go to the public Vagrant box catalog. When you find one you like, just replace it's name with boxpath. For example, vagrant init ubuntu/trusty64.

Starting a VM

  • vagrant up -- starts vagrant environment (also provisions only on the FIRST vagrant up)
@susimsek
susimsek / docker-important-commands.md
Created December 4, 2020 11:14
Docker and Docker Compose Important Commands

Docker Commands, Help & Tips

Show commands & management commands

$ docker

Docker version info

@susimsek
susimsek / CustomErrorAttributes.java
Created December 12, 2020 18:22
Spring REST Custom Error Handling
@Component
public class CustomErrorAttributes extends DefaultErrorAttributes {
@Override
public Map<String, Object> getErrorAttributes(WebRequest webRequest, ErrorAttributeOptions options) {
Map<String, Object> errorAttributes = new LinkedHashMap();
Map<String, Object> attributes = super.getErrorAttributes(webRequest, options);
long timestamp = ((Date) attributes.get("timestamp")).getTime();
@susimsek
susimsek / VoteRepository.java
Last active December 12, 2020 18:50
Spring Data Jpa Query Example
public interface VoteRepository extends JpaRepository<Vote, Long> {
@Query("SELECT NEW com.example.polls.model.ChoiceVoteCount(v.choice.id, count(v.id)) FROM Vote v WHERE v.poll.id in :pollIds GROUP BY v.choice.id")
List<ChoiceVoteCount> countByPollIdInGroupByChoiceId(@Param("pollIds") List<Long> pollIds);
@Query("SELECT NEW com.example.polls.model.ChoiceVoteCount(v.choice.id, count(v.id)) FROM Vote v WHERE v.poll.id = :pollId GROUP BY v.choice.id")
List<ChoiceVoteCount> countByPollIdGroupByChoiceId(@Param("pollId") Long pollId);
@Query("SELECT v FROM Vote v where v.user.id = :userId and v.poll.id in :pollIds")
List<Vote> findByUserIdAndPollIdIn(@Param("userId") Long userId, @Param("pollIds") List<Long> pollIds);
@susimsek
susimsek / CustomExceptionControllerAdvice.java
Last active September 13, 2023 02:04
Spring Boot File Content Type Validation With Annotation
@ControllerAdvice
public class CustomExceptionControllerAdvice {
@ExceptionHandler(MultipartException.class)
void handleMultipartException(MultipartException ex,HttpServletResponse response) throws IOException {
response.sendError(HttpStatus.BAD_REQUEST.value(),"Please select a file");
}
@ExceptionHandler(ConstraintViolationException.class)
public void handleConstraintViolationException(ConstraintViolationException ex,HttpServletResponse response) throws IOException {
@susimsek
susimsek / AppException.java
Created December 25, 2020 16:09
Spring Boot General Response Status Exceptions
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public class AppException extends RuntimeException {
public AppException(String message) {
super(message);
}
public AppException(String message, Throwable cause) {
super(message, cause);
}
}
@susimsek
susimsek / ForwardedHeaderFilterConfig.java
Last active December 26, 2020 17:24
Spring boot Hateoas Link Change Hostname Using X-Forwarded-* Header
@Configuration
public class ForwardedHeaderFilterConfig {
@Bean
public FilterRegistrationBean<ForwardedHeaderFilter> forwardedHeaderFilter() {
FilterRegistrationBean<ForwardedHeaderFilter> result = new FilterRegistrationBean<>();
result.setFilter(new ForwardedHeaderFilter());
result.setOrder(0);
return result;
}