vendredi 20 mai 2022

Trouver les plus gros fichiers, supprimés ou non, d'un repository git

Lancer dans git bash ou un shell linux: git rev-list --objects --all \ | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \ | awk '/^blob/ {print substr($0,6)}' \ | sort --numeric-sort --key=2 \ | cut --complement --characters=13-40 \ | numfmt --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest

jeudi 2 décembre 2021

Load key \"id_rsa\": invalid format

Copying a Windows ssh key to a linux machine and trying to ssh from there to a server, my ssh key was always refused. I finally found this thread recommending to check the ssh key headers to ensure it is valid, and discovered it was a putty key I needed to convert to Openssh format using Putty Generator.

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

Today I've discovered the Snyk CLI and use it to discover vulnerable dependencies to upgrade in a maven project. Good experience. If I can make a free version run as a maven task it could be a good alternative to owasp-dependency-check.

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

In module A, an integration test was passing, in module B a similar test would fail with a NoClassDefException. Module A had a dependency on a module that B hadn't. Adding the missing dependency on module B fixed the issue.

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);
    }