Saturday, September 19, 2015

Adding new machine to rc files sync

Some time ago I wrote a post on linux productivity tools I use.
As from time to time I need to install new machine that would benefit from the synced rc files, I’ll document the steps required (as rediscovering it every time is rather a waste of time).

What I’d need

I’ll use the previously introduced:
* oh-my-zsh
* homeshick
* vim’s vundle plugin and
* tmux with tmuxinator
* powerline fonts

Please note: order is important here, otherwise some install steps might fail.

oh-my-zsh

Install via:

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

homeshick

Install via:

git clone git://github.com/andsens/homeshick.git $HOME/.homesick/repos/homeshick

Get existing dotfiles via:

cd $HOME/.homesick/repos
$HOME/.homesick/repos/homeshick/bin/homeshick clone <your git repo>

For me, as I use the private bitbucket repo, I just had to add the ssh keys generated to bitbucket first:

  1. generate ssh key via (following https://help.github.com/articles/generating-ssh-keys/)
  2. go to repo on bitbucket via web browser
  3. add generated key at: Settings -> Deployment keys

And run the

cd $HOME/.homesick/repos
$HOME/.homesick/repos/homeshick/bin/homeshick clone git@bitbucket.org:typekpb/dotfiles.git

Make sure to let homeshick symlink all the dotfiles from the repo (you might want to back up those to be overwritten). You’ll be prompted for symlinking stuff.

vim’s vundle plugin

As a prerequisite you’d need (g)vim installed (install instructions would be distro specific).

Install vundle plugin via:

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

Afterwards install all the vundle managed plugins via running in the vim:

:BundleInstall

tmuxinator

Make sure to install tmux and ruby first (probably from the distro packages available).

gem install tmuxinator

if it’s to be installed globally, use:

sudo gem install tmuxinator

powerline fonts

Following the official instructions:

cd /tmp
wget https://github.com/powerline/powerline/raw/develop/font/PowerlineSymbols.otf
wget https://github.com/powerline/powerline/raw/develop/font/10-powerline-symbols.conf
mkdir ~/.fonts
mv PowerlineSymbols.otf ~/.fonts/
fc-cache -vf ~/.fonts/
mkdir -p ~/.config/fontconfig/conf.d/
mv 10-powerline-symbols.conf ~/.config/fontconfig/conf.d/

after restart seems to work OK.

Done :)

Tuesday, January 6, 2015

Ubuntu 14.04 with HP Deskjet 930c

I’ve got old printer: HP Deskjet 930c. Following steps were necessary to use it with my Ubuntu 14.04:

  1. Printer: start + connect it via USB
  2. download HP drivers bundle called: HP Linux Imaging and Printing from: http://hplipopensource.com/hplip-web/gethplip.html
  3. install bundle via (answering couple yes/overwrite questions):
chmod +x hplip-3.14.10.run && ./hplip-3.14.10.run 

You should see your new printer afterwards.

Friday, October 24, 2014

Linux productivity tools for me

This is the stack/are the tools that keep me productive in my day to day programming experience on linux.

Well, first of all let me tell you, that this might not fit your needs , as I’m a full time java programmer so have OS choices open (still I won’t go to my java-related stuff here, to make infos general and possibly usable for non-java guys as well.).

Linux is my choice for quite some years already and this post won’t detail the reasons, rather will focus on tools/utilities that help me survive in this world.

Distro

Well, let’s start from the ground. I don’t have a clear winner here. In fact I run currently 3 different ones (didn’t count my router and phone here):

In fact the info present in this post won’t detail too much on the 3.rd one, as it’s a server that just runs. The only thing I need there is a ssh access and that’s pretty much it, so this post would be rather short for that one :)

The reasons for Fedora, and Ubuntu in my case are:

  • stability (well, let’s say things don’t crash that often for me),
  • packages for most of the SW I need available in repositories and
  • the software packages are not at some archaic versions.

Window manager

Well, the nice thing is that most common window managers are available across all the popular distros. My choice here is Xfce.

Well, I don’t hate others, this just fits my needs best:

  • no need for fancy effects for me as
  • speed is rather my preference.
  • still I need something that I would not fight with every day.

Project I’m keeping my eye on is: LXQt. Still waiting for a more stabilized release (0.8 was released recently, which says to be ready for production desktops, but I’d plan to give it a try with the next release as well as when I have some time to set it up).

