środa, 23 grudnia 2015

Quick fix for non-responding keyboard in Ubuntu

In order to unlock keyboard just restart ibus deamon
ibus-daemon -rd
PS. Check batteries in your keyboard if restarting does not help :)

Fun with awk - how to aggregate column values in bash

How to aggregate values in particular column

for i in $(ls); do du -sm $i; done | awk '{s+=$1;print s,$0} END{print "S:",s}'

środa, 16 grudnia 2015

Quick fix for disappeared time panel in Unity top bar

Forcing restart of unity-panel by killing it do the job. Ingenious ;D.
sudo killall unity-panel-service

poniedziałek, 14 grudnia 2015

How to format xml with xmllint using tab instead of double space

Using xmllint is very handy way of formatting xml, but suffers from limitted formatter options. Luckly the most crucial is available but not very straitforward to use. xmllint is using XMLLINT_INDENT system variable for setting characters sequence used as indentation. To set it as \t character you need a special trick ($'\t')
$ export XMLLINT_INDENT=$'\t'
Now every xmllint --format will use tab for indentation. Setting formatting command for vim.
map @@x !%xmllint --format --recover -^M

Simplified code review exchange format

If i am wrong but i don't know any unified format for code review result exchanging. Something that should be obviously available and shared among dozens of utilities schema.yaml sourcefile revision line offset (opt) comment author date

niedziela, 13 grudnia 2015

Eclipse Plugin - How to add error validation markers for

Register org.eclipse.core.resources.markers extension point
 
  
  
  
  
 
Declare constant (optional)
interface Constants {
     String MARKER_VALIDATION_ERROR = "org.myapp.validation.problem";
}
Delete all validation markers for assigned to processed file.

 private static boolean deleteMarkers(IFile file) {
  int markersCount = 0;
  try {
   markersCount = file.findMarkers(Constants.MARKER_VALIDATION_ERROR, false, IResource.DEPTH_ZERO).length;
   file.deleteMarkers(Constants.MARKER_VALIDATION_ERROR, false, IResource.DEPTH_ZERO);
  } catch (CoreException e) {
   throw Throwables.propagate(e);
  }
  return markersCount > 0;
 }

Compute and add new validation marker:
 private static void addMarker(IFile file, String message, int severity, ModelObject model, Expression expression) throws CoreException {
  IMarker marker = file.createMarker(Constants.MARKER_VALIDATION_ERROR);
  marker.setAttribute(IMarker.MESSAGE, message);
  marker.setAttribute(IMarker.SEVERITY, severity);
  marker.setAttribute(IMarker.SOURCE_ID, model.getId());
  logger.debug("Marker created: " + file + ", attr: " + marker.getAttributes().keySet());
 }

How to deploy chosen artifacts of multimodule maven application

In case there is parent module you need to install also this parent pom.
  REPO_ID=myRepoIdDefinedInSettingsXml && \
  REPO_URL=http://example.com/nexus/content/repositories/releases && \
  VERSION=2.3.1 && \
  /usr/local/bin/mvn deploy:deploy-file \
     -DgroupId=${GROUP_ID} \
     -DartifactId=${PARENT_ARTIFACT_ID} \
     -Dpackaging=pom \
     -Dversion=${VERSION} \
     -DrepositoryId=${REPO_ID} \
     -Durl=${REPO_URL} \
     -Dfile=build/release-*/pom.xml && \
Once parent module is installed (but in fact doesn't need to be first) we can install our modules (MODULE1, MODULE4 and MODULE_N). Installing sources is optional (if your package phase does not generate source bundle - just skip -Dsource option.
for ARTIFACTID in MODULE1 MODULE4 MODULE_N; do \
    for FILE in $(find target/${ARTIFACTID} -name "${ARTIFACTID}*.jar" | grep -v sources); do \
      /usr/local/bin/mvn deploy:deploy-file \
        -DgroupId=${GROUP_ID} \
        -DartifactId=${ARTIFACTID} \
        -Dversion=${VERSION} \
        -DpomFile=$(dirname ${FILE})/../pom.xml \
        -Dpackaging=jar \
        -DrepositoryId=${REPO} \
        -Durl=${REPO_URL} \
        -Dfile=$(dirname ${FILE})/${ARTIFACTID}-${VERSION}.jar \
        -Dsources=$(dirname ${FILE})/${ARTIFACTID}-${VERSION}-sources.jar; \
    done; \
  done; \

How to run sql script against H2 file database with single command

There are cases when the quickest way to fix database is by running some sql script. Assuming you have used h2 in the past you're most likly have h2 driver in your m2 repo. Once you found it try the following:
 java -cp h2*.jar org.h2.tools.RunScript -url <URL> -script init.sql
where URL is default jdbc string and can be jdbc:h2:~/test