Sonos unable to add folder due to Kapersky firewall

On laptop I tried to add a local folder on C drive to Sonos. The Sonos controller on the same laptop gave the 1002 error code. This is a timeout?

Tried to find solution on web. Firewall had no issues and anti virus software wasn’t doing anything strange. Just in case, I turned off file scanning. Still have issue. Turned off the Windows firewall; still have problem.

Long story short, Kapersky has a firewall running, doh! Turned that off, Sonos can read local folder. Makes no sense. Why would a firewall block a local app from local folder? Probably because the local Sonos controller has to update the local network with that folder so that other controllers in house can also use it.

Links
Sonos support page on error code 1002

Windows mouse pointer disappears on second monitor

Started happening recently. Maybe an upgrade or some new glitch in system caused it. Experimenting, and found that turning on the Mouse’s Pointer trails eliminated the problem.

System

  • Windows 7 Professional
  • UltrMon 3.2.2
  • HP PC p6230y
  • AMD Phenon II X4 810 Processor 2.60 GHz
  • System Mouse driver

Related Links

Java Properties dupe key detect using subclass

And now for the final word on this ‘problem’, the simplest approach is just to subclass the Properties class. The Properties class extends HashTable and uses it’s put(key,value) method. So we just override that method to do the duplicate key detection.

This was also addressed using Groovy scripting in this post, “Remove duplicate lines using Groovy”.

Source also available as a gist.

package com.octodecillion.util;

import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
 * Detect duplicate properties when loading Properties from stream.
 * <p>
 * 
 * @author jbetancourt
 * @since Nov 18, 2015
 */
public class DuplicatePropertyDetectorWithSubClass {

	/**
	 * Detect duplicate keys in Properties resource.
	 * <p>
	 * @see Properties#load(Reader)
	 * 
	 * @param reader The reader is <b>NOT</b> closed.
	 * @return Map Map where map key is duplicated key and list is values of those keys
	 * @throws IOException reading the stream
	 * @throws Exception 
	 */
	public Map<String, List<String>> load(Reader reader) throws Exception {
		if(reader==null){ throw new NullPointerException("reader cannot be null");}
		final Map<String, List<String>> results = new HashMap<>();
		
		Properties props = new Properties(){
			private static final long serialVersionUID = 1L;

			@Override
			public synchronized Object put(Object key, Object value) {
				if (this.containsKey(key)) {
					List<String> list = new ArrayList<>();
					if (results.containsKey(key)) {
						list = results.get(key);
					} else {
						results.put((String) key, list);
					}

					list.add((String) value);
				}			
				
				return super.put(key, value);
			}
		};
		
		props.load(reader);
		return results;
	}
}

Links
Nice tutorial on Anonymous classes: Anonymous Classes

Java Properties dupe key detect using CGLIB

In a prior post I used Javassist for Dynamic Proxying of Properties class’s load method. This allowed detection of duplicate keys in a Properties file.

In this post I use the Class Generation Library (CGLIB).

Listing 1, Source available at Gist

package com.octodecillion.util;

import java.io.IOException;
import java.io.Reader;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

/**
 * Detect duplicate properties when loading Properties from stream.
 * <p>
 * This version uses <a href="https://github.com/cglib/cglib/wiki">CGLIB</a> Dynamic Proxy support.
 * 
 * @author jbetancourt
 * @since Nov 18, 2015
 */
public class DuplicatePropertyDetectorWithCGLIB {

