Skip to content

Instantly share code, notes, and snippets.

View ufuk's full-sized avatar
🤔

Ufuk Uzun ufuk

🤔
View GitHub Profile
@ufuk
ufuk / run-simple-http-server.sh
Last active January 21, 2017 14:40
SimpleHTTPServer is a simple HTTP server that provides standard GET and HEAD request handlers. Default port is 8000.
#!/bin/bash
python -m SimpleHTTPServer
@ufuk
ufuk / find-out-slower-tests.sh
Last active January 5, 2021 09:48
Lists test classes descending ordered by elapsed time to find out which ones are slower than others. Run this BASH script at project's root.
#!/bin/bash
# Run tests
mvn clean test --fail-never
# Print header
echo
echo "TEST NAME, TESTS COUNT, FAILURES COUNT, ERRORS COUNT, SKIPPED COUNT, TIME ELAPSED"
# Prepare report
@ufuk
ufuk / find-out-stale-branches.sh
Last active October 31, 2017 08:35
Lists git branches ordered by last change time to find out which ones are stale branches.
#!/bin/bash
# DESCRIPTION
# -----------
#
# Produces CSV output like this:
#
# LAST CHANGE TIME, TIME ELAPSED, AUTHOR, BRANCH
# 2017-01-16 14:56:26 +0000, 3 months ago, john.doe@example.com, origin/bug-fix-1
# 2017-01-23 18:27:53 +0300, 2 months ago, john.doe@example.com, origin/new-feature-1
@ufuk
ufuk / RestTemplateCanNotReadResponseBodyWhenHTTPStatus401.java
Last active November 30, 2016 19:00
Spring RestTemplate Issue - Can't read response body when the HTTP request has return status 401
// Use HttpComponentsClientHttpRequestFactory to fix the issue
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
...
RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
@ufuk
ufuk / ComparingUtils.java
Last active September 2, 2020 13:41
Fluent API for comparing two Comparables.
public class ComparingUtils {
public static <T extends Comparable<T>> ComparisonBuilder<T> is(T comparable) {
return new ComparisonBuilder<>(comparable);
}
public static class ComparisonBuilder<T> {
private Comparable<T> subject;
@ufuk
ufuk / StartEndTimeWithJodaTime.java
Created October 24, 2016 09:09
Joda-Time library provides us a Virtual Clock utility named "DateTimeUtils". This is a demonstration for mocking start-end times.
import org.joda.time.DateTime;
public class StartEndTimeWithJodaTime {
private DateTime startTime;
private DateTime endTime;
public void process() {
startTime = DateTime.now();
@ufuk
ufuk / LazyDeveloper.java
Last active July 6, 2025 21:37
Just another reason to why you shouldn't use Lombok, in another saying another reason to why you should write unit tests: You have two fields in your class. Fields are in the same type. You use @AllArgsConstructor to auto-generate your all args constructor. It works for a moment, until you change the order of the field.
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class LazyDeveloper {
private String firstName;
private String lastName;
@ufuk
ufuk / HowToGetHttpServletRequestAndResponseProgrammatically.java
Created October 6, 2016 11:31
To get the request and response objects in Spring MVC projects you can use this code
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
HttpServletRequest httpServletRequest = servletRequestAttributes.getRequest();
HttpServletResponse httpServletResponse = servletRequestAttributes.getResponse();
@ufuk
ufuk / Child.java
Last active October 5, 2016 21:14
Workaround for Project Lombok's builders with inheritance issue.
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class Child extends Parent {
private String childField_1;
@ufuk
ufuk / EntityBuilder.java
Created August 16, 2016 07:04
ObjectBuilder & EntityBuilder
import ...BaseEntity;
import org.apache.commons.lang.math.RandomUtils;
import org.hibernate.Session;
public class EntityBuilder<T extends BaseEntity> extends ObjectBuilder<T> {
@Override
public EntityBuilder<T> set(String fieldName, Object value) {
return (EntityBuilder<T>) super.set(fieldName, value);
}