import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
static class SerDe<T> {
public static <T> String serialize(T obj) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, As.PROPERTY);
return mapper.writeValueAsString(obj);
}
public static <T> T deserialize(String s, Class<T> clazz) throws JsonProcessingException, IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, As.PROPERTY);
return mapper.readerFor(clazz).readValue(s);
}
}
środa, 23 września 2015
Generic JSON SerDe with Jackson2
czwartek, 9 kwietnia 2015
Remmina, Freerdp - how to change keyboard layout on target windows machine
Cannot type underscore sign - question mark is put instead? Most probably keyboard layout is wrong.
Check what keyboard layout you have set at the moment.
$ setxkbmap -query rules: evdev model: pc105 layout: pl,usAbove we can see two layouts in order: "pl" followed by "us". Lets switch them.
setxkbmap -layout us,plNow try to reconnect to the server. Underscore is again underscore ;)
piątek, 3 kwietnia 2015
3 most appealing WYSIWYG HTML editor widgets
Three most promising and most appealing WYSIWYG online html editor widgets
1. Quill
Quill is a free, open source WYSIWYG editor built for the modern web. With its extensible architecture and a expressive API you can completely customize it to fulfill your needs.Some built in features include:
- Fast and lightweight
- Semantic markup
- Standardized HTML between browsers
- Cross browser support including Chrome, Firefox, Safari, and IE 9+
- Get fine-grained access to editor contents and event notifications.
- Works across all modern browsers on desktops, tablets and phones.
- It's easy to add custom behavior or modifications on top of Quill.
- Quill is open source.
URL: http://quilljs.com
2. Aloha
Aloha Editor provides you capabilities to create editing experiences embedded seamlessly in your web application.- Use the clean and modern user interface of Aloha Editor, customize it or use the one you already have.
- Aloha Editor is a stand alone library with a functional and stateless API that provides you with essential editing capabilities not available in browsers.
- GPL v2 or commercial license
URL: http://www.alohaeditor.org
3. Froala
URL: https://editor.froala.com
wtorek, 17 marca 2015
This account is currently not available - how to execute command as user with nologin shell set
How to run a command as a user without bash shell set?
There is actually one nifty way to do this - use thesu command with combination of two options s and c.
# su -s /bin/bash -c 'touch /tmp/file'What actually will happen here is basically overriding configured shell with the one passed with
"-s" option.
How to run a long operation with a spinner/hourglass indicator within eclipse plugin (swt application) ?
From time to time there is a need to run some relatively long operation synchronously. In such a case will be good to indicate the fact to the user. There is very simple way of doing this with
BusyIndicator class.
Just replace syncExec with BusyIndicator.showWhile.
Display.getCurrent().syncExec(new Runnable() {
@Override
public void run() {
// long operation
}
});
with the following:
BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
@Override
public void run() {
// long operation
}
});
How to invoke java method with a time limit?
Java has no handy way to do so. You can always use Thread to run a method and after some time out interrupt it.
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class Test {
public static void main(String[] args) throws InterruptedException, ExecutionException, TimeoutException {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future future = executor.submit(new Runnable() {
@Override
public void run() {
try {
TimeUnit.DAYS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
try {
future.get(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
future.cancel(true);
throw e;
} catch (TimeoutException e) {
future.cancel(true);
throw e;
}
}
}
Maven 3.2.3 internals - how it works
- private MavenExecutionResult doExecute(MavenExecutionRequest request)
Executing maven request contains the following steps:
1). Sets starting time to the request object 2). Instantiates result container object 3). Validates local repository 4). Creates new repository session (RepositorySystemSession) 5). Instantiates new maven session object (for future purposes lets call it just "session") 6). Notifies AbstractMavenLifecycleParticipant listeners that session has been started 7). Fires ExecutionEvent.Type.ProjectDiscoveryStarted event with created session to the EventCatapult instance 8). Gathers projects for maven reactor and puts them into session 9). Validate projects (building plugins with extensions cannot be part of reactor) - puts just warns 10). Creates projects dependency graph 11). Quits if any exceptions occurred so far 12). Creates ReactorReader and updates session with sorted projects list and projects map (MapAd 8. Collecting all projects
private void collectProjects( Listprojects, List files, MavenExecutionRequest request )
ProjectBuildingRequest projectBuildingRequest = request.getProjectBuildingRequest(); ListIn project builder build method ReactorModelPool is created which is intended to holding all POM files that are known to the reactor. This allows the project builder to resolve imported POMs from the reactor when building another project's effective model. Next the project builders iterate through all pom files and for each creates MavenProject which is passed to DefaultModelNuildingListener and set on ModelBuildingRequest instance. Now the ModelBuilder object comes into play. ModelBuildingRequest instance is passed into build method. After some initial helper objects instantiations the readModel method is invoked.results = projectBuilder.build( files, request.isRecursive(), projectBuildingRequest );
private Model readModel(ModelSource modelSource,
File pomFile,
ModelBuildingRequest request,
DefaultModelProblemCollector problems) throws ModelBuildingException
DefaultModelProcessor instance do the read.
public Model read( InputStream input, MapFinally the new instance of MavenXpp3ReaderEx is created and read method invoked. Once model is done it is registered in projectIndex map.options ) throws IOException
If project is recursive and contains modules it locates pom.xml for each and add it to moduleFiles list. Such prepared list is again passed into the same build method as the initial aggregator pom file. Once all projects are build, next step is populating ReactorModelPool object, created at the beginning. It goes through all interim results and registers all models
//DefaultProjetBuilder:593 private void populateReactorModelPool( ReactorModelPool reactorModelPool, ListinterimResults ) { for ( InterimResult interimResult : interimResults ) { Model model = interimResult.result.getEffectiveModel(); reactorModelPool.put( model.getGroupId(), model.getArtifactId(), model.getVersion(), model.getPomFile() ); populateReactorModelPool( reactorModelPool, interimResult.modules ); } }
Subskrybuj:
Posty (Atom)