    /**
     * Detect duplicate keys in Properties resource.
     * <p>
     * @see Properties#load(Reader)
     * 
     * @param reader The reader is <b>NOT</b> closed.
     * @return Map Map where map key is duplicated key and list is values of those keys
     * @throws IOException reading the stream
     * @throws RuntimeException for any issue with proxying
     */
    public Map<String, List<String>> load(Reader reader) throws IOException {
        if(reader==null){ throw new NullPointerException("reader cannot be null");}
        
        final Map<String, List<String>> dupeResults = new HashMap<>();
        final String put_method_name = "put";
        
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(Properties.class);
        enhancer.setCallback(new MethodInterceptor() {
            @Override
            public Object intercept(Object object, Method method, 
              Object[] args, MethodProxy proxy) throws Throwable {
                if(method.getDeclaringClass() != Object.class && isPut(method.getName())) {
                    System.out.println("Putting: " + args[0]);
                    String key = (String) args[0],value = (String) args[1];
                    if (((Properties) object).containsKey(key)) {
                        List<String> list = new ArrayList<>();
                        if (dupeResults.containsKey(key)) {
                            list = dupeResults.get(key);
                        } else {
                            dupeResults.put(key, list);
                        }

                        list.add(value);
                    }
                }
                
                return proxy.invokeSuper(object, args);
            }
            
            private boolean isPut(String name) {
                return name.equals(put_method_name);
            }
        });
        
        Properties props = (Properties) enhancer.create();
        props.load(reader);

        return dupeResults;
    }
}

Links

Java Properties dupe key detect using Javassist

In a prior post, I used Commons Configuration to detect duplicate properties in a Properties file. The code was very simple.

Here I present a solution using a Dynamic Proxy class. A complexity is that though Properties extends the Map interface, that interface does not declare a load method. And, the JDK Dynamic Proxy support can only be used for interfaces, not concrete classes. The Javassist library can be used for this purpose as shown in listing 1 below.

Listing 1, dupe detect with Javassist Source Gist

package com.octodecillion.util;

import java.io.IOException;
import java.io.Reader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import javassist.util.proxy.MethodFilter;
import javassist.util.proxy.MethodHandler;
import javassist.util.proxy.ProxyFactory;

/**
 * Detect duplicate properties when loading Properties from stream.
 * <p>
 * This version uses <a href="https://jboss-javassist.github.io/javassist/">Javassist</a> Dynamic Proxy support.
 * 
 * @author jbetancourt
 * @since Nov 18, 2015
 */
public class DuplicatePropertyDetectorWithJavassist {

    /**
     * Detect duplicate keys in Properties resource.
     * <p>
     * @see Properties#load(Reader)
     * 
     * @param reader The reader is <b>NOT</b> closed.
     * @return Map Map where map key is duplicated key and list is values of those keys
     * @throws IOException reading the stream
     * @throws RuntimeException for any issue with proxying
     */
    public Map<String, List<String>> load(Reader reader) throws IOException {
        if(reader==null){ throw new NullPointerException("reader cannot be null");}
        
        final Map<String, List<String>> dupeResults = new HashMap<>();
        final String put_method_name = "put";
        
        try {
            ProxyFactory factory = new ProxyFactory();
            factory.setSuperclass(Properties.class);
            factory.setFilter(new MethodFilter() {
                @Override
                public boolean isHandled(Method m) {                    
                    return m.getName().equals(put_method_name);
                }
            });

            ((Properties) factory.create(new Class<?>[0], new Object[0], 
              new MethodHandler() {
                @Override
                public Object invoke(Object self, Method thisMethod, 
                    Method proceed, Object[] args) throws Throwable {

                    String key = (String) args[0],value = (String) args[1];

                    if (((Properties) self).containsKey(key)) {
                        List<String> list = new ArrayList<>();
                        if (dupeResults.containsKey(key)) {
                            list = dupeResults.get(key);
                        } else {
                            dupeResults.put(key, list);
                        }

                        list.add(value);
                    }

                    return proceed.invoke(self, args);
                }

            })).load(reader);

        } catch (NoSuchMethodException | IllegalArgumentException 
                | InstantiationException | IllegalAccessException
                | InvocationTargetException e) {
            throw new RuntimeException(e);
        }

        return dupeResults;
    }    
}

Links
Javassist

Java dupe key Properties detect using Commons Configuration

Java Properties files can contain duplicate key entries. This can be a problem since the Java Properties loader will just keep the last value parsed.

Not a problem for small applications, but when property files grow in number and size this can become a maintenance issue. Fortunately there are many solutions for this (I hope). This post will present a very simple method that performs duplicate key detection.

