mercredi 22 février 2017

Is there common approach to encapsulate xml data structure changes?

I'm working out a program module, that designed to get data as tree with strict structure. For storing it use a xml format.

But, just appeared situation when I need to do the same task with another data structure, that can be converted to previous one. And in future there is perspective that new data will have another structure too.

Is there any general solution for such a problem?

PS. For now, it's seemed to be good solution to make a module, that would get xslt stylesheet and xml and after that by use of xslt processor give me appretiate xml structured data.

Performance code of wrappering

Question: What is the performance cost of wrapping an object inside of another object? Both in RAM and CPU usage increase from calling the object directly.

Extra Details: I'm working on developing a framework that will wrapper code to isolate plugins from the core implementation of a program. The question keeps popping up in my head "What is the performance cost". I know it will be more than direct access to the code being wrapped. However, I can not seem to find any solid sources or data online to show exactly what results to expect. Which is an issue as I'm developing this to replace the implementation for roughly 40 projects. So when asked what level of overhead is expected in the update I need to have some data.

Also, in case anyone is unsure what I mean by wrapped code. It is the process in which an object is created using an interface that sends all method calls to an object stored in the object. This is done to hide the implementation of an object when the original object can not be modified or changed to include the interface. Below is an example of what I'm talking about.

public class WrapperObject implements WrapperInterface
{
    private SomeObjectClass theObject;

    public WrapperObject(SomeObjectClass theObject)
    {
        this.theObject = theObject;
    }

    public void method1()
    {
        theObject.method1();
    }

    public void method2()
    {
        theObject.method2("someData", 1);
    }
}

As well I do know about JIT in java and other optimization technics the JVM does. I'm asking what I can expect from the overhead of using a system like this for a large project. As I will be wrapping or converting just about everything before it gets to the plugin code. This includes methods that may be called a few 1000 times a second as well as methods only called once.

I will also be building prototypes in the next few days to test performance as well. I'm just looking for some design input to better understand what to expect. Rather than looking blindly at my code making guesses that waste time.

Grep two words with their subsequent words from a json file

I want to grep a combination of two words from a huge log file, the words are scattered and not in any particular order.

     Sample log :
    {"1a":"2017-01-28 00:00:00","2a":"sample","a":"12345","b":"2017-02-06","c":"2017-02-06T17:51:02.454-08:00","d":"Mozilla/5.0
    ; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1","e":"2017-02-06 
    ","f":"03","g":"example","h":"logA","i":"IFX","j":"a85","k":"12345678"},
{"1a":"2017-01-28 00:00:00","2a":"sample","a":"12345","b":"2017-02-06","c":"2017-02-06T17:51:02.454-08:00","d":"Mozilla/5.0
    ; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1","e":"2017-02-06 
    ","f":"03","g":"example","h":"logB","i":"IFX","j":"a85","k":"12345678"}

In this file, I want to grep "1a":"" and "h":"" which there should not be any duplicates

I tried using egrep this way but it gives the entire line :

egrep -oE '1a\|"h"' but this does not give the required output.

awk /pattern1/ && /pattern2/ filename #no use

Thanks for the help

Angular2 shared/core module in lazy

I have 4 feature modules which will be loaded lazy. Have multiple popups components, which is need for the feature modules. Currently i have created a shared module which will export these component and each feature module will import this shared module. The tradeoff for this kind of design is, the shared module will be included in all the feature bundles. The problem is some popup component is not needed in some feature module.

Any ideas?

How to solve double update cost to cache and remote database?

I am working on a web application caching big amount of data on front for better performance. The issue I am facing is that I need to update data in many ways and each update needs to be done on cache and on remote database which leads to double updating effort. I am asking for any best practice / design pattern to make this scenario easier to deal with.

I am using Angular 2 if this would change anything about the answer

mardi 21 février 2017

How do I use the SPA and Front Controller with in php?

For example, http://ift.tt/1fljiJ4

If you click another menu, url is in the form of a Front Controller, but Chrome's network tool will not redirecting the existing page.

example frontController.php

// require_once './index.php';

if ($_SERVER['REQUEST_URI'] == '/test1') {
  include 'test1.php';
} else if ($_SERVER['REQUEST_URI'] == '/tmp') {
  include 'tmp.php';
} else {
  include 'notfound.php';
}

always redirect index.php , I think it is natural.

How can I get it(SPA main file - index.*) to be called once?

What is best way to connect data from different services and use them with ng-model

I'm new to angular and to design some complicated things...

I have two services: phrasesService and translationsService, they stores two objects:

phrases = [ {text: "phrase1"}, {text: "phrase2"}, {text: "phrase3"} ]
    
translations = [ { language: "russian", phrases: ["phrase1", "phrase2", "phrase3"] }, { language: "hindi", phrases: ["phrase1", "phrase2, "phrase3"] }]

And I have methods to get translations:

getTranslationsInLang(lang) , that returns array of phrases in lang and getPhraseTranslation(lang, numPhrase) , that returns translation of one phrase

Now I want to display phrases and their translations in inputs (for editing):

<input class="form-control phrase-text" type="text" ng-model="phrase.text">
<input class="form-control translation-text" type="text" ng-model="????.translation">
  1. What is the best way to realize this, for store all data and display it for editing?
  2. And what should I use in ng-model for translation input?