Blog

Here's a SPARQL query that counts all statements (triples) in a repository.

Count all statements
SELECT (COUNT(?s) AS ?triples) WHERE {
    ?s ?p ?o
}

Note that this can be a long running query. For me it took took 21 seconds to count the statements in a repository with 30 million triples.

An example SPARQL query that can help you assemble the hierarchy of classes in an ontology.

select distinct ?type ?label ?supertype 
where { 
	{ ?type a owl:Class . } UNION { ?ind a ?type . } . 
	OPTIONAL { ?type rdfs:subClassOf ?supertype } . 
	OPTIONAL { ?type rdfs:label ?label } 
} ORDER BY ?type


Source: I found this query within the web console of Stardog as one of the sample queries they provide in a drop-down list of options.

Recently I completed a little study incorporating Spring for Stardog into a Spring Boot web app, with successful results. Here's how.

Contents

Introduction

Stardog is a Java based RDF repository server (a.k.a. triple-store and more), which supports the RDF graph data model; SPARQL query language; property graph model and Gremlin graph traversal language; HTTP and SNARL protocols for remote access and control; OWL 2 and user-defined rules for inference and data analytics; virtual graphs; geospatial query answering; and programmatic interaction via several languages and network interfaces. At this point, I don't have a lot of experience with Stardog, but I've been experimenting with it to see what I can learn. As part of my study, I recently incorporated Stardog Spring into a Spring Boot web app - taking notes along the way. Here's my notes on how I got it setup and working successfully.

Download and Install Stardog

For my local development environment on Mac OS, I installed Stardog 5 BETA (Community Edition).

You can download Stardog at www.stardog.com. Once you've downloaded it, unzip the archive to a destination directory. I'm put mine in /Users/cburleson/stardog

Next you need to set the STARDOG_HOME environment variable. You can do this by adding an export line to your .bash_profile.

cd ~
sudo nano .bash_profile

Add the following line:

Add to .bash_profile
export STARDOG_HOME=/Users/cburleson/stardog

Save changes made to .bash_profile by hitting Control+o (that’s an o as in otter), ENTER, then exit out of nano by hitting Control+X.

Note that changes made .bash_profile will require the shell to be restarted or a new shell to spawn.

Copy stardog-license-key.bin into the STARDOG_HOME location. Then you can start the Stardog server to test your installation.

Start the Stardog server
/Users/cburleson/stardog/bin/stardog-admin server start

If everything is working properly, you should get the following response.

Stardog server startup response
ERROR 2017-05-09 14:34:56,823 [main] com.complexible.stardog.protocols.http.server.StardogHttpServiceLoader:createService(161): Unable to create an instance of HttpService class com.complexible.stardog.protocols.http.server.virtual.admin.VirtualGraphHttpService, missing compatible constructor

Stardog server 5.0-beta started on Tue May 09 14:34:57 CDT 2017.

Stardog server is listening on all network interfaces.
HTTP server available at http://localhost:5820.

STARDOG_HOME=/Users/cburleson/stardog

Note that there is an ERROR in this response, but I think it just has to do with the fact that I'm using the Community edition and not an enterprise edition (see: this support issue)

Still, the server is running and can be accessed in a web browser at  http://localhost:5820/


Login with:


Usernameadmin
Passwordadmin


You can also check the server status with the following command:

Check Stardog server status
/Users/cburleson/stardog/bin/stardog-admin server status

Now, that you've tested the installation, you can stop the server with the following command.

/Users/cburleson/stardog/bin/stardog-admin server stop


Add the Stardog Maven Repo to pom.xml

In order to get the required dependencies, you need to add the Stardog public maven repository to your repositories defined in the Maven POM (pom.xml). Here's how that section looks in my file:

Stardog Maven repo in pom.xml
<repositories>

    <repository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </repository>

    <repository>
        <id>stardog-public</id>
        <url>http://maven.stardog.com</url>
    </repository>

</repositories>

Add Stardog Dependencies to pom.xml

Now, we can add the required dependencies. Notice that even though I installed Stardog 5 BETA, I'm using a different version number for various dependencies (still, it works).

Stardog dependencies in pom.xml
<dependency>
    <groupId>com.complexible.stardog</groupId>
    <artifactId>client-snarl</artifactId>
    <version>4.2.4</version>
    <type>pom</type>
</dependency>


<dependency>
    <groupId>com.complexible.stardog</groupId>
    <artifactId>client-http</artifactId>
    <version>4.2.4</version>
    <type>pom</type>
</dependency>


<dependency>
    <groupId>com.complexible.stardog</groupId>
    <artifactId>server</artifactId>
    <version>4.2.4</version>
    <type>pom</type>
</dependency>

<!--
<dependency>
    <groupId>com.complexible.stardog.sesame</groupId>
    <artifactId>stardog-sesame-core</artifactId>
    <version>4.2.4</version>
    <type>jar</type>
</dependency>
-->
<!--
<dependency>
  <groupId>com.complexible.stardog.jena</groupId>
  <artifactId>stardog-jena</artifactId>
  <version>4.2.4</version>
  <type>jar</type>
