Thursday, May 14, 2015

Convert images to pdf and back

Today I found out a simple and flexible tool which converts images to pdf and vice versa - convert. It was already built in my Fedora 21.

Example:

Let's say I have 1.jpg, 2.jpg, 3.jpg files. To convert them into a single result.pdf run the following command:

$ convert 1.jpg 2.jpg 3.jpg result.pdf

or

$ convert {1..3}.jpg result.pdf

Now I want to get my images back from the result.pdf:

$ convert -density 300 result.pdf image.jpg

where "-density 300" is a precision in points per inch. Each pdf page will be converted into a separate image.

convert supports a lot of different flags and options. To learn more about it:

$ man convert

or

Wednesday, April 1, 2015

log4j2: line separator in header's parameter of PatternLayout

Log4j2 provides a new parameter for PatternLayout:

Parameter name: header
Type: String
Description: the optional header string to include at the top of each log file

With the following log4j2.xml configuration:

1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="20">
    <Appenders>
        <RollingRandomAccessFile name="file" fileName="logs/app.log" filePattern="logs/app-%d_%i.log.gz">
            <PatternLayout>
                <header>
Version: ${env:APP_RELEASE_VERSION}
                </header>
                <pattern>%message%n</pattern>
            </PatternLayout>
            <Policies>
                <OnStartupTriggeringPolicy/>
            </Policies>
        </RollingRandomAccessFile>
    </Appenders>
    <Loggers>
        <Root level="debug">
            <AppenderRef ref="file"/>
        </Root>
    </Loggers>
</Configuration>

Git: undo the last rebase

$ git reflog

f0d821f HEAD@{0}: commit_a
2ea24f8 HEAD@{1}: commit_b
0c3cd49 HEAD@{2}: commit_c
de5b02a HEAD@{3}: commit_d

Suppose that "commit_c" was the head commit of the branch just before the rebase. Let's reset the current branch to this commit:

$ git reset --hard HEAD@{2}

Playing with vim configuration for C++

What I got as a result:


The main features:
  • embedded file system explorer
  • syntax highlighting
  • hotkeys for compiling/running C++ code

Wednesday, February 11, 2015

Netty server is incompatible with ObjectOutputStream on the client side

Recently I faced with the following problem while playing with Netty:

1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
io.netty.handler.codec.TooLongFrameException: Adjusted frame length exceeds 1048576: 2901213193 - discarded
at io.netty.handler.codec.LengthFieldBasedFrameDecoder.fail(LengthFieldBasedFrameDecoder.java:493)
at io.netty.handler.codec.LengthFieldBasedFrameDecoder.failIfNecessary(LengthFieldBasedFrameDecoder.java:469)
at io.netty.handler.codec.LengthFieldBasedFrameDecoder.decode(LengthFieldBasedFrameDecoder.java:404)
at io.netty.handler.codec.serialization.ObjectDecoder.decode(ObjectDecoder.java:68)
at io.netty.handler.codec.LengthFieldBasedFrameDecoder.decode(LengthFieldBasedFrameDecoder.java:351)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:231)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:131)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:372)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:780)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:99)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:497)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:465)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:359)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Thread.java:745)

How to insert code blocks in Blogger posts

I didn’t find any setting which would allow me to insert code blocks in Blogger posts but I managed to overcome this problem.

Here’re two simple and handy online converters of code to html:

markup
pros: language auto-detection, small html in the output
cons: no line numbers support, no horizontal scrolling
styles I liked: Slush & Poppies, iPlastic

hilite.me
pros: line numbers support, horizontal scrolling in case of long lines
cons: big html in the output
styles I liked: friendly, default, colorful
CSS I used: border:none;

Let’s say we have the following piece of code which is desirable to insert as a code block:

public class RowSocketClient {

    public static void main(String[] args) throws Exception {
        String host = "localhost";
        int port = 4446;

        try (Socket socket = new Socket(host, port);
                ObjectOutputStream out
                    = new ObjectOutputStream(socket.getOutputStream())) {
            out.writeObject("ping");
        }
    }
}

Tuesday, February 3, 2015

Useful installations for Fedora to keep in mind

Creating a bootable USB

$ sudo dd if=/path/to/Fedora-Live-xxx.iso of=/dev/sdc

where sdc can be found by inserting the usb drive and executing:

$ dmesg | tail

yum plugin which helps to choose the fastest mirrors

$ sudo yum install yum-plugin-fastestmirror

RPM fusion reposetories

# su -c 'yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm'

Codecs

$ sudo yum install gstreamer1-libav gstreamer1-plugins-bad-free-extras gstreamer1-plugins-bad-freeworld gstreamer1-plugins-good-extras gstreamer1-plugins-ugly gstreamer-ffmpeg xine-lib-extras xine-lib-extras-freeworld k3b-extras-freeworld gstreamer-plugins-bad gstreamer-plugins-bad-free-extras gstreamer-plugins-bad-nonfree gstreamer-plugins-ugly gstreamer-ffmpeg

E-book management tool

$ sudo yum install calibre

UI package manager

$ sudo yum install yumex

Nvidia Optimus (Bumblebee installation)

Visit: http://fedoraproject.org/wiki/Bumblebee

Move applications in tray to the top bar

Install TopIcons Gnome Extension

Friday, January 23, 2015

Hash mark in git commit message

 From the git commit message:

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.


So, if you want to use a hash mark '#' in the commit message (E.g.: "#77 - fixed by changing user's permissions") use the following form of commit:

git commit --cleanup=whitespace

NOTE: don't forget to remove other unnecessary lines which start with '#' otherwise they will be added to the commit message as well

Wednesday, December 10, 2014

My donation for Eclipse


My donation is 35$. Thanks for a great IDE!

You can also become a friend: https://www.eclipse.org/donate/

New Fedora 21 release


Release Notes: http://docs.fedoraproject.org/en-US/Fedora/21/html/Release_Notes/

Download: https://getfedora.org/en/workstation/download/

Some changes/improvements I found interesting:

GNOME 3.14
Update GNOME to the latest upstream release, 3.14

GCC49
Switch GCC in Fedora 21 to 4.9.x, rebuild all packages with it.

Headless Java
Server installations of Fedora should usually not pull in packages related to X system or sound subsystem. For this reason part of OpenJDK package has been split into headless subpackage which has smaller dependency chain. Fedora packages should be migrated to require java-headless instead of full java package when appropriate

Java 8
Make Java 8 (provided by OpenJDK 8 which is java-1.8.0-openjdk) the default Java runtime. The current default Java runtime (Java 7, provided by OpenJDK 7, java-1.7.0-openjdk) will be obsoleted and removed.