CSS

Tuesday, October 31, 2017

Move dropbox directory on Linux using the command line

Short Answer

You can't.  All the stuff on the internet is real old.   I worked on this for 10 hours and here is my answer.

How to get the directory where you want

This is only really useful if you want to move the dropbox directory to a filesystem other then the one your users are on.

Create a user whose home directory is where you want the Dropbox directory to be.  The Dropbox directory is going to end up under this user's home directory.  

Why is this better then a symbolic link?

It is better than a symbolic link since because Dropbox uses OS level file notifications calls to decide what to sync.  These do not work through a symbolic link.  If you just make a link called Dropbox and point it to another filesystem your files will not be synced.  You can change and create files through a symbolic link.  Dropbox needs to have a real link to work.

Tuesday, June 27, 2017

Fix Greeter Login panel on Ubuntu 17.04

This works with all flavors of Linux that use LightDM as their greeter.

When my laptop was in its docking station, the login prompt would not display.  I guess it was displaying on the closed laptop display.

Create a file /opt/sbin/set-prime-mon

Contents:
#!/bin/sh
# Set prime monitor to left most
LOG=/var/log/set-prime-mon.log
# Remove any previous logs
rm -f $LOG
output=$(xrandr | grep -E " connected (primary )?[1-9]+" | grep "+0+0" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
echo $output >> $LOG 2>&1
if [ -n $output ]; then
 echo "setting prime to $output" >> $LOG 2>&1
 xrandr --output $output --primary
fi

Create a file /etc/lightdm/lightdm.conf.d/99-setprime.sh

Contents:
display-setup-script=/opt/sbin/set-prime-mon

Wednesday, April 19, 2017

Stopping new Icon when I launch a java appication from Gnome or Unity

So I had successfully created a .desktop file to launch Eclipse from Gnome.  I also found it no problem  making it a favorite.  The problem I was having was every time I launched Eclipse I ended up with 2 icons.  The Favorite and one for the running process.  The trick to making not getting this is to make sure the .desktop name matches the xwindows WM_CLASS property. You can get this value by running:

 xprop WM_CLASS 

Next click on the window of the Java application you are interested in.  In the case of Eclipse the value is "Eclipse" so the file needs to be named Eclipse.desktop.

Thursday, March 30, 2017

Java Base64 OutputStream cutting off characters

This took me a while to figure out. I am using a Outputstream to write create a piece of XML.  One of the elements needed to be Base64 encoded.  I wrapped my outputstring using java.util.Base64.wrap.  I did not close the Base64 OutputStream.  It is not really clear but the close of this stream is when it takes care of padding,

Bad Code

// out is a FileOutputStream 
final Base64.Encoder encoder = Base64.getMimeEncoder(); 
final OutputStream clob = encoder.wrap(out); 
IOUtils.copy(in, clob, Charset.forName("UTF-8")); 
// No close of clob Just went and kept writing to out 

Good Code

// out is a FileOutputStream 
final Base64.Encoder encoder = Base64.getMimeEncoder(); 
final OutputStream clob = encoder.wrap(
      new CloseShieldOutputStream(out)); // Use nice Apache IO Wrapper that does                        // not chain close 
IOUtils.copy(in, clob, Charset.forName("UTF-8")); 
clob.close(); // this forces out the padding

Wednesday, November 19, 2014

Fix errors with IBM Data Studio and DB2 10.4 on Linux Mint 17.1

I was getting the following errors every time I clicked on something with my newly installed IBM Data Studio:


com.ibm.db2.jcc.am.SqlException: DB2 SQL Error: SQLCODE=-805, SQLSTATE=51002, SQLERRMC=NULLID.SYSSH200 0X5359534C564C3031, DRIVER=4.18.60 at com.ibm.db2.jcc.am.kd.a(Unknown Source) at com.ibm.db2.jcc.am.kd.a(Unknown Source) at com.ibm.db2.jcc.am.kd.a(Unknown Source) at com.ibm.db2.jcc.am.bp.c(Unknown Source) at com.ibm.db2.jcc.t4.bb.p(Unknown Source) at com.ibm.db2.jcc.t4.bb.h(Unknown Source) at com.ibm.db2.jcc.t4.bb.b(Unknown Source) at com.ibm.db2.jcc.t4.p.a(Unknown Source) at com.ibm.db2.jcc.t4.vb.i(Unknown Source) at com.ibm.db2.jcc.am.bp.kb(Unknown Source) at com.ibm.db2.jcc.am.cp.xc(Unknown Source) at com.ibm.db2.jcc.am.cp.b(Unknown Source) at com.ibm.db2.jcc.am.cp.kc(Unknown Source) at com.ibm.db2.jcc.am.cp.executeQuery(Unknown Source) at com.ibm.datatools.uom.ConnectionService.getDB2Instance(Unknown Source) at com.ibm.datatools.dse.db2.luw.ui.internal.databases.listview.DB2ConnectionDetailsProvider.getInstanceName(Unknown Source) at com.ibm.datatools.uom.ui.internal.databases.listview.ObjectListDatabasesPropertiesProvider$ConnectionProfilePropertyValueProvider.getPropertyValue(Unknown Source) ...

I did a bind and it cleared up.


db2 terminate 
db2 CONNECT TO dbname user USERID using PASSWORD 
db2 BIND path/db2schema.bnd BLOCKING ALL GRANT PUBLIC SQLERROR CONTINUE 
db2 BIND path/@db2ubind.lst BLOCKING ALL GRANT PUBLIC ACTION ADD 
db2 BIND path/@db2cli.lst BLOCKING ALL GRANT PUBLIC ACTION ADD 
db2 terminate

Here is where I got the commands from: http://www-01.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.qb.server.doc/doc/t0024970.html?cp=SSEPGG_10.5.0%2F2-2-0-4-2

Wednesday, March 26, 2014

Java Epoch to TIMESTAMP function

One of the timestamps in one tables I work with is stored as a java epoch.  Here is a function I wrote to convert it to a timestamp.

This is done in DB2 on a iSeries so some you may need to edit it some.  In particular ant line that *SomeWord is probably a iSeries thing.

CREATE FUNCTION YFUALFA.TIMESTAMP_EPOCH ( 
 EPOCH BIGINT ) 
 RETURNS TIMESTAMP   
 LANGUAGE SQL 
 SPECIFIC YFUALFA.TIMESTAMP_EPOCH 
 DETERMINISTIC 
 READS SQL DATA 
 RETURNS NULL ON NULL INPUT 
 NO EXTERNAL ACTION 
 SET OPTION  ALWBLK = *ALLREAD , 
 ALWCPYDTA = *OPTIMIZE , 
 COMMIT = *NONE , 
 DECRESULT = (31, 31, 00) , 
 DFTRDBCOL = *NONE , 
 DYNDFTCOL = *NO , 
 DYNUSRPRF = *USER , 
 SRTSEQ = *HEX   
 RETURN TIMESTAMP ( '1970-01-01' , '00:00:00' ) + EPOCH SECONDS  ; 
  
COMMENT ON SPECIFIC FUNCTION YFUALFA.TIMESTAMP_EPOCH 
 IS 'Timestamp from a Java epoch' ;

Thursday, May 30, 2013

How to create a Hibernate UserType for a Boolean that really works

So I am working with a legacy database using JPA/Hibernate.  Our booleans are stored as a VARCHAR(5) with the values of either 'true' or 'false',  This does not lend its self to using the built in Hibernate type or either yes_no or true_false.

I tried using Hibernates org.hibernate.usertype.UserType interface to create a user type.  This almost worked.  I was able to successfully read and write data.  The problem was that if I had a query in which  I want to statically use true or false I had to singe quote the true or false.  See below for what did and did not work.

What I wanted

Select ss from StudentSupportSurvey ss where ss.stopNags = true 

What I had to do

Select ss from StudentSupportSurvey ss where ss.stopNags = 'true' 

UserType that worked

Notice that I did not implement UserType I instead extended AbstractSingleColumnStandardBasicType.  In my opinion it is probably always better to override one of the abstract classes found in org.hibernate.type then to implement UserType.

package org.yfu.util.hibernate;

import java.io.Serializable;

import org.hibernate.dialect.Dialect;
import org.hibernate.type.AbstractSingleColumnStandardBasicType;
import org.hibernate.type.DiscriminatorType;
import org.hibernate.type.PrimitiveType;
import org.hibernate.type.StringType;
import org.hibernate.type.descriptor.java.BooleanTypeDescriptor;
import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;

public class TrueFalseBooleanUserType extends AbstractSingleColumnStandardBasicType<Boolean>
 implements PrimitiveType<Boolean>, DiscriminatorType<Boolean>{

 private static final long serialVersionUID = -2794554001044861116L;
 
 public TrueFalseBooleanUserType() {
  super(VarcharTypeDescriptor.INSTANCE, BooleanTypeDescriptor.INSTANCE);
 }

 @Override
 public String getName() {
  return "yfu_boolean";
 }
 
 public Class getPrimitiveClass() {
  return boolean.class;
 }

 public Boolean stringToObject(String xml) throws Exception {
  return fromString( xml );
 }

 public Serializable getDefaultValue() {
  return Boolean.FALSE;
 }

 public String objectToSQLString(Boolean value, Dialect dialect) throws Exception {
  return StringType.INSTANCE.objectToSQLString( value.booleanValue() ? "true" : "false", dialect );
 }
}

This allowed me to right my query like this:
Select ss from StudentSupportSurvey ss where ss.stopNags = true