</dependency>
-->

<!--
<dependency>
    <groupId>com.complexible.stardog.gremlin</groupId>
    <artifactId>stardog-gremlin</artifactId>
    <version>4.2.4</version>
    <type>jar</type>
</dependency>
-->


<dependency>
    <groupId>com.complexible.stardog</groupId>
    <artifactId>stardog-spring</artifactId>
    <version>2.1.3</version>
    <type>jar</type>
</dependency>


<!--
<dependency>
    <groupId>com.complexible.stardog</groupId>
    <artifactId>stardog-spring-batch</artifactId>
    <version>2.1.3</version>
    <type>jar</type>
</dependency>
-->

<!-- https://mvnrepository.com/artifact/org.apache.lucene/lucene-core -->
<dependency>
    <groupId>org.apache.lucene</groupId>
    <artifactId>lucene-core</artifactId>
    <version>6.5.1</version>
</dependency>

Notice that I've got stardog-spring-batch commented in the file, but commented out. I put it in the file incase I decide to use it in the future, but for now, I don't need it.

Create or Edit Spring Application Context File

I prefer using pure Java only configuration for Spring, but I had trouble with this one, so opted to use the XML configuration. I created the following file inside of src/main/resources...

applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean name="embeddedProvider" class="com.base22.rdfx.config.EmbeddedProvider"></bean>

    <bean name="dataSource" class="com.complexible.stardog.ext.spring.DataSourceFactoryBean">
        <property name="to" value="testdb"/>
        <property name="provider" ref="embeddedProvider"/>
        <property name="username" value="admin"/>
        <property name="password" value="admin"/>
    </bean>

    <bean name="template" class="com.complexible.stardog.ext.spring.SnarlTemplate">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <bean name="importer" class="com.complexible.stardog.ext.spring.DataImporter">
        <property name="snarlTemplate" ref="template"/>
        <property name="format" value="N3"/>
        <property name="inputFiles">
            <list>
                <value>classpath:data/sp2b_10k.n3</value>
            </list>
        </property>
    </bean>

</beans>

Notice that the data importer bean is going to look for an RDF file in the classpath, which should exist in src/main/resources/data.

I got that file from the source project for stardog-spring, which you can find on GitHub at:  https://github.com/stardog-union/stardog-spring

You could use any RDF file that you want to have auto-loaded into the Stardog repository.

Make the applicationContext.xml Available to Your Spring Boot App

In order for your Spring Boot app to recognize and load the applicationContext.xml, you'll need to add an annotation to the main application class (the one with a Java main() method)...

The annotation you'll need to add is:

@ImportResource("classpath:applicationContext.xml")

My main application class looks like this:

Platform.java
package com.base22.rdfx;
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;
 
@SpringBootApplication
@ImportResource("classpath:applicationContext.xml")
public class Platform {
 
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Platform.class, args);
    }
 
}


Create an EmbeddedProvider Java Class

The applicationContext.xml file references an EmbeddedProvider class. There is no EmbeddedProvider exposed by the stardog-spring library, but I found one in the stardog-spring source code at src/main/test/java/com/complexible/stardog/ext/spring.

You'll need to create this class in your project and make sure that you reference the package and class properly for the embeddedProvider bean in your applicationContext.xml file.

EmbeddedProvider.java
package com.base22.rdfx.config;

import com.complexible.common.protocols.server.ServerException;
import com.complexible.stardog.Stardog;
import com.complexible.stardog.StardogException;
import com.complexible.stardog.api.admin.AdminConnection;
import com.complexible.stardog.api.admin.AdminConnectionConfiguration;
import com.complexible.stardog.ext.spring.Provider;
import com.complexible.stardog.protocols.snarl.SNARLProtocolConstants;

public class EmbeddedProvider implements Provider {

   @Override
   public void execute(String to, String url, String user, String pass) {

      try {
         Stardog.builder()
               .create()
               .newServer()
               .bind(SNARLProtocolConstants.EMBEDDED_ADDRESS)
               .start();
         AdminConnection dbms = AdminConnectionConfiguration.toEmbeddedServer().credentials(user, pass).connect();
         if (dbms.list().contains(to)) {
            dbms.drop(to);
            dbms.createMemory(to);
         } else {
            dbms.createMemory(to);
         }
         dbms.close();
      } catch (StardogException e) {

      } catch (ServerException e) {

      } finally {

      }

   }
}


Use the Spring for Stardog SnarlTemplate in a Controller

For a quick acid test, I created a simple Spring Controller that gets executed when you hit the path /test in a web browser.

Here's the simple test controller I created, which logs output from a SPARQL query to the console.

TestController.java
package com.base22.rdfx.controllers;

import com.complexible.stardog.ext.spring.SnarlTemplate;
import com.complexible.stardog.ext.spring.mapper.SimpleRowMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

@RestController
public class TestController {

   private static final Logger log = LoggerFactory.getLogger( TestController.class);

   @Autowired
   private SnarlTemplate template;

   //private static final String template = "Hello, %s!";
   //private final AtomicLong counter = new AtomicLong();