Shell

I have 2 candidates here:

  • bash and
  • zsh.

bash I use for scripting. It’s been my choice for quite some time already and I don’t see a need for change any time soon. As I’m quite used to it and the most people/projects I share the scripts with are OK with that/have used it already.

zsh as my default shell. This is still the world I consider new to me (see my recent post on that).

Shell env sync

As I have multiple machines I’m working on, there are 2 essential projects in the area for me:

oh-my-zsh

Provides for my zsh:

  • nicely/systematically structured plugin approach,
  • autocompletition and
  • all sorts of aliases.

To document my use case a bit here, these are the plugins I have present in my .zshrc:

plugins=(git mvn glassfish yum colored-man vagrant z common-aliases gradle homeshick vim-interaction powerline tmuxinator tmux)

Please note: Some are not available officially, and in the time of writing are just present as pull request from me to the project. Namely:

Well, might sound like a self promotion, but feel free to check and provide feedback on these if you find them useful.

Homeshick

Lets me synchronize all my custom zsh plugins as well as .bashrc files over git repository.

The only requirements are:

  • git and bash on all the clients
  • and the git repo accessible from all my clients.

In my case, there are things I don’t want to expose to public, but have no problem to have it hosted in some private git repo. So bitbucket is my choice, as I have there private git repo for free for the purpose.

Shell sessions bootstrapping

There are 2 important projects for me here:

Tmux and tmuxinator enable me to have just one yaml formatted file for bootstrapping my terminals.

I preffer it to having multiple tabs open in some GUI terminal, as it:

  • bootstraps all my shells daily in a same/reproducible way,
  • provides me with the nice way on organizing these and
  • navigation between these works with keyboard only => switching between different tasks becomes after some time of usage just a routine.

So no more searching in countless cards/windows for particular task.

Shell productivity

I don’t want to list all the linux utils I use, as I guess I’d make list too long and too boring (even for me to write). So let’s just name some, that I consider worth it:

  • ack - powerful grep replacement (I might document in the separate blog post),
  • notify-send and
  • all sorts of aliases and zsh/bash functions, that would be too many to list here, moreover might be too specific and useless for others.

Notify-send

I blogged about notify-send already.

I use it for all the app-server (in my case Glassfish) lifecycle management operations (start/stop/restart domain) as well as deployment stuff.

As these:

  • take quite some time to finish and
  • might end up with errors,

I let it myself updated with notification having:

  • exit code
  • chunk of the last couple lines from the log file.

This is great, as I can work in parallel and it gets my attention, once the job is done.

Desktop app launcher

Without having an option for fast startup of my favourite programs I’d waste my time searching the icons or menus.

As Xfce doesn’t provide me with the powerful one, I use: Synapse.

File manager

Well, there are times when I play with files in the command line, but sometimes it just fits better to use some UI for the purpose.

My choice is Krusader. Well, the most stuff I need is available, namely:

  • file/folder manipulation,
  • file folder comparison and
  • file/folder contents search.

The only thing that bothers me is the fact that development is rather stalled in the project.

Still, viable alternative might be: Double commander, which seem to be even cross-platform and can use the total commander plugins (which used to be my choice on windows for the purpose).

Editor

I tried to live with Gedit and for simple note-taking it might be a good choice, however as I like to play with ruby these days, I tried to find something that would help more in the area.

(G)Vim

After searching I came to conclusion, that (G)Vim is quite popular in the Linux world.

Well, it’s worth to mention vim joke here, which expresses the feelings of many on this editor: Infinite Vim monkey theorem (see Infinite monkey theorem for explanation).

Still, I’ve seen:

  • many people favouring it,
  • it’s the first editor I remember to have available once logging in to my school linux account (OK no real argument, just sentiment),
  • it seemed to provide countless plugins for all sorts of stuff and
  • it’s incredibly powerful, as far as I’ve seen and learning it might pay back.

So I decided cca 2 years back to uninstall the editors I’ve been used to and force myself to use (G)Vim.

Great source of information was for me: vimcasts, which helped me a lot in the area.

Well, I plan to document my .vimrc setup in a separate post, as it could make this one way too long.

Files sync tool

Unison is my choice her. For more info on my use case, see this blog post.

Conclusion

