Pages

21/09/2019

[Android] Revive MyTracks app

MyTracks was the best GPS tracking application. Lightweight, simple to use, well integrated with Google Drive, no extra crap. Until the fire nation attacked Google decided to kill it hoping you would switch to that pile of manure that is Google fit.

As valid alternatives I could only find ViewRanger or Open GPS Tracker but they are just not as good in my opinion.

The way Google killed the app, was to revoke the API keys it used. Meaning that by swapping those keys out with ones you own, everything works as expected.

Interested? Then check out the revive MyTracks project on Github

[Maven] Copy specific files from artifact in local directory

With Maven dependency plugin, it is possible to unpack certain content from specific artifacts in a desired directory during a certain phase:

 <build>  
   <plugins>  
     <plugin>  
       <groupId>org.apache.maven.plugins</groupId>  
       <artifactId>maven-dependency-plugin</artifactId>  
       <version>3.1.1</version>  
         <executions>  
           <execution>  
             <id>YOUR_ID</id>  
             <phase>SOME_PHASE</phase>  
             <goals>  
               <goal>unpack</goal>  
             </goals>  
             <configuration>  
               <artifactItems>  
                 <artifactItem>  
                   <groupId>SOME_GROUP</groupId>  
                   <artifactId>SOME_ARTIFACT</artifactId>  
                   <version>SOME_VERSION</version>  
                   <type>SOME_TYPE</type>  
                   <overWrite>true</overWrite>  
                   <outputDirectory>some/folder</outputDirectory>  
                   <includes>some/pattern/**,and/another/pattern/**</includes>  
                 </artifactItem>  
               </artifactItems>  
             </configuration>  
         </execution>  
       </executions>  
     </plugin>  
   </plugins>  
 </build>  


Important parameters are:

  • artifactItem to ONLY consider that artifact instead of ALL imported ones
  • type to specify the artifact type, eg: jar
  • overWrite to specify whether to overwrite existing files in output folder
  • outputDirectory to specify where to unpack the content
  • includes to limit unpacking ONLY to specific files and folders. Multiple patterns can be added by separating with a comma

[Maven] Delete folders during specific phase

Using Maven clean plugin, it is possible to specify a clean behaviour to delete only selected folders during a certain phase:

 <build>  
   <plugin>  
     <artifactId>maven-clean-plugin</artifactId>  
     <version>3.1.0</version>  
     <executions>  
       <execution>  
         <id>YOUR_ID</id>  
         <phase>SOME_PHASE</phase>  
         <goals>  
           <goal>clean</goal>  
         </goals>  
         <configuration>  
           <excludeDefaultDirectories>true</excludeDefaultDirectories>  
             <filesets>  
               <fileset>  
                 <directory>some/directory</directory>  
               </fileset>  
             </filesets>  
         </configuration>  
       </execution>  
     </executions>  
   </plugin>  
 </build>  


Important parameters are:

  • excludeDefaultDirectories to avoid cleaning also the directories that a normal mvn:clean execution would
  • fileset to specify only the directories to delete

[cURL] Use file content as payload

With curl, it is possible to specify a file content as payload simply with:

-d @$file

For example:

curl -X POST some_url -H some_headers -d @$file

[bash] Loop over all files in folder filtering by extension

In bash, it is possible to loop over all files with a specific extension in a folder with:

for file in folder/*.extension
do
    something with $file
done

Note that if directory is empty, one iteration will performed on the nonexistent *.extension file. To avoid that set the nullglob shell option for that run only as such:

shopt -s nullglob

your_script_here

shopt -u nullglob

[bash] Store content of file in a variable

In bash, it is possible to store the content of a file in a variable simply with:

file=/path/to/somefile.something
content="`cat $file`"

Note the special quotes used

[bash] String substitution with parameter expansion

In bash, it is possible to use parameter expansion with syntax ${expression} to perform a string replace. Here are some examples, the first value MUST be a variable.

To replace ONE occurrence of substring:

result=${string/substring/replace_with}

For example

string=grogblog
result=${string/blog/logs}

will return groglogs

To replace ALL occurrences of substring:

result=${string//substring//replace_with}

For example

string=grogbloggrogblog
result=${string//blog/logs}

will return groglogsgroglogs

Note the difference is simply the // instead of / at the beginning

[bash] Substring with parameter expansion

In bash it is possible to use parameter expansion with syntax ${expression}to perform a substring operation. Here are some examples, the first value MUST be a variable.

To cut out some text from the BEGINNING of the string:

result=${string#string_to_cut}

For example

string=groglogs
result=${string#grog}

will return logs

To cut out some text BEFORE the END of the string:

result=${string%cut_point*}

For example

string=grog.logs
result=${string%.*}

will return grog

They can also be chained to operate on the same variable in a sequence