Friday, August 24, 2018

Jmdns not resloving service

I followed the example that comes with JmDNS. My code is as below!

jmdns = JmDNS.create();
jmdns.addServiceListener("_nmx._tcp.local.",new ServiceListener() {

                            @Override
                            public void serviceResolved(ServiceEvent event) {
                                // TODO Auto-generated method stub
                                Log.e("called","serviceResolved");
                            }

                            @Override
                            public void serviceRemoved(ServiceEvent event) {
                                // TODO Auto-generated method stub

                            }

                            @Override
                            public void serviceAdded(ServiceEvent event) {
                                // TODO Auto-generated method stub
                                Log.e("called","serviceAdded");
                                Log.e("val:",event.getType()+":"+event.getName());
                                ServiceInfo info = event.getInfo();
                            //  Log.e("name",info.getHostAddress());
                                jmdns.requestServiceInfo(event.getType(), event.getName());

                            }
                        });
                    }

I never see "called serviceResolved" log message. But i see service added log message. Is there anything else should i do to resolve the service to get the ip of the host?

Monday, August 20, 2018

docker compose not finding file in gitlab job

I'm running a gitlab-ci.yml job with a gitlab-runner which is using the docker executor with the docker.sock mounted from the host (set in the config file).

docker composes run.sh file located here: https://github.com/docker/compose/blob/master/script/run/run.sh doesn't seem to find the docker-compose.lint.yml file I need it to run.

Part of the gitlab-ci.yml file:

Lint from image:
  <<: *temp
  stage: Lint
  script:
    - ls -a
    - cat docker-compose.lint.yml
    - . docker-compose_run.sh -f docker-compose.lint.yml up --remove-orphans --force-recreate --abort-on-container-exit

Dockerfile of the image that the gitlab-ci.yml file is using:

FROM debian:stretch

# Set Bash as default shell
RUN rm /bin/sh && \
    ln --symbolic /bin/bash /bin/sh

    # apt-get
RUN apt-get update && \
    apt-get install -y \
    # Install SSH
    openssh-client \
    openssh-server \
    openssl \
    # Install cURL
    curl \
    # Install git
    git \
    # Install locales
    locales \
    # Install Python
    python3 \
    python-dev \
    python3-pip \
    # Build stuff
    build-essential \
    libssl-dev \
    libffi-dev \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg2 \
    software-properties-common

# Install Docker
    # Add Docker’s official GPG key
RUN curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | apt-key add - && \
    # Set up the stable repository
    add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
   $(lsb_release -cs) \
   stable" && \
    # Update package index
    apt-get update && \
    # Install Docker CE
    apt-get install -y docker-ce

    # pip
RUN pip3 install \
    # Install Docker Compose
    docker-compose

# Set locale
RUN sed --in-place '/en_US.UTF-8/s/^# //' /etc/locale.gen && \
    locale-gen && \
    # Set system locale (add line)
    echo "export LANG=en_US.UTF-8" >> /etc/profile && \
    # Set system timezone (add line)
    echo "export TZ=UTC" >> /etc/profile

Job output:

...more stuff above here
$ ls -a
.
..
.clocignore
.dockerignore
.eslintignore
.eslintrc.json
.git
.gitignore
.gitlab-ci.yml
.nvmrc
.nyc_output
Dockerfile
README.md
__.gitlab-ci.yml
bin
build.sh
build_and_test.sh
coverage
docker-compose.lint.yml
docker-compose.test.yml
docker-compose_run.sh
lib
package-lock.json
package.json
stop.sh
test
test.sh
wait-for-vertica.sh
$ cat docker-compose.lint.yml
version: "3"

services:
  ei:
    image: lint:1
    environment:
      - NODE_ENV=test
    entrypoint: ["npm", "run", "lint"]
$ . docker-compose_run.sh -f docker-compose.lint.yml up --remove-orphans --force-recreate --abort-on-container-exit
.IOError: [Errno 2] No such file or directory: u'./docker-compose.lint.yml'
ERROR: Job failed: exit code 1

Sunday, August 19, 2018

'apkanalyzer' is not recognized as an internal or external command

I often compare my new build apk size with the production build and I am looking for options to automate this activity such that it compares both new and prod apk sizes and reports me. I am aware of APK Analyzer of Android Studio but I want to do that using command-line tools. This doc lists the usage of apkanalyzer but upon running this command

apkanalyzer -h apk file-size myapk.apk

It says "'apkanalyzer' is not recognized as an internal or external command, operable program or batch file." though I have already set the environment path to \Android\sdk\tools\bin.