Hope you find some inspiration here. And would be glad to hear from you guys about any I missed, but you could not live without.

Still, I can’t believe anyone read this far. As I guess I would not force myself to :).

Friday, July 11, 2014

Kindle for offline html docs reading

Summer is here, while laying on the beach, you can use the time to learn new programming language or get some overview on the framework of your interest. Possibly the things you had no time left for over the year.

I bought myself Kindle, my beach holiday is just a day away, so it’s time to fill the reader with content.

Goal

Get an online html docs to Kindle for offline reading.

Required software

  • wget - download program
  • calibre - ebook reader/converter/…

Process

  1. find the docs you’re interested in (I’ll refer to <http://your-manual.com> as the url of the docs of my interest)
  2. download it (I used wget to do so, inspired by stackoverflow answer, please note this is expecting all docs no one domain only):

    wget --recursive --timestamping -l inf --no-remove-listing --page-requisites <http://your-manual.com>
  3. start calibre
  4. drag&drop the downloaded index (main) page to calibre
  5. convert to mobi format (via right click on the book and choosing Convert Books -> Convert individually afterwards editing metadata and choosing mobi as the Output format)
  6. connect your kindle (via usb)
  7. send ebook to device - via right clicking the ebook and choosing: Send to device -> Send to main memory
  8. done!

The valuable part

Well, the challenging part is for me always to actually digest the docs. So go ahead and read it (if it’s worth it). Self-discipline, I need to work on that, I guess.

Wednesday, June 25, 2014

Migrating from bash to zsh

These are my steps in migration from bash to zsh. I’m documenting these to keep the future reference for me (and possibly other readers as well).

Motivation?

Check out the Slideshare presentation: Why Zsh is Cooler than Your Shell

Current shell

to find out the current shell:

ps -p $$

it’s useful during migration to make sure the new shell is really in use.

Migration

Migration itself included (on my Fedora) reconfiguring:

oh-my-zsh

There exists users’ maintained collection of zsh customizations, that I found useful. Called: oh-my-zsh. (Please note the amazing Github’s - Star count. Once seeing that I didn’t doubt I’ll give it a try.)

For installation I just went for:

curl -L http://install.ohmyz.sh | sh

oh-my-zsh with powerline

I’m used to powerline everywhere ((g)vim/konsole/tmux/bash) already, so let’s keep it working in zsh as well.

I created file: ~/.oh-my-zsh/custom/powerline.zsh with contents:

. ~/.local/lib/python2.7/site-packages/powerline/bindings/zsh/powerline.zsh

Please note: You need to go for the actual location of powerline installation on your system.

and in the file: ~/.zshrc I had to comment out line:

# ZSH_THEME="robbyrussell"

otherwise oh-my-zsh theme seems to conflict with powerline one.

oh-my-zsh plugins

The real benefit of oh-my-zsh commes with plugins, so I went for those I find useful. Via changing the file: ~/.zshrc having:

plugins=(git mvn glassfish yum colored-man vagrant z common-aliases gradle)

oh-my-zsh custom stuff

As my ~/.bashrc held already quite some customizations, I migrated those to:

~/.oh-my-zsh/custom/*.zsh

Even this part was nice, as I could tidy up things a bit and omit unused stuff. Moreover I decided to create multiple *.zsh files (as these are auto-loaded) to achieve modularity.

Done

Honestly in the beginning, I had no clue how much I would enjoy my new shell.

Friday, June 13, 2014

Xfce: How to disable toolbar text in KDE apps

Recently I’ve experienced quite a funny situation. I use Krusader for file browsing that calls Kompare for file comparisons. However I was not able to copy changes from left to right (or vice versa) in the compared files, as I could not see all the toolbar buttons (these were too big). I didn’t even notice for quite some time, that there are others, not displayed on my screen.

But who needs text description in toolbars? Well, I don’t!

I remembered global setting from the Gnome world that it should be possible, so searched from the KDE equivalent.

Found it (in my Fedora + Xfce) in:

Xfce menu button -> Options (hope this one is right, as I have it as Einstellungen) -> KDE SystemOptions (for me KDE SystemEinstellungen) -> Style (Stil) -> Fine Tuning tab -> Toolbars section
where I just chose No Text in the both: Main toolbar text as well as in the Secondary toolbar text.

That did the job for me.

Apache Ant tasks for JMX access

I wanted to invoke JMX operations from the Ant tasks. However finding usable ant tasks library as well as the usage was rather tricky. So let me share my experience to make things easier for others.

Ant tasks for JMX operations

I decided to follow Tomcat documentation and used ant tasks distributed with tomcat.

Just for the record the usage is not restricted to Tomcat deployed JMX mBeans. For me it worked for java process accessible via JConsole via Remote connection.

Retrieving the library

  1. As I wanted to get the latest version I used maven central repository “search by classname” feature and searched for: org.apache.catalina.ant.jmx.JMXAccessorTask (see the query)
  2. afterwards I went for the tomcat 8 jar file (called tomcat-catalina-ant-8.0.8.jar)
  3. and just copyied the latest available to my $ANT_HOME/lib dir.

Usage

I didn’t have a chance (or motivation?) to check all the tasks available, the full list of tasks available can be seen in the zipped file: org/apache/catalina/ant/jmx/antlib.xml, following were present for me:

<typedef
    name="open"
    classname="org.apache.catalina.ant.jmx.JMXAccessorTask" />
<typedef
    name="set"
    classname="org.apache.catalina.ant.jmx.JMXAccessorSetTask" />
<typedef
    name="get"
    classname="org.apache.catalina.ant.jmx.JMXAccessorGetTask" />
<typedef
    name="invoke"
    classname="org.apache.catalina.ant.jmx.JMXAccessorInvokeTask" />
<typedef
    name="query"
    classname="org.apache.catalina.ant.jmx.JMXAccessorQueryTask" />
<typedef
    name="create"
    classname="org.apache.catalina.ant.jmx.JMXAccessorCreateTask" />
<typedef
    name="unregister"
    classname="org.apache.catalina.ant.jmx.JMXAccessorUnregisterTask" />
<typedef
    name="equals"
    classname="org.apache.catalina.ant.jmx.JMXAccessorEqualsCondition" />
<typedef
    name="condition"
    classname="org.apache.catalina.ant.jmx.JMXAccessorCondition" />

out of these, I gave following a try:

org.apache.catalina.ant.jmx.JMXAccessorTask
org.apache.catalina.ant.jmx.JMXAccessorInvokeTask
org.apache.catalina.ant.jmx.JMXAccessorQueryTask

For the demonstration purposes I’m using Glassfish 4.0.

Example: Listing JMX MBeans

Let’s assume we want to retrieve the MBean by name (namely: java.lang:type=Memory). Please note username and password were not required for access (otherwise they should be specified via respective properties).

Noteworthy here is the resultproperty, which could hold array from which we could get a name. So having in ant build script:

<typedef 
    name="jmxQuery"
    classname="org.apache.catalina.ant.jmx.JMXAccessorQueryTask" />

<jmxQuery
    host="localhost"
    port="8686"
    echo="true"
    name="java.lang:type=Memory"
    resultproperty="memory" />

<echo>Retrieved MBeans count: ${memory.Length}</echo>
<echo>The 1.st one has name: ${memory.0.Name}</echo>

results for me in following output:

 [jmxQuery] memory.Length=1
 [jmxQuery] memory.0.Name=java.lang:type=Memory
     [echo] Retrieved MBeans count: 1
     [echo] The 1.st one has name: java.lang:type=Memory

Example: Invoking operation via JMX

Here is a 2 step approach required:

  1. connect to remote server via JMX and afterwards
  2. invoke the operation on the particular MBean.

For demonstration purposes, let’s assume we want to call garbage collection (via invoking operation: gc() on MBean named: java.lang:type=Memory)

Sample ant build file chunk does the job (please note ref property value that has to be the same across these 2 tasks):

<typedef 
    name="jmxOpen"
    classname="org.apache.catalina.ant.jmx.JMXAccessorTask" />

<typedef 
    name="jmxInvoke"
    classname="org.apache.catalina.ant.jmx.JMXAccessorInvokeTask" />

<jmxOpen
    host="localhost"
    port="8686"
    ref="glassfish"
    failOnError="true" />

<jmxInvoke
    name="java.lang:type=Memory"
    operation="gc"
    echo="true"
    delimiter=" "
    failOnError="true"
    ref="glassfish" />

Further information

For more details, I recommend reading the official Tomcat documentation as well as Javadocs.