Friday, August 24, 2018

Manipulate colors separately in bitmap

SOLVED

I have an array holding pixel values as Java int (32bit) thus in the form AARRGGBB I want to manipulate colors indipendently, so my source image will turn more green, or more red or more blue. How can I do this in Java? (this code works now)

/* Extract green from pixel (0-255)
 * short is 16 bit, because all Java types are signed
 * so a Java byte would be-128 +128 */
short green = (short) ((pixel >> 8) & 0xff);
// Add some amount
short newGreen = green + 50;
green = (newGreen > 255) ? (short)255 : newGreen;
// Now final step
int mask = 0xffff00ff;
pixels[index] = (pixel & mask) | ((green & 0xff) << 8);

SOLVED

Solved

           public static void toGreenScale(BufferedImage bi){
                   for (int i = 0; i < bi.getWidth(); i++){
                        for (int j = 0; j < bi.getHeight(); j++)
           {
             int rgb = bi.getRGB(i, j);
             int red = (rgb >> 16) & 0xFF;
             int green = (rgb >> 16) & 0xFF;
             int blue = (rgb >> 16) & 0xFF;

             int r= (red   << 16) | (red   << 8) | red;
             int g = (green << 16) | (green << 8) | green;
             int b = (blue  << 16) | (blue  << 8) | blue;
              g=g+50;//add an if condition to handle if g>255
              Color c=new Color(r,g,b);
           bi.setRGB(i,j,c.getRGB(););}
           }

}

Monday, August 20, 2018

Close/abandon projects/branches strategy on SVN?

I was wondering what's the recommended strategy when a project or branch gets finished (will never ever be changed again) or abandoned.

In case of the projects, should I:

  • Leave it as it is
  • Have a repository root folder where all the projects get moved to when they are finished/abandoned
  • Just rename the folder to something like "CLOSED - Project Name"
  • Move it to a new repository that contains all the closed projects (I think this isn't a very good idea since I would lose all the history)
  • Another solution?

In case of the branches, should I:

  • Leave it as it is
  • Move it to a folder inside the branches named CLOSED or ABANDONED
  • Rename the branch to "Closed - Branch Name"
  • Another solution?

Solved

You can just delete it. All the history will be retained inside the repository - the repository (almost) never forgets.

You can access it using the command line tools by specifying a peg revision:

svn command item@PEG-REV

In TortoiseSVN you can go back in time by setting the peg revision using this button:

Repo-Browser

If you don't know the correct peg revision, use the log to find it.


I would recommend using proper tagging approach for the purpose of tracking latest project/branch state. Even though branch history is kept in a repository after it has been deleted, sometimes it is difficult (or just takes a long time) to find latest branch state of the deleted branch using peg revisions.

As for me, I use fine-grained tagging approach which can be illustrated by the following diagram (here you can find more detailed diagram representing the same principles):

tagging approach

As you can see, it uses specific convention of structuring your repository. Tags directory will have following subdirectories:

/tags
    /builds
        /PA
        /A
        /B
    /releases
        /AR
        /BR
        /RC
        /ST

PA means pre-alpha A means alpha B means beta AR means alpha-release BR means beta-release RC means release candidate ST means stable

Following described convention, you will have specific directories structure in your repository:

/tags
        /builds
            /PA
                /1.x.0
                /1.x.3
                /2.x.0
            /A
                /1.x.1
                /1.x.4
                /2.x.1
            /B
                /1.x.2
                /1.x.5
             -> /2.x.2 <-
        /releases
            /AR
                /1.0.0
            /BR
                /1.0.1
            /RC
                /1.0.2
                /1.0.3
            /ST
             -> /1.0.4 <-

It is expected that before you delete branch, you create tag in corresponding directory. And then you can easily find latest states of your deleted branches in, for example, tags/builds/B or tags/releases/ST directories.


I have a dislike for deleting old projects from Subversion. Although many people say that they will always exist in the history, the fact is that it's really not discoverable, as you have to start picking random dates in the past to find out where the project was and then when it was deleted. If you don't know the exact name of what you're looking for then finding deleted items in Subversion is really non-trivial.

I prefer a different strategy of creating a top-level directory in SVN called 'archive'. Any old projects are moved there so that you retain the advantage that old projects no longer appear in the trunk, but if you need to consult the source for the old project then it's very easy to find, and it keeps the old defunct projects in one place.

In my case the repository structure is something like this:

/trunk
/tags
/branches
/archive
  /projects

Sunday, August 19, 2018

function_score: treat missing field as perfect hit

What I need to do is boost documents by location (closer is better). locations is nested type.

Works fine except Elasticsearch does not return documents if locations is missing in document. If fields is missing, Elasticsearch should treat document as perfect hit. Any idea how to achieve this?

My query:

{
   "sort": [
      {
         "_score": "desc"
      }
   ],
   "query": {
      "function_score": {
         "query": {
            "bool": {
               "must_not": [],
               "should": [
                  {
                     "nested": {
                        "path": "locations",
                        "query": {
                           "function_score": {
                              "score_mode": "sum",
                              "functions": [
                                 {
                                    "gauss": {
                                       "locations.coordinates": {
                                          "origin": {
                                             "lat": "50.1078852",
                                             "lon": "15.0385376"
                                          },
                                          "scale": "100km",
                                          "offset": "20km",
                                          "decay": "0.5"
                                       }
                                    }
                                 }
                              ]
                           }
                        }
                     }
                  }
               ]
            }
         }
      }
   }
}

BTW: I'm using Elasticsearch 5.0

Solved

Add one more function into the functions section with high boost (like 1000) for missing locations, something like this:

{
    "query": {
        "bool": {
            "must_not": {
                "exists": {
                    "field": "locations"
                }
            }
        },
    },
    "weight": 1000
}

So records with missing locations will come first because of high weight.

Syntax can differ a little. More information on queries here:

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html


Friday, August 17, 2018

How does one add the reference to use the SOAP API C#?

I want to make an application that automatically deploys reports made in SSRS to the reporting server. I found that the best way to do this is by using SOAP.

I have been searching on this topic for a little while now and I don't see anyone saying how to add the SOAP API reference to a Visual Studio project.

This page page seems like it is directed toward the complete beginner with this API (which I am), yet it does not cover step #1 in actually using the API, which would be to add the reference. What using statement should I use, and/or what is the name and location of the DLL which needs to be specified, in order to start using the API?

Solved

I have never done it before until just now but it looks like you just need to add a Service Reference in Visual Studio. Since SQL 2008 R2 the URL looks like this:

http://server/reportserver/ReportService2010.asmx?wsdl  

For more information see this MSDN page.


As mentionned by SMM, you simply have to add a web service reference to your Visual Studio project. Go to "Project" menu, and click on "Add a service reference...". Then put your SSRS service address in the window that shows as explained in previous post, and... that's it !

A new folder "Web reference" is now present in your project, with an item inside, representing the reference to the SOAP web service you add.

Let me know if you have some trouble. Regards,