ibus-daemon -rdPS. Check batteries in your keyboard if restarting does not help :)
środa, 23 grudnia 2015
Quick fix for non-responding keyboard in Ubuntu
In order to unlock keyboard just restart ibus deamon
Fun with awk - how to aggregate column values in bash
How to aggregate values in particular column
for i in $(ls); do du -sm $i; done | awk '{s+=$1;print s,$0} END{print "S:",s}'
środa, 16 grudnia 2015
Quick fix for disappeared time panel in Unity top bar
Forcing restart of unity-panel by killing it do the job. Ingenious ;D.
sudo killall unity-panel-service
poniedziałek, 14 grudnia 2015
How to format xml with xmllint using tab
instead of double space
using tab
instead of double space
Using xmllint is very handy way of formatting xml, but suffers from limitted formatter options. Luckly the most crucial is available but not very straitforward to use.
xmllint is using XMLLINT_INDENT system variable for setting characters sequence used as indentation.
To set it as
\t
character you need a special trick ($'\t')
$ export XMLLINT_INDENT=$'\t'Now every
xmllint --format
will use tab for indentation.
Setting formatting command for vim.
map @@x !%xmllint --format --recover -^M
Simplified code review exchange format
If i am wrong but i don't know any unified format for code review result exchanging. Something that should be obviously available and shared among dozens of utilities
schema.yaml
sourcefile
revision
line
offset (opt)
comment
author
date
niedziela, 13 grudnia 2015
Eclipse Plugin - How to add error validation markers for
Register
org.eclipse.core.resources.markers
extension point
Declare constant (optional)
interface Constants { String MARKER_VALIDATION_ERROR = "org.myapp.validation.problem"; }Delete all validation markers for assigned to processed file.
private static boolean deleteMarkers(IFile file) { int markersCount = 0; try { markersCount = file.findMarkers(Constants.MARKER_VALIDATION_ERROR, false, IResource.DEPTH_ZERO).length; file.deleteMarkers(Constants.MARKER_VALIDATION_ERROR, false, IResource.DEPTH_ZERO); } catch (CoreException e) { throw Throwables.propagate(e); } return markersCount > 0; }Compute and add new validation marker:
private static void addMarker(IFile file, String message, int severity, ModelObject model, Expressionexpression) throws CoreException { IMarker marker = file.createMarker(Constants.MARKER_VALIDATION_ERROR); marker.setAttribute(IMarker.MESSAGE, message); marker.setAttribute(IMarker.SEVERITY, severity); marker.setAttribute(IMarker.SOURCE_ID, model.getId()); logger.debug("Marker created: " + file + ", attr: " + marker.getAttributes().keySet()); }
How to deploy chosen artifacts of multimodule maven application
In case there is
parent module
you need to install also this parent pom.
REPO_ID=myRepoIdDefinedInSettingsXml && \ REPO_URL=http://example.com/nexus/content/repositories/releases && \ VERSION=2.3.1 && \ /usr/local/bin/mvn deploy:deploy-file \ -DgroupId=${GROUP_ID} \ -DartifactId=${PARENT_ARTIFACT_ID} \ -Dpackaging=pom \ -Dversion=${VERSION} \ -DrepositoryId=${REPO_ID} \ -Durl=${REPO_URL} \ -Dfile=build/release-*/pom.xml && \Once parent module is installed (but in fact doesn't need to be first) we can install our modules (MODULE1, MODULE4 and MODULE_N). Installing sources is optional (if your package phase does not generate source bundle - just skip
-Dsource
option.
for ARTIFACTID in MODULE1 MODULE4 MODULE_N; do \ for FILE in $(find target/${ARTIFACTID} -name "${ARTIFACTID}*.jar" | grep -v sources); do \ /usr/local/bin/mvn deploy:deploy-file \ -DgroupId=${GROUP_ID} \ -DartifactId=${ARTIFACTID} \ -Dversion=${VERSION} \ -DpomFile=$(dirname ${FILE})/../pom.xml \ -Dpackaging=jar \ -DrepositoryId=${REPO} \ -Durl=${REPO_URL} \ -Dfile=$(dirname ${FILE})/${ARTIFACTID}-${VERSION}.jar \ -Dsources=$(dirname ${FILE})/${ARTIFACTID}-${VERSION}-sources.jar; \ done; \ done; \
How to run sql script against H2 file database with single command
There are cases when the quickest way to fix database is by running some sql script.
Assuming you have used h2 in the past you're most likly have h2 driver in your m2 repo.
Once you found it try the following:
java -cp h2*.jar org.h2.tools.RunScript -url <URL> -script init.sqlwhere URL is default jdbc string and can be
jdbc:h2:~/test
poniedziałek, 30 listopada 2015
Java8 - Top most useful "default method" appliances.
- Creating dummy default implementations
- Default interfaces - making interfaces functional
- Brings utility functions from couple sources
wtorek, 17 listopada 2015
How to get around git aliases?
Are you tired with typing the same long git commands? Here you are the solution. GIT ALIASES!!
Here you have a bundle of most useful:
git config --global alias.hist "log --pretty=format:'%h %s%d [%an]' --graph --date=short"
git config --global alias.lol "log --graph --decorate --pretty=oneline --abbrev-commit --all"
git config --global alias.sts status
git config --global alias.co checkout
git config --global alias.newbranch 'checkout -b'
git config --global alias.last 'log -1 HEAD'
git config --global alias.unstage 'reset HEAD --'
poniedziałek, 2 listopada 2015
"Expected CSRF token not found. Has your session expired?"
Exception:
org.springframework.security.web.csrf.MissingCsrfTokenException
It is produced when CsfrFilter when doing filtering find that
It is generated when token loaded from token repository (CsrfTokenRepository)
czwartek, 29 października 2015
poniedziałek, 12 października 2015
[PDE] How to find out all plugins that given extension point is used
There are two ways to do so from PDE UI level. First is by opening "Open Plug-in Artifact" view (
Ctrl + Shift + A
) - technically org.eclipse.pde.internal.ui.search.dialogs.FilteredPluginArtifactsSelectionDialog
class.
Once you type "expressions.propertyTesters" in filter box and deselect all but "Show Extension" item hidden under black triangle on the right, the matching items will contain all plugins are using "org.eclipse.core.expressions.propertyTesters" extension point.
The another way is using default Search Dialog (Ctrl + H
). The last tab is "Plug-in Search".
- Search For: Extension Point
- Limit To: References
*expressions.propertyTesters
)
niedziela, 11 października 2015
How to programmatically open ProblemsView in Eclipse
In order to open up a default "Problem View" view we need invoke
showView
method of on IViewPart
instance. Here you are little snippet opening view as a separate job.
Job job = new Job("Opening problems view") { @Override protected IStatus run(IProgressMonitor monitor) { IWorkbench workbench = PlatformUI.getWorkbench(); try { workbench.getWorkbenchWindows()[0].getActivePage().showView("org.eclipse.ui.views.ProblemView"); } catch (PartInitException e) { e.printStackTrace(); } return Status.OK_STATUS; } }; job.schedule(500);
czwartek, 8 października 2015
How to make active waiting in separate thread
final ScheduledExecutorService newScheduledThreadPool = Executors.newScheduledThreadPool(1); newScheduledThreadPool.scheduleAtFixedRate(new Runnable() { @Override public void run() { boolean isExecutionDone = false; try { isExecutionDone = checkIfExecutionIsDone(); } finally { if (isExecutionDone) { newScheduledThreadPool.shutdown(); } } } }, 1, 1, TimeUnit.SECONDS);
środa, 23 września 2015
Generic JSON SerDe with Jackson2
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); } }
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 ModelBuildingExceptionDefaultModelProcessor 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 ); } }
wtorek, 24 lutego 2015
Hadoop How to
How to disable "speculative execution"?
configuration.setBoolean("mapred.map.tasks.speculative.execution", false); configuration.setBoolean("mapred.reduce.tasks.speculative.execution", false);How to set notification url?
configuration.set("job.end.notification.url", request.getNotificationUrl());How to attach all required jars to the job? configuration.set("tmpjars", StringUtils.join(request.getJars(), ","));
piątek, 20 lutego 2015
Sending POST Request with command line
http://superuser.com/questions/149329/what-is-the-curl-command-line-syntax-to-do-a-post-request
AngularJs JSONP
http://www.codeproject.com/Articles/42641/JSON-to-JSONP-Bypass-Same-Origin-Policy
Chrome error:
Uncaught SyntaxError: Unexpected token :Firefox error:
SyntaxError: missing ; before statement
XMLHttpRequest cannot load http://hadoop05:12010/sqoop/version?id=1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
czwartek, 19 lutego 2015
> Ambiguous method overloading for method java.io.File#This error happend when you not set AIR_HOME and FLEX_HOME properly.. Cannot resolve which method to invoke for [null] due to overlapping prototypes between: [class java.lang.String] [class java.net.URI]
https://helpx.adobe.com/air/kb/archived-air-sdk-version.html http://labs.adobe.com/downloads/air.html
$FLEX_HOME/bin/adt -certificate -validityPeriod 25 -cn SelfSigned 1024-RSA sampleCert.pfx
.starling.samples.android.DemoWeb 0.0.1 HelloWorld demo_web.swf mobileDevice <!--[CDATA[ ]]>
/opt/adobe-air-sdk/bin/adt -package -target apk -storetype pkcs12 -keystore sampleCert.pfx DemoWeb.apk DemoWeb.xml demo_web.swf
środa, 11 lutego 2015
Dockerfile - how to run bash script without using external files
The usual way of smuggling external scripts to docker image builds is by adding them from directory where Dockerfile is located (
ADD
command). But this cause a need to maintain external resources which is not so handy, especially when scripts are rather short.
The workaround is to echo all the commands and pass them to sh
:
RUN echo -e "su -c \"echo 'N' | hdfs namenode -format\" hdfs \n\ su -c \"hdfs datanode 2>&1 > /var/log/hadoop-hdfs/hadoop-hdfs-datanode.log\" hdfs& \n\ su -c \"hdfs namenode 2>&1 > /var/log/hadoop-hdfs/hadoop-hdfs-namenode.log\" hdfs& \n\ sleep 5 \n\ /usr/lib/hadoop/libexec/init-hdfs.sh \n\ killall java \n\ " | sh
wtorek, 3 lutego 2015
GIMP - how to export image to base64
That was somewhat extremely surprising to me that GIMP does not provide Base64 exporter out of the box (but I am not the GIMP expert - maybe there is ;)). Nonetheless, as it seems to me a quite straightforward to implement such feature, I faced the challenge. After short googling and refreshing deep buried Python knowledge, it became simple, amazingly simple in fact. Here you are some details in three simple steps:
0. Open "Python Console" (don't be afraid, it does not bite you, or choke either ;)
Go to "Filters" menu -> "Python-Fu". The python console should appear.1. Take an image
img = gimp.image_list()[0] // assuming you'd got just one image opened2. Read all bytes
bytes = open(img.filename, "rb").read()3. Encode bytes with 'base64' algorithm
bytes.encode('base64')Done.
And for "one-liner" fanboys, we can compact it into one line:
open(gimp.image_list()[0].filename, "rb").read().encode('base64')
bytes.encode('base64')
puts some new-line characters, alternatively you can use the following:
import base64 base64.b64encode(open(gimp.image_list()[0].filename, "rb").read())Reference: Python Scripting Official Doc
poniedziałek, 2 lutego 2015
How to obtain Eclipse absolute installation path programmatically
The easiest way is to use
org.eclipse.core.runtime.Platform
class and its static getInstallLocation
method.
Location installLocation = Platform.getInstallLocation();A Location interface is defined in OSGi specification and basically represents an java.net.URL object. Additionally it allows creating nested locations and mechanism for locking locations. The default and the only one shipped implementation is BasicLocation, but it is internal class and just pure implementation (no other fancy features ;) To obtain path as a String user the following code:
String absolutePath = Platform.getInstallLocation().getURL().getFile();Alternatively you can read the content
InputStream is = Platform.getInstallLocation().getURL().getContent();
środa, 28 stycznia 2015
Why running docker command returns "/var/run/docker.sock: permission denied"
/var/run/docker.sock: permission denied
$ docker ps FATA[0000] Get http:///var/run/docker.sock/v1.16/containers/json: dial unix /var/run/docker.sock: permission denied. Are you trying to connect to a TLS-enabled daemon without TLS?First quick look at the
/var/run/docker.sock
file.
$ ls -l /var/run/docker.sock srw-rw---- 1 root docker 0 sty 28 11:53 /var/run/docker.sockThe solution should be now clear - you can solve the issue by adding user you are logged in to the
docker
group.
So, let's do this:
$ sudo gpasswd -a ${USER} dockerThere should be now a change in
/etc/group
file.
$ cat /etc/group | grep ^dockerNext you need start new terminal session to apply the change and check if you are in the
docker
group. Should be listed in the following command execution:
$ groupsIf still cannot see docker in the groups you're in - and you run linux with graphical interface (eg Ubuntu) you may need basically restart machine. Once done restart your docker container (if you were not needed restarting machine in previous step ;)
$ sudo service docker.io restartThat's all, now
docker ps
should be no problem to run.
niedziela, 25 stycznia 2015
How to use rsync to synchronize two folders without overriding permissions
Very popular and easy to remeber rsync command is
rsync -a source_dir target_dir
. "-a" is equivalent of "-rlptgoD"
. What does it mean?? Let's analyze it step by step.
- "-r" - reqursive
- "-l" - copy symbolic links as symbolic links
- "-p" - preserve permessions
- "-t" - preserve modification dates
- "-g" - preserve group
- "-o" - preserve owner (works only with root account)
- "-D" - preserve device files and special files
rsync -rltgoD m/bdg .
wtorek, 13 stycznia 2015
Rsync - ERROR: rsync error: protocol incompatibility (code 2) at compat.c(171) [sender=3.0.6]
$rsync -av file.zip user@host:file.zip protocol version mismatch -- is your shell clean? (see the rsync man page for an explanation) rsync error: protocol incompatibility (code 2) at compat.c(171) [sender=3.0.6]This message can be somewhat misleading at first glance, but the key to solve this issue is answering what actually means "clean shell" ;). Most probably there is some MOTD (message of the day) displayed in one of the config files (eg. .bashrc) when user starts a new session. To check if it is the case, try the following command:
ssh designer@10.1.1.162 true | wc -cIf this command returns more then 0 that means there is some output produced. Get rid of it should fix it.
środa, 7 stycznia 2015
Ubuntu - how to download Oracle JDK with single command
Downloading jdk from oracle download web page requires passing a cookie with request header.
The template:
curl -LO ${URL} -H "Cookie: oraclelicense=accept-securebackup-cookie"
Java 8
curl -LO http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-x64.tar.gz -H "Cookie: oraclelicense=accept-securebackup-cookie"
Java 7
curl -LO http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.tar.gz -H "Cookie: oraclelicense=accept-securebackup-cookie"
Java 9 - early access
curl -LO http://www.java.net/download/jdk9/archive/b44/binaries/jdk-9-ea-bin-b44-linux-x64-23_dec_2014.tar.gz -H "Cookie: oraclelicense=accept-securebackup-cookie"Alternatively you can use wget command
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u25-b17/jdk-8u25-linux-x64.tar.gz
Subskrybuj:
Posty (Atom)