When first confronted with dupe detection goal, reading the Properties file directly and determining dupes using a HashMap sounds simple. However, you would have to duplicate the Properties file format parsing. That can get complex. For example, a property entry may use “:” or “=” to specify the key, value pair. Plus, you would have to handle the line continuations feature, and other requirements.

Commons Configuration makes this simple since its Properties loader will create lists for any duplicate property key. Thus, to detect duplicates, just find which property values are lists, see listing 1 below.

Listing 1, Duplicate key detection using Commons Config Also available as a Gist

package com.octodecillion.util;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;

/**
 * Detect duplicate properties when loading Properties from stream.
 * <p>
 * 
 * @author jbetancourt
 * @since
 */
public class DuplicatePropDetectWithCommonsConfig {

    /**
     * Detect duplicate keys in Properties resource.
     * <p>
     * <a href="">Commons Config</a> is used.
     * {@link Properties} class.
     * 
     * @see Properties#load(Reader)
     * 
     * @param reader The reader is NOT closed.
     * @param delimiterParsingDisabled 
     * @return Map of keys that are duplicated with a list value of each value of duplicate. 
     * @throws ConfigurationException 
     */
    @SuppressWarnings("unchecked")
    public Map<String, List<String>> loadWithConfig(Reader reader, boolean delimiterParsing) 
      throws ConfigurationException {
        PropertiesConfiguration config = new PropertiesConfiguration();
        final Map<String, List<String>> results = new HashMap<>();

        config.setDelimiterParsingDisabled(delimiterParsing);
        config.load(reader);

        Iterator<String> keys = config.getKeys();
        while (keys.hasNext()) {
            String theKey = keys.next();
            Object valueObject = config.getProperty(theKey);
            if (!(valueObject instanceof String)) {
                results.put(theKey, (List<String>) valueObject);
            }
        }

        return results;
    }
    
    /**
     * @author jbetancourt
     *
     */
    @RunWith(Enclosed.class)
    public static class DuplicatePropDetectWithCommonsConfigTest {
        private static final String DATA1_PROPERTIES = "/Data1.properties";

        /**
         * @throws ConfigurationException
         */
        @Test
        public void testLoadFileWithConfig() throws ConfigurationException {

            InputStream is = this.getClass().getResourceAsStream(DATA1_PROPERTIES);
            Assert.assertNotNull(is);

            DuplicatePropDetectWithCommonsConfig detector = new DuplicatePropDetectWithCommonsConfig();
            Map<String, List<String>> map = detector.loadWithConfig(new InputStreamReader(is), true);
            Assert.assertEquals(1, map.size());

            Assert.assertTrue(map.containsKey("three"));

        }
    }
}

Links

Java fluent inline map initialization

This is a common task, and there are many good and bad solutions out there. Java 8 even has a “Supplier” that can assist with inline map initializations.

Unfortunately, Java does not have a simple method like that found in the Groovy language. A map in Groovy is:

def map = [name: ‘Gromit’, likes: ‘cheese’, id: 1234].

 
I implemented a builder in Java 7 that is just simple syntax sugar. This is before I found Per-Åke Minborg’s great blog post Java 8, Initializing Maps in the Smartest Way on the topic, or the others found online. Perhaps I was using the wrong search. Hmm.

Using my version without all the Generics details:
Map codes = InitMap.with(new HashMap())
   .put(“xyz”,”321″).put(“abc”,”362″).toMap();

Alternatively, you can create a Map instance and use the builder, no need to invoke toMap():
Map<String,String> map = new HashMap<>();
InitMap.with(map).put(“xyz”,”321″).put(“abc”,”362″);

How does it work? InitMap is just a “partial” Decorator. When you create the InitMap object the Map parameter is stored in a field. Then when you “put” key/values, they becomes a ‘put’ to the hidden map. This allow you to chain the ‘put’s. When your done adding entries, you invoke toMap() to get the actual Map instance. The simplest thing that works.