Not sure why command-line is not recognizing this command, could you let me know where I could possibly have gone wrong or is there any other way to check apk file size using command-line?

Thanks for any help in advance.

Solved

This means that apkanalyzer does not exist in your SDK path.

To download it, just got to SDK Manager and click on Android SDK Tools, then click Ok to continue and download the missing tools.

SDK manager


APKAnalyzer tool is fully loaded with the Android Studio.

APK Analyzer tool is available in android studio https://developer.android.com/studio/build/apk-analyzer.html.

Most the command executable options can be used just with the good UI available in the Android Studio.


The apkanalyzer file (with no extension) in my sdk>tools>bin installed on my windows 10 pc is a Unix Shell script. Windows doesn't recognize this file as a valid command.

This appears to be a bug in the windows install of the Android SDK Tools 26.1.1.


As others have mentioned, make sure you have installed the Android SDK Tools via the SDK Manager. They should show up in /tools/bin. A long time ago I added /tools to my $PATH in my ~/.bash_profile, but never added /tools/bin; apparently I missed the note that as of SDK Tools, Revision 25.3.0 tools were deprecated or otherwise moved to there among other places.

Seee also https://developer.android.com/studio/command-line/ for details on the regular Tools, Build, Platform, and Emulator tools.


Friday, August 17, 2018

Generating an array of integers without violating constraints

I am struggling with a problem for hours. It is a constraint satisfaction problem. Let me describe it on a simple example:

Assume there is an array of integers with length 8. Every cell can take certain values. First 4 cells can take 0, 1 or 2 and the other half can take 0 or 1. These 3 arrays can be some examples.

{2,1,0,2,1,1,0,1}
{2,2,1,0,0,1,0,0}
{0,0,0,2,0,0,0,1}

However there are some constraints to construct the arrays as follows:

constraint1 = {1,-,-,-,-,1,-,-}  // !(cell2=1 && cell6=1) cell2 and cell6 can not be in these format. 
constraint2 = {0,-,-,-,-,-,-,0}  // !(cell1=0 && cell8=0)
constraint3 = {-,-,-,2,1,1,-,-}  // !(cell4=2 && cell5=1 && cell6=1)
constraint4 = {1,1,-,-,-,-,-,-}  // !(cell1=1 && cell2=1)

For better understanding;

{0,1,1,2,0,1,0,0}  // this is not valid, because it violates the constraint2
{1,1,2,2,1,1,0,1}  // this is not valid, because it violates the constraint3 and constraint4
{1,1,0,0,0,1,0,0}  // this is not valid, because it violates the constraint4

I need to generate an array of integers which does not violates any of the given constraints.

In my approach;

1) Create an array (called myArray) and initialize every cell to -1
2) Count the number of cells which are used in constraints. Above example, cell1 is used 3 times, cell2 is used 1 time, cell3 is not used, so on so forth.
3) Choose the cell which is used more in constraints (it is cell1, used 3 times)
4) Find the distribution of numbers in this cell. (In cell1, 1 is used 2 times and 0 is used 1 time)
5) Change this chosen cell in myArray to the number which is used less. (In cell1, since 0 is used less than 1, cell1 in myArray will be 0) 
6) Delete all the constraints from the list which has 1 or 2 in their cell1.
7) Go to step 2 and do same steps until all constraints are eliminated

The idea of this algorithm is to chose the cell and its value in such a way that it will eliminate more constraints.

However, this algorithm is not working, when the number of constraints are higher.

Important Note: This is just a simple example. In normal case, length of the array is longer (averagely 100) and number of constraints is higher (more than 200). My input is length of the array, N constraints and the values each cell can take.

Is there anyone who has better idea to solve this problem?

Solved

Here is a code that I have written in C# to generate a random matrix and then to remove the constraint in the matrix.

class Program
{
    static void Main(string[] args)
    {

        int[] inputData = new int[4] { 3, 7, 3, 3 };
        int matrixRowSize = 6;

        /////////////////////////// Constraints 

        int []constraint1 = new int[4] { 1, -1, -1, 2}; // here is the constaint that i want to remove.
        // note the constaints could be more than 1, so there could be a generic method

        Random r = new Random();
        int[,] Random_matrix = new int[matrixRowSize, inputData.Length];
        ///////////// generate random matrix 
        for (int i = 0; i < inputData.Length; i++)
        {
            for (int j = 0; j < matrixRowSize; j++)
            {       
                int k = r.Next(0, inputData[i]);  


                Random_matrix[j, i] = k;
            }
        }

}