   @RequestMapping("/test")
   public void test(@RequestParam(value="name", defaultValue="World") String name) {

      log.trace(">> test()");

      String sparql = "SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 5";

      List<Map<String,String>> results = template.query(sparql, new SimpleRowMapper());

      for ( Map<String, String> result : results ) {

         log.trace( "-- test() > --------------------------");

         Set keys = result.keySet();

         for ( Iterator i = keys.iterator(); i.hasNext(); ) {
            String key = (String) i.next();
            String value = result.get(key);
            log.trace("-- test() > " + key + " | " + value);
         }

      }

   }

}

How to Use the SnarlTemplate

The Spring Programming section of the documentation on the Stardog website provides some good information. However, if you want to see some actual code examples, you might want to refer to the TestDataSourceFactory.java class on GitHub. That's where I learned how to execute the query shown in my TestController using a SimpleRowMapper.

Test the App

Now you should be able to run your Spring Boot application and hit the TestController (/test in your browser). When you hit the URL, you should see the following output logged to the console, which shows that you've successfully configured and used Spring for Stardog. As you can see, five triples were returned from the given LIMIT 5 SPARQL query...

14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > --------------------------
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > p | http://www.w3.org/2000/01/rdf-schema#subClassOf
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > s | http://localhost/vocabulary/bench/Journal
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > o | http://xmlns.com/foaf/0.1/Document
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > --------------------------
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > p | http://www.w3.org/2000/01/rdf-schema#subClassOf
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > s | http://localhost/vocabulary/bench/Proceedings
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > o | http://xmlns.com/foaf/0.1/Document
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > --------------------------
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > p | http://www.w3.org/2000/01/rdf-schema#subClassOf
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > s | http://localhost/vocabulary/bench/Inproceedings
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > o | http://xmlns.com/foaf/0.1/Document
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > --------------------------
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > p | http://www.w3.org/2000/01/rdf-schema#subClassOf
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > s | http://localhost/vocabulary/bench/Article
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > o | http://xmlns.com/foaf/0.1/Document
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > --------------------------
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > p | http://www.w3.org/2000/01/rdf-schema#subClassOf
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > s | http://localhost/vocabulary/bench/Www
14:40:36.903 [http-nio-8080-exec-1] TRACE com.base22.rdfx.controllers.TestController - -- test() > o | http://xmlns.com/foaf/0.1/Document

Conclusion

In this post, I showed how I used Spring for Stardog in a Spring Boot web app. With some minor variation, these instructions could probably be useful for any Spring app and not just a Spring Boot web app. 

There is also some useful information in the QUICKSTART.txt file on GitHub that you might find useful, so be sure to check it out.




Some very rough notes I took while learning to create an Atlassian Confluence plugin. Perhaps, I'll clean these notes up a bit when I create my next plugin.



Contents

Install the Atlassian SDK

See: Set up the Atlassian Plugin SDK and Build a Project

Create the Plugin Skeleton

Navigate to the directory on your system where you'd like to create your plugin.  The command we are about to run will create a folder with the plugin directories inside. 

Create directory /Users/cburleson/repos/test-conf-plugin

cd into the directory

atlas-create-confluence-plugin

The first time, Maven will download a bunch of packages.

Now you need to define some things:

Define value for groupId: : com.codyburleson.test
Define value for artifactId: : myPlugin
Define value for version: 1.0.0-SNAPSHOT: : 1.0.0-SNAPSHOT
Define value for package: com.codyburleson.test: : com.codyburleson.test.MyPlugin

You will then be prompted to confirm:

Confirm properties configuration:
groupId: com.codyburleson.test
artifactId: myPlugin
version: 1.0.0-SNAPSHOT
package: com.codyburleson.test.MyPlugin
 Y: : Y

Maven will download some more stuff.

Open eclipse and switch to the /repos workspace

The basic skeleton for your Atlassian JIRA plugin is created in a new myPlugin directory: 

Feel free to take a moment to explore the different files created by the Atlassian SDK before you continue. 

Change to the myPlugin directory and enter the following command: 

atlas-run

DO NOT FORGET TO USE CTRL-D TO SHUT THE atlas-run execution down gracefully!

This will download a bunch of stuff (Maven) and then run the product with your plugin installed.

Navigate to:

http://localhost:1990/confluence

Login with admin | admin

Go find your plugin in the manage page:

http://localhost:1990/confluence/plugins/servlet/upm/manage/all

Import Into Eclipse IDE

Import > Eisting Maven Projects and find the project with the pom.xml file.

Preferences > Maven

Add a new Installation and point to: /Applications/Atlassian/atlassian-plugin-sdk-6.2.14/apache-maven-3.2.1

Set Maven user settings so that the Global settings point to: /Applications/Atlassian/atlassian-plugin-sdk-6.2.14/apache-maven-3.2.1/conf/settings.xml


Panel Macro


cd /Users/cburleson/repos/confluence-panel-macro/panelMacro
atlas-run


Open the atlassian-plugin.xml file in your favourite editor.


Locate the end of the <web-resource>...</web-resource> section in the file and enter the following:



