Skip to content

Instantly share code, notes, and snippets.

View ufuk's full-sized avatar
🤔

Ufuk Uzun ufuk

🤔
View GitHub Profile
@ufuk
ufuk / DistributedLock.java
Last active July 14, 2024 08:54
Distributed lock solution for Spring projects, using aspect and Redis
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.concurrent.TimeUnit;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface DistributedLock {
@ufuk
ufuk / hsqldb-with-postgresql-syntax.properties
Last active February 18, 2025 08:56
To use HSQLDB with PostgreSQL syntax add ";sql.syntax_pgs=true" to end of the JDBC URL. Alternatively use ";sql.syntax_ora=true" for Oracle.
spring.datasource.url=jdbc:hsqldb:mem:testdb;sql.syntax_pgs=true
@ufuk
ufuk / LoggingObjectMapper.java
Created April 20, 2017 11:37
JSON serializing with masking support...
import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair;
public final class LoggingObjectMapper extends ObjectMapper {
private static final long serialVersionUID = -1620079742091329228L;
public LoggingObjectMapper() {
super();
@ufuk
ufuk / uniq-lines-with-grep.sh
Created May 28, 2017 21:07
Searching some text and getting unique result lines with grep
grep "search text" filename.txt | sort | uniq
@ufuk
ufuk / AsyncConfiguration.java
Last active December 10, 2022 21:43
The easy way to disable @ Async annotation for test contexts. Same approach can be used to disable @ Scheduled annotation as well.
package ...configuration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.EnableAsync;
@Configuration
@EnableAsync
@Profile("!test")
public class AsyncConfiguration {
@ufuk
ufuk / siege-post-json.sh
Last active April 14, 2023 16:37
Siege command to benchmark POST method with JSON payload and headers example. ("-c" for concurrent request count) ("-t" for time) ("-H" for header)
siege -c50 -t5S -H 'Content-Type: application/json' -H 'access-token: ...' 'http://localhost:8080/... POST {"...": "...", ...}'
@ufuk
ufuk / find-largest-10-directories.sh
Last active July 9, 2017 19:22
Helps you to find out largest 10 directories in the current working directory in a UNIX system. (Command to see disk usage: df -h)
du -a . | sort -n -r | head -n 10
@ufuk
ufuk / concatenate-grep-and-split-by-delimeter.sh
Created July 10, 2017 09:08
Concatenate files, grep lines, split by a delimeter using awk and print some columns as sorted and uniqe. May be useful for parsing logs.
cat file1 file2 ... fileN | grep "<SEARCHING TEXT>" | awk -F'<DELIMETER>' '{print $1 $2 ... $n;}' | sort | uniq
@ufuk
ufuk / SomeSpringBeanThatNeedsAResource.java
Last active July 11, 2017 07:50
Getting and using a file from classpath with Spring's @ Value annotation.
package ...;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;
import java.io.InputStream;
@Service
public class SomeSpringBeanThatNeedsAResource {
@ufuk
ufuk / postgresql-export-import-schema.sh
Last active June 11, 2018 12:50
Exporting and then importing full schema for PostgreSQL.
# export
PGPASSWORD="<PASSWORD>" pg_dump -U <USERNAME> -h <HOST> -d <DB_NAME> -n <SCHEMA_NAME> > export.sql
# import
PGPASSWORD="<PASSWORD>" psql -U <USERNAME> -h <HOST> -d <DB_NAME> -n <SCHEMA_NAME> -f export.sql