Not too sure about the Generics stuff. Generics are like a loose thread on a coat; if you keep pulling on it, soon you’ll have no coat.*

Jump to source

Links

Footnotes

*This leads, me anyway, to wondering how do you test compile only concerns, like generics? Sure, compile errors are thrown if you try to use Generics type-safe code incorrectly. But, how do you know your generics code is meeting the requirements, or that future maintenance would not still enforce the requirements?

Hmm. Only thing I can think of is you have to write unit test that invoke a Javac compiler on strings of source code.


Source Section

  • Java 8, but not the new JDK features.
  • Eclipse Mars for development

Listing 1, InitMap and tests implementation, full source Gist

Toward predictive interfaces: 'Google Now on tap'

In a prior post I compared “Google Now” and the concept of a Proactive User Interface. It looks like ‘Google Now on tap’ will finally be a step in the right direction.

My first impression from a quick read of some articles is that it is an expansion of the info cards concept with more correlation with current UI context. This is such a powerful, and an extremely obvious feature, that you wonder why this was not done years ago. True, Google will put more search and Big Data power behind this. But, is it really predictive and will it “learn” a users information patterns?

An information pattern example (from my prior post) is a User is viewing a web site. There is a probability that if a certain amount of time is spent or a certain page or article type is visited, that clicking a share button will be followed by predictable actions. For example, sharing a link with a colleague or loved one. The UI presented will then present a proactive plan. See “Proactive User Interface“. Generating information related to context is still requiring the user to perform wasted effort to form and act on immediate action plans. So what are those octocore chips for?

Proactive Interface v2
Diagram of idea

Updates

  • Nov 9, 2015: Google just open sourced a Machine Learning system, TensorFlow.

Links

Remove forced uppercase from WordPress post titles

The new Theme for this blog converted the titles to all uppercase. What possible UI design decision was that? Just makes no sense.

Anyway, fortunately there is a “helpful” wordpress documentation page that shows how to change this: create a child theme for your changes. This is on WordPress’s Codex. I found that link by a forum discussion, [resolved] [closed] How to change site title from all caps to lower case.

It worked! And, I don’t even know how to code WordPress. Those instruction are not very clear. For example, it mentions that you may have to do something different if the Theme uses multiple css files. Do what exactly? And my current Theme “twentyforteen” does have multiple css files, though not in the root folder.

What did I do? Created the two files, style.css and functions.php. FTP’d them to a new folder twentyfourteen-child. Then enabled the new Theme “twentyfourteen-child” in my blog.

Listing 1, style.css

/*
 Theme Name:   Twenty Fourteen Child
 Theme URI:    http://example.com/twenty-Fourteen-child/
 Description:  Twenty Fourteen Child Theme
 Author:       John Doe
 Author URI:   http://example.com
 Template:     twentyfourteen
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Tags:         light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
 Text Domain:  twenty-fourteen-child
*/
.entry-title {
	font-size: 33px;
	font-weight: 300;
	line-height: 1.0909090909;
	margin-bottom: 12px;
	margin: 0 0 12px 0;
	text-transform: none;
}

Listing 2, functions.php

<?php
/**
 * Twenty Fourteen child functions and definitions
 *
 *   ALL THE DETAILS FROM CODEX ARTICLE
 *
 * @package WordPress
 * @subpackage Twenty_Fourteen
 * @since Twenty Fourteen 1.0
 */

add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

}

I repeated the steps here so I have a reference to what worked in my situation.

Note 4 can't connect USB to Windows 7 PC

Tried a few things trying to connect Samsung Galaxy Note 4. Only thing that worked was uninstalling the Samsung driver in the Device Manager of PC. Then when you connect the phone with a USB cable, there should be an auto detection and installing of the drivers. Three things are installed

Of course, your cable must be the right kind (not just a power cable) and so forth.

I got the tip by “xfaega” at: http://forum.xda-developers.com/showpost.php?p=49040275&postcount=19

Strange that this was always working then stopped. I wonder if it was that attempt to update Android recently that was continually interrupted. Darn amazing phones.