<xhtml-macro name="panel" class="com.codyburleson.confluence.macro.Panel" key='panel-macro'>
	    <description key="panel.macro.desc"/>
	    <category name="formatting"/>
	    <parameters/>
</xhtml-macro>

Open the file /src/main/resources/myConfluenceMacro.properties and add the following line at the bottom of the file:

panel.macro.desc="Cody Burleson's Panel Macro"

Create the 

com.codyburleson.confluence.macro package.

Create the Java file in that package...

Panel.java
package com.codyburleson.confluence.macro;

import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.macro.Macro;
import com.atlassian.confluence.macro.MacroExecutionException;

import java.util.Map;

public class Panel implements Macro {

    public String execute(Map<String, String> map, String s, ConversionContext conversionContext) throws MacroExecutionException {
        return "<h1>Hello World</h1>";
    }

    public BodyType getBodyType() { return BodyType.NONE; }

    public OutputType getOutputType() { return OutputType.BLOCK; }
}

This is the minimum skeleton your Macro will require to implement the confluence Macro class and display a Macro object in Confluence. 

In your terminal window, change directory back to the top directory for your plugin (eg cd /repos/confluence-panel-macro/panelMacro)

Run the command:

atlas-mvn package

You should see a confirmation message 

[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.656 s
[INFO] Finished at: 2016-10-10T18:33:09+10:00
[INFO] Final Memory: 37M/433M
[INFO] ------------------------------------------------------------------------

Monitor the window where confluence was run originally and confirm that QuickReload finished loading. You should see a confirmation message:

Here I got a stack trace error.

[INFO] [talledLocalContainer] java.lang.RuntimeException: Cannot getResourceAsStream(panelMacro_en_GB.properties): This operation must occur before the plugin 'com.codyburleson.confluence.panelMacro' is uninstalled
[INFO] [talledLocalContainer] 	at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:54)

I created the file: 

panelMacro_en_GB.properties

Important to REFRESH THE WORKSPACE after creating new files.

Then fun atlas-mvn-package again - and all was cool...


