Oh my blog!
vendredi 20 mai 2022
Trouver les plus gros fichiers, supprimés ou non, d'un repository git
jeudi 2 décembre 2021
Load key \"id_rsa\": invalid format
mardi 9 novembre 2021
How to find and automatically remove old catalina logs
Tomcat can produce daily log files, potentially filling your disk space over time.
You can list the catalina log files old than 30 days using
find /srv/apache-tomcat-8.5.14/logs/catalina.*.log -mtime +30
To remove files older than 30 days, you can run the following command:
find /srv/apache-tomcat-8.5.14/logs/catalina.*.log -mtime +30 -exec rm -f {} \;
Finally, you can make it a cron to remove old log files daily:
crontab -e
In the cron file, add the regex and command:
# every day at 6PM
0 18 * * * find /srv/apache-tomcat-8.5.14/logs/catalina.*.log -mtime +30 -exec rm -f {} \;
You can then list all crontabs using
crontab -l
NB: if you want your command to run as sudo, you need to modify the sudo crontabs instead:
sudo crontab -e
mercredi 22 septembre 2021
Snyk CLI
jeudi 22 juillet 2021
Change configurations depending on the environment in Spring
For years I programmed with the awesome Grails framework. One of it's elegant features is the possibility to define environment-specific configurations in your application.yml.
Example application.yml:
Moving to Spring Boot I was missing this feature until I found out how to do it in the documentation ( section 59.6) using Spring profiles.
Example application.yml:
vendredi 16 juillet 2021
Resolving NoClassDefException
mardi 13 juillet 2021
Configuring h2 with GIS
Using the H2 gis, I could make my integration tests work with h2, creating spatial queries with jpa.
- Use the hiberante dialect org.hibernate.spatial.dialect.h2geodb.GeoDBDialect
- Initialise the database by executing CREATE ALIAS IF NOT EXISTS H2GIS_SPATIAL FOR "org.h2gis.functions.factory.H2GISFunctions.load"; CALL H2GIS_SPATIAL(); You can wrap the query in a sql script and use @Sql(scripts = "/sql/h2_gis_initialization.sql") to execute it on your test class.
- in maven, import h2 gis. Be aware that each version requires a specific version of h2
<!-- https://mvnrepository.com/artifact/org.orbisgis/h2gis -->
<dependency>
<groupId>org.orbisgis</groupId>
<artifactId>h2gis</artifactId>
<version>${h2.gis.version}</version>
</dependency>
- in your liquibase script, create the column with the GEOMETRY type:
<changeSet author="hschoonjans" id="create_table_localization_t">
<createTable tableName="LOCALIZATION_T">
<column name="ID" type="BIGINT">
<constraints primaryKey="true"/>
</column>
<column name="geometry" type="GEOMETRY"/>
</createTable>
</changeSet>
Run integration test:
@Test
void it_can_search_within_geometry() {
final Polygon polygon = new GeometryFactory().createPolygon();
List<Localization> results = repository.findAll(within(polygon));
Assertions.assertEquals(0, results.size());
}
public static Specification<Localization> within(Geometry geometry) {
return (root, query, builder) -> JTSSpatialPredicates.within(builder, root.get(Localization_.geometry), geometry);
}