Now you can try adding the Macro to a test page in Confluence (you'll need to make a new Confluence Space and Page before you can test it out so go ahead and do that first).


Now, you will allow the user to specify their name using a parameter to learn about how parameters can be set, and used.

Open the atlassian-plugin.xml file in your favourite editor.

Locate the <parameters/> element within the <xhtml-macro> element you created in the first part of this tutorial.  


Replace the <parameters/> element with the following:


<parameters>
    <parameter name="Title" type="string" />
</parameters>

This specifies that the parameter is called 'Name' and is of type 'string'.  You can find the full list of types under the Parameters heading in the macro module documentation

Now modify the execute method in the Java class so it looks like this:

public String execute(Map<String, String> map, String s, ConversionContext conversionContext) throws MacroExecutionException {
    if (map.get("Title") != null) {

        StringBuilder sb = new StringBuilder();
        sb.append("<div class=\"panelHeader\">");
        sb.append(map.get("Title"));
        sb.append("</div>");
        return sb.toString();
        
    } else {
        return "<h1>Hello World!<h1>";
    }
}

REFRESH THE PROJECT and then execute atlas-mvn package.

Press CTRL-D to shut down the atlas-run session gracefully.


Reference Resources

Create a Confluence 'Hello World' Macro

Linux and Unix Commands

A cheatsheet for common Linux / Unix commands.


Contents

Change File Permissions

CommandUsage
chmod +x filename.extGive execute access to a file.
sudo chmod -R 777 workspace-R means RECURSIVE
sudo chown -R basejump workspaceTake ownership of a file.
basejump (user) and workspace (directory) 

Compress or Extract Files


CommandUsage
tar -zxvf file.tar.gzTo extract one or more members from an archive:
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file

Compress an entire directory or single file.

Note: Be sure to add the .tar.gz in the archive file name yourself; the command doesn't do it for you. 


Here’s what the switches mean:

-c: Create an archive.
-z: Compress the archive with gzip.
-v: Display progress in the terminal while creating the archive, also known as “verbose” mode. The v is always optional in these commands, but it’s helpful.
-f: Allows you to specify the filename of the archive.


Create an Alias for a Common Command

CommandUsage
alias p=<command>Create shortcut aliases to common commands.
For example:
alias p="open /x/yx/z" to open a particular directory in Finder

Execute Command as Root User

CommandUsage
sudo <command>Execute command as the root user.
sudo !!Execute the last command as root user.
(!!) represents the last command you just tried to run, but couldn't because of permission issues.

Execute Task in Background

CommandUsage
./startTest.sh &Start the execution in the background, which will allow you to kill your SSH terminal without killing the process itself.

Find Large Files

CommandUsage
cd /
find . -size +10000000c -print
Prints out the names of all files with size > 10mb.
cd /
sudo du -sm * 
Examine the size of the directories under /.
You can then navigate into any given subdirectory and execute dm -sm * again to see which subdirectories are the largest. 

Inspect Disk Space and Usage

CommandUsage
df -hInspect disk space and usage (in MB or GB)


Work with Environment Variables

CommandUsage
printenvPrints all currently set environment variables and values.

Remove a File


CommandUsage
mvRename a file 
rmRemove a file 
rm -fForcefully remove a file
rm -iInteractively remove a file

If you are not certain about removing files that match a pattern you supply, it is always good to run rm interactively (rm –i) to prompt before every removal.

Directory Commands


CommandUsage
mv <oldDirName> <newDirName>Rename a directory. Be aware: this is actually a move command. So, you're just moving the directory from one name to another in the same path.
rmdirRemove an empty directory
rm -rf <dirName>

Forcefully remove a directory recursively.

Remove the f switch to be prompted for each sub-directory and file inside.

cp -rf present/directory /desire/directory

Copy an entire directory, its subdirectories, and files.

Remove the f switch to be prompted for each sub-directory and file inside.


Switch User

CommandUsage
su - <username>Switch to the given user, loading their profile.
You may have to use sudo su - <username>. 
suWithout a username means to just switch to root user.
whoami"Who Am I?" Prints the current user. 


View a File

CommandUsage
catUsed for viewing files that are not very long; it does not provide any scroll-back.
tacUsed to look at a file backwards, starting with the last line.
lessUsed to view larger files because it is a paging program; it pauses at each screenful of text, provides scroll-back capabilities, and lets you search and navigate within the file. Note: Use / to search for a pattern in the forward direction and ? for a pattern in the backward direction. Press Q to quit.
tailUsed to print the last 10 lines of a file by default. You can change the number of lines by doing -n 15 or just -15 if you wanted to look at the last 15 lines instead of the default.
headThe opposite of tail; by default it prints the first 10 lines of a file.


Use Pipes

The UNIX/Linux philosophy is to have many simple and short programs (or commands) cooperate together to produce quite complex results, rather than have one complex program with many possible options and modes of operation. In order to accomplish this, extensive use of pipes is made; you can pipe the output of one command or program into another as its input.

In order to do this we use the vertical-bar, |, (pipe symbol) between commands as in:
$ command1 | command2 | command3


The above represents what we often call a pipeline and allows Linux to combine the actions of several commands into one. This is extraordinarily efficient because command2 and command3 do not have to wait for the previous pipeline commands to complete before they can begin hacking at the data in their input streams; on multiple CPU or core systems the available computing power is much better utilized and things get done quicker. In addition there is no need to save output in (temporary) files between the stages in the pipeline, which saves disk space and reduces reading and writing from disk, which is often the slowest bottleneck in getting something done.


An example SPARQL query filtering for resources within a given date range (between two given dates).

PREFIX c: <https://carbonldp.com/ns/v1/platform#>

SELECT ?document ?createdDate WHERE {
    ?document c:created ?createdDate
	FILTER (?createdDate < "2017-04-18T22:29:33.667Z"^^xsd:dateTime && ?createdDate > "2017-04-18T21:37:37.708Z"^^xsd:dateTime)
} LIMIT 100

To automatically serve static resources with Spring Boot (e.g. when using spring-boot-starter-web), you can simply place the static resources in one of several paths that Spring Boot automatically recognizes as a static file paths.


Following are paths that will are recognized as static file paths:

  • src/main/resources/META-INF/resources/index.html
  • src/main/resources/resources/index.html
  • src/main/resources/static/index.html
  • src/main/resources/public/index.html

You can then access the resources at:

http://host/index.html

So, for example, given the following resource at the following location...

  • src/main/resources/static/css/bootstrap.min.css

You could fetch the file with the following URL:

http://host/css/bootstrap.min.css


What are the most popular database management systems? DB-Engines Ranking provides a list that's updated monthly. You can look at the complete ranking or filter by types like Relational DBMS, Key-value stores, Document stores, Graph DBMS, RDF stores, Search engines, and more.

For a ranked list of popular databases, check out the DB-Engines Ranking page on the DB-Engines site, a knowledge base of relational and NoSQL database management systems.

Most Popular RDF Stores as of April 2017

Following, for example, is a list of popular RDF Stores as calculated in April 2017.

The site calculates popularity monthly using the following general parameters (see also: Method of calculating the scores of the DB-Engines Ranking):

  • Number of mentions on websites, measured as number of results in search engines queries on Google, Bing and Yandex (searching for <system name> together with the term database, e.g. "Oracle" and "database").
  • General interest in the system, as determined by the frequency of searches in Google Trends.
  • Frequency of technical discussions about the system, as determined by the number of related questions and the number of interested users on Stack Overflow and DBA Stack Exchange.
  • Number of job offers, in which the system is mentioned on leading job search engines Indeed and Simply Hired.
  • Number of profiles in professional networks, in which the system is mentioned in popular professional networks LinkedIn and Upwork.
  • Relevance in social networks, as per a count of the number of Twitter tweets, in which the system is mentioned.






Logging with Spring Boot is dead simple. Everything's pretty much setup and ready to go. In this post, I provide some quick and simple tips to get your Spring Boot logs rolling.

About Logging Dependencies

If you use the ‘Starters’, Logback will be used with appropriate routing included to ensure that dependent libraries that use Java Util Logging, Commons Logging, Log4J or SLF4J will all work correctly. Let's suppose, for example, that you're using the web starter in your Maven pom.xml file, as shown below.

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>

Generally you won’t need to change any logging dependencies and the Spring Boot defaults will work just fine. That is to say, you don't need to add any additional dependencies to the POM for logging. You can verify this by printing a tree representation of your project dependencies. On the command line, change to your project directory and executing the following command.

Print Maven Dependency Tree
mvn dependency:tree

Notice that the Spring Boot starter already includes dependencies for logging...

[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.5.2.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.5.2.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.2.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.11:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.11:compile
[INFO] |  |  |  +- org.slf4j:jcl-over-slf4j:jar:1.7.24:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.24:compile
[INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.24:compile

Configure Log Levels

The easiest way to configure logging levels is in the application.properties file. If you don't already have one, create an application.properties file in the root of the resources folder. Then, simply prefix Java packages and classes with logging.level as shown below. Notice that you can configure the root logger at a specific level first, then get more specific with other loggers.

application.properties
logging.level.root=INFO
logging.level.com.cburleson.rdfx=TRACE

Put Logging Code in Your Classes

Now, we can use SLF4J for logging. Here's how.

Add the following to the imports section of your java code:


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Add the following at the top of your class in the global section (just under the line that declares your class public class Whatever extends Whatever). Change the name of the class (MyClassName) in the getLogger method call, of course. Name it the same as the class you're dropping this code into.


static final Logger LOG = LoggerFactory.getLogger(MyClassName.class);

To test quickly, you can throw some logging statements in your code somewhere where you know they'll be fired right away when you run your app. For example:


LOG.trace("Hello World!");
LOG.debug("How are you today?");
LOG.info("I am fine.");
LOG.warn("I love programming.");
LOG.error("I am programming.");

The default log configuration will echo messages to the console as they are written. If your terminal supports ANSI, color output will be used to aid readability.

Log to a File

If you want to write log files in addition to the console, you can set a logging.file or logging.path property in your application.properties. For example...

logging.level.root=INFO
logging.level.com.cburleson.rdfx=TRACE


#output to a temp_folder/file
logging.file=${java.io.tmpdir}/myapp.log

#output to a file
#logging.file=/Users/cburleson/myapp.log


#output to a file called spring.log in the specified path
#logging.path=/var/log

Using SLF4J over Log4j

Now, if you want to use SLF4 over Log4j 2, and a log4j configuration file, the setup is a little different. In your Maven, POM, you must exclude spring-boot-starter-logging and then add a dependency for spring-boot-starter-log4j2 as shown below.


  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <exclusions>
          <exclusion>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-logging</artifactId>
          </exclusion>
      </exclusions>
  </dependency>

  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-log4j2</artifactId>
  </dependency>

Then you need to have a log4j2.xml file on the classpath; for example - in src/main/resources. Here's a simple log4j2.xml file example.

log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
        </Console>
        <File name="MyFile" fileName="all.log" immediateFlush="false" append="false">
            <PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </File>
    </Appenders>
    <Loggers>
        <Root level="debug">
            <AppenderRef ref="Console" />
            <!-- AppenderRef ref="MyFile"/ -->
        </Root>

        <Logger name="com.base22" level="trace" additivity="false">
            <AppenderRef ref="Console"/>
        </Logger>

    </Loggers>
</Configuration>


Conclusion

As you can see, logging from your Spring Boot application is piece of cake. Of course, there's a lot more that you can do as your requirements dictate. For more information, take a look at Logging, in the Spring Boot Reference Guide.

References
  • Logging, in the Spring Boot Reference Guide
Confluence Panel Macro

A macro for Atlassian Confluence that mimics a Bootstrap 3 Panel.


Overview

This is a simple macro I developed that mimics the Bootstrap 3 Panel. The macro takes an optional Title, an optional Style, and a rich text macro body. It renders results as shown in the examples section below.

I did this as a learning exercise in preparation to do a more sophisticated plugin for Confluence. You might find the code useful if your doing something similar. You can find the source code in the following public repository on GitHub:

https://github.com/codyburleson/confluence-panel-macro


Tested on:

  • Atlassian Confluence 6.0.5
  • Google Chrome Version 57.0.2987.98 (64-bit) on Mac OS

If you find any issues, please open an issue on GitHub.

Examples


This panel has no title filled out and no style selected. It shows an example of using another macro within the body; the STATUS MACRO .
No Style Selected
 This one has a title, but no style selected. It defaults to the 'default' style.
Default
This panel is configured with the style 'default'.
Primary
 This panel is configured with the style 'primary'.
Success
 This panel is configured with the style 'success'.
Info
 This panel is configured with the style 'info'.
Warning
 This panel is configured with the style 'warning'.
Danger
 This panel is configured with the style 'danger'.

Attachments

The current version of the macro that I've got deployed here in this wiki is attached. If you want to try it out, you can upload the jar through Manage add-ons in the Confluence admin area.

  File Modified
Java Archive panelMacro-1.0.0-SNAPSHOT.jar Mar 25, 2017 by Cody Burleson

License

MIT License

Copyright (c) 2017 Cody Burleson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

This page is a never-ending work-in-progress where I've decided to capture handy little tips for enhancing workflow in WebStorm. Shoot me an email if you know of any other handy little things that I can add to this list.

Auto-Import (TypeScript)

Put cursor at end of red text object name and click CTRL + SPACE (auto-complete) and select the object from the pop-up context menu.

Comment Code

Select code, then CMD + /

Multiple Cursors

ALT + CLICK to set multiple cursors manually on the page. (on mac that includes the function key)
or...
Select a word and press CTRL + G 


Did you know that Emmet's built-in to WebStorm? Emmet takes the snippets idea to a whole new level: you can type CSS-like expressions that imply the HTML structure you want, press Tab, and then WebStorm spits out the desired HTML.

Try It!

Here's a simple example of a basic expression in the Emmet syntax. Try typing the following in an HTMl page in WebStorm:

ul>li*10

At the end of the expression, just hit the Tab key. WebStorm will use Emmet to parse the text and spit out the intended HTML which, in this case, will be an unordered list with 5 list items (shown below):

<ul>
   <li></li>
   <li></li>
   <li></li>
   <li></li>
   <li></li>
</ul>


For details, you can refer to the Emmet Documentation, but for convenience, I'm including the most common stuff below. There's a lot more to it though, so if you like what you see here, be sure to RTFM.

Emmet Syntax

Nesting

You can use > operator to nest elements inside each other:

div>ul>li
Result
<div>
    <ul>
        <li></li>
    </ul>
</div>

Sibling

Use + operator to place elements near each other, on the same level:

div+p+bq
Result
<div></div>
<p></p>
<blockquote></blockquote>

Multiplication

With * operator you can define how many times element should be outputted:

ul>li*5
Result
<ul>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
</ul>

Grouping

Parenthesises are used by Emmets’ power users for grouping subtrees in complex abbreviations:

div>(header>ul>li*2>a)+footer>p
Result
<div>
    <header>
        <ul>
            <li><a href=""></a></li>
            <li><a href=""></a></li>
        </ul>
    </header>
    <footer>
        <p></p>
    </footer>
</div>

If you’re working with browser’s DOM, you may think of groups as Document Fragments: each group contains abbreviation subtree and all the following elements are inserted at the same level as the first element of group.

You can nest groups inside each other and combine them with multiplication * operator.

ID and CLASS


In CSS, you use elem#id and elem.class notation to reach the elements with specified id or class attributes. In Emmet, you can use the very same syntax to add these attributes to specified element:

div#header+div.page+div#footer.class1.class2.class3
Result
<div id="header"></div>
<div class="page"></div>
<div id="footer" class="class1 class2 class3"></div>

Custom attributes

You can use [attr] notation (as in CSS) to add custom attributes to your element:

td[title="Hello world!" colspan=3]
Result
<td title="Hello world!" colspan="3"></td>

Item numbering

With multiplication * operator you can repeat elements, but with $ you can number them. Place $ operator inside element’s name, attribute’s name or attribute’s value to output current number of repeated element:

ul>li.item$*5
Result
<ul>
    <li class="item1"></li>
    <li class="item2"></li>
    <li class="item3"></li>
    <li class="item4"></li>
    <li class="item5"></li>
</ul>

You can use multiple $ in a row to pad number with zeroes:

ul>li.item$$$*5
Result
<ul>
    <li class="item001"></li>
    <li class="item002"></li>
    <li class="item003"></li>
    <li class="item004"></li>
    <li class="item005"></li>
</ul>

Text

You can use curly braces to add text to element:


a{Click me}
Result
<a href="">Click me</a>

Greek Text

You know - that filler text that designers use when they can't think of real words that are relevant to a design...

lorem5
Lorem ipsum dolor sit amet.


Holy Shit Example

Here's a crazy example to give you an idea of what you can accomplish if you get bad ass with Emmet.

Emmet Abbreviation
nav#menuSystem.navMenu.isOpen>div#hotelLogo>div.navMenuIcon.logoIcon+div#arrowPointer+ul#navMenuMain>li.navMenuItem.navMenuItem$$$*10>div.navMenuIcon{Item $}+a{Item $}
Result
<nav id="menuSystem" class="navMenu isOpen">
   <div id="hotelLogo">
      <div class="navMenuIcon logoIcon"></div>
      <div id="arrowPointer"></div>
      <ul id="navMenuMain">
         <li class="navMenuItem navMenuItem001">
            <div class="navMenuIcon">Item 1</div>
            <a>Item 1</a></li>
         <li class="navMenuItem navMenuItem002">
            <div class="navMenuIcon">Item 2</div>
            <a>Item 2</a></li>
         <li class="navMenuItem navMenuItem003">
            <div class="navMenuIcon">Item 3</div>
            <a>Item 3</a></li>
         <li class="navMenuItem navMenuItem004">
            <div class="navMenuIcon">Item 4</div>
            <a>Item 4</a></li>
         <li class="navMenuItem navMenuItem005">
            <div class="navMenuIcon">Item 5</div>
            <a>Item 5</a></li>
         <li class="navMenuItem navMenuItem006">
            <div class="navMenuIcon">Item 6</div>
            <a>Item 6</a></li>
         <li class="navMenuItem navMenuItem007">
            <div class="navMenuIcon">Item 7</div>
            <a>Item 7</a></li>
         <li class="navMenuItem navMenuItem008">
            <div class="navMenuIcon">Item 8</div>
            <a>Item 8</a></li>
         <li class="navMenuItem navMenuItem009">
            <div class="navMenuIcon">Item 9</div>
            <a>Item 9</a></li>
         <li class="navMenuItem navMenuItem010">
            <div class="navMenuIcon">Item 10</div>
            <a>Item 10</a></li>
      </ul>
   </div>
</nav>




Here's how to avoid tracking page views in Google Analytics when you're logged in as an administrative or other specific user.


This solution presupposes that your Google Analytics tracking snippet is pasted into the field labelled "At end of the HEAD" in the Custom HTML section in the Confluence Administration Area as shown below...

Before modification, your Google Analytics tracking code should look something like this.

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-21819432-1', 'auto');
ga('send', 'pageview');


</script>

Now, to avoid tracking pages for an administrative user (or any particular user or set of users, for that matter), you can wrap the ga() function calls in an IF check. In the following code, we use the Confluence AJS object to determine whether or not the authenticated user is an administrative user. If that's true, we do not reach the ga() functions and thus, the pageview is not tracked. In all other cases, however, the pageview will be tracked.

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

if(! AJS.params.isConfluenceAdmin) {
	ga('create', 'UA-21819432-1', 'auto');
  	ga('send', 'pageview');
}
</script>

You could use console.log statements to test this in your local browser.

If you want to avoid logging page views for specific users, you can check for specific user names with AJS.params.remoteUser.


In my digital journal, I've kept a page called "Bucket List", but I've kicked it out in favor of a new title: "Goals".

I've learned that the language you use and the story you tell yourself is fundamentally important to what you actually achieve and do. And maybe it goes even deeper than that. Maybe it's not just the language you use, but the personal meaning that you've ascribed to the concepts in that language. The Merriam-Webster online dictionary defines a bucket list as a list of things that one has not done but wants to do before dying. That's how I think of it too, but there's something about the concept for me that is far more forgiving than a list of goals. I think of the bucket list as a list of frilly things or nice-to-dos - just icing on the cake of life, which you never have to eat. Nobody's going to hold it against you if you don't do the things that are on your bucket list - not even yourself. Death is your deadline, after all.

I don't think that works for me, so instead, I've decided to change the title of my Bucket List to "Goals". The meaning of the two concepts are entirely different to me. Goals are much more real. For me, a goal implies a stronger intent to achieve it. A goal begs an action plan. A goal begs to be SMART:

  • Specific (and Significant)
  • Measurable (and Meaningful)
  • Attainable (and Action-oriented)
  • Realistic, Relevant (and Rewarding)
  • Time-Based (and Time-bound or Trackable)

To me, the things on a bucket list are just ideas. Possibilities. Opportunities. I'd rather think of them as "draft goals". They're worth writing down. But give them any careful thought and they might just as easily fall off the list as get prioritized and planned. So, now I have my list of goals - some prioritized and planned. Some SMART. Some, just draft ideas. But I don't have a bucket list anymore.

There are simply things I've done, things I will do, and things I might do - goals I've achieved, goals I will achieve, and then all the things that might or might not become goals. If they become goals, they'll get an action plan and evaluation against the principles of SMART. If they don't make it to that point, then they probably are just frilly ideas that don't deserve to stay on the list.

 

This week, I've been listening to the audiobook, Benjamin Franklin: An American Life by Walter Iscaacson. My favorite part, so far is where he recounted thirteen virtues that Benjamin Franklin recorded in his autobiography. I think Ben Franklin wrote these in 1726, at the mere age of twenty.

  1. Temperance. Eat not to dullness; drink not to elevation.
  2. Silence. Speak not but what may benefit others or yourself; avoid trifling conversation.
  3. Order. Let all your things have their places; let each part of your business have its time.
  4. Resolution. Resolve to perform what you ought; perform without fail what you resolve.
  5. Frugality. Make no expense but to do good to others or yourself; i.e., waste nothing.
  6. Industry. Lose no time; be always employ'd in something useful; cut off all unnecessary actions.
  7. Sincerity. Use no hurtful deceit; think innocently and justly, and, if you speak, speak accordingly.
  8. Justice. Wrong none by doing injuries, or omitting the benefits that are your duty.
  9. Moderation. Avoid extremes; forbear resenting injuries so much as you think they deserve.
  10. Cleanliness. Tolerate no uncleanliness in body, cloaths, or habitation.
  11. Tranquillity. Be not disturbed at trifles, or at accidents common or unavoidable.
  12. Chastity. Rarely use venery but for health or offspring, never to dullness, weakness, or the injury of your own or another's peace or reputation.
  13. Humility. Imitate Jesus and Socrates.