Implementing autocomplete for English in C++

When it comes to implementing autocompletion in C++ in some type of input field, the question is which algorithm to choose and where to get the source for completion. In this post I’ll try to answer both questions.

As for the algorithm, SO gives us hints about tries, segment trees and others. You can find good article about them. Author has implemented some of them in a repository called FACE (fastest auto-complete in the east). You can easily find it on GitHub. This solution is used for the autocompletion in search engine Duck-Duck-Go which should tell you how good it is. Unfortunately their solution requires dependencies on libuv and joyent http-parser, which is not good in case you need just to integrate autocompletion functionality into your C++ application, but not build auto-complete server and send queries to it. Another drawback – libuv and cpp-libface itself fails to compile in Windows which is bad in case you’re building cross-platform solution.

You can find out how to built FACE into your cross-platform C++ application below.

(more…)

How to keyword and upload photos/illustrations to microstocks

If you’re a photographer new to microstock photography, I highly reccomend you to embark this wonderful way of passive earning using your artworks. But I will suppose that you know what is this about and how basically use it. I would even suppose you’ve passed an exam on some stock agency and uploaded your first artworks. But did you know there’re plenty of stocks? And did you know it’s better to work with all major players of this industry? Shutterstock, iStock, Fotolia, Depositphotos to name just a few. And there is a lot more.

Keywording and uploading your photos to stocks can be fairly considered as the most boring part of this business. It’s quite a long way to upload your files to 10 different websites, keyword them and submit. For such a purpose I’m working on a keywording and uploading tool, called Xpiks. It’s main objective is to help you to dramatically reduce time you spend on keywording and uploading and enable you to upload to more stocks simultaneously. For that reason I added features like parallel editing of several files, keywords suggestion, spell checking, automatic FTP uploading, stock requirements checking and others.

You can see screenshots or read more on how to use it on the official website.

This program is open source and free and available through all major platforms: OS X, Windows and Linux. There’s a support section and you’re welcome to file your bug or post a question there.

Don’t waste more time than needed, download Xpiks and enjoy!

Building Hedgewars under OS X Yosemite

Ok, you considered to build Hedgewars by yourself. To be clear, I’m going to build 0.9.21 on 10.10 Yosemite on MacBook Pro with Retina. First of all, read official manual. After source code pull from Mercurial failed via hg command I considered downloading source on the Downloads page.

As original HowTo says, you should build Ogg and Vorbis, but while Ogg build succeeded, Vorbis said it can’t resolve u_int16_t type and after some googling I’ve found it was a known issue and you should replace #include <inttypes.h> with #include <sys/types.h> under #elfif (defined(__APPLE__) && defined(__MACH__)) in file ogg/os_types.h. Then everything goes more or less ok until you’re trying to generate makefile with Cmake. I had to turn off video recording feature, screenshots in PNG (BMPs instead) and no local server. Finally, I came up with

cmake . -DQT_QMAKE_EXECUTABLE=/usr/bin/qmake -DNOPNG=1 -DNOVIDEOREC=1 -DNOSERVER=1 -DCMAKE_BUILD_TYPE=Release

After successful build you still can’t play, because hwengine fails to launch. It looks for libfreetype.6.dylib in /usr/X11, but you might even don’t have X11 installed. If yes, proceed to Quartz/X11, download and install it. Don’t forget after all make symlink to original X11 directory using sudo ln -s /opt/X11 /usr/X11.

And still, after everything is done, Hedgewars fail to run in fullscreen mode so you might consider running it via VirtualBox and some Linux distro instead.

By the way, you can download my build of Hedgewars 0.9.21 for OS X Yosemite 10.10 here.

How to process Nikon D5300 NEF and other unsupported RAW formats in Darktable

My favorite tool, Darktable, does not support new Nikon D5300 NEF format and, obviously, a lot of other RAW formats due to proprietary software for them. But there is a solution. There is a free tool from Adobe for Windows and Mac: DNG converter, which is free and converts a lot (almost all, I guess) of proprietary RAW formats to DNG (Digital NeGative – open lossless raw format. Complete list of supported RAW formats for DNG Converter.

snapshot2

For now DNG Converter is fairly simple so it runs flawlessly under Wine and you’re able to export all your NEF (or other) photos first to DNG and then to process them in your favorite RAW editor. That’s it!

(in my case then I switched Alt-Tab from working DNG converter, it crashed under Wine, but when window is active all the time, it works ok)

Also, if you set file format to 12-bit NEF in your camera, it would have green colors if you open them in any RAW editor (Darktable, RAWTherapee, Lighthouse, etc). But if you chose 14-bit RAW, it looks ok despite the fact it would be more sharp in native Nikon Windows- and Mac-only software.

If you have any questions, feel free to ask them in commets!

UPD: Darktable 1.6 supports D5300 NEF files if processed without OpenCL

TeamCity 8 on CentOS 6.4 from scratch

In this post I’ll describe whole TeamCity installation process on a fresh CentOS (on the moment I’m writing it’s 6.4) for your private project or startup.
First, proceed to the CentOS downloads page and download CentOS distro through .iso, .torrent or whatever-you-like and start the installation process. If you’re familiar with any  linux distro installation, it won’t take you much time to complete the installation. I’m using the minimal configuration without any Desktop Environment and with minimum core- and other system utils. Nonetheless, consider installing iptables, elinks and java (openjdk).
After the installation is over, login, add a user for yourself with adduser and let’s start with TeamCity (maybe you’ll also consider adding yourself to the sudoers file).
First, create /opt/jetbrains/ directory and download latest TeamCity using wget.
# mkdir /opt/jetbrains
# cd /opt/jetbrains
# wget http://download.jetbrains.com/teamcity/TeamCity-8.0.5.tar.gz
# tar -xpzf TeamCity-8.0.5.tar.gz

Now lets create a system user (e.g. no home directory) for TeamCity to resolve security issues correctly:

# adduser -r teamcity
# passwd teamcity
# chown -R teamcity:teamcity TeamCity
We’ll use PostgreSQL for the internal database for TeamCity. So let’s install postgresql packages (8.4 for CentOS 6.4). For details of the PostgreSQL installation please refer to official webpage.
# yum install postgresql
# service postgresql initdb
# chkconfig postgresql on
Also edit the /var/lib/pgsql/data/pg_hba.conf file to allow authorization from localhost. Go to the end and replace ident to trust for localhost in the configuration for hosts. Now lets create another user for the future TeamCity database and create a database for that user.
# sudo -u postgres psql postgres
password postgres
# sudo -u postgres createuser -D -A -P teamcity_user
# sudo -u postgres createdb -O teamcity_user teamcity_db
(D = Cannot create databases, A = Cannot add users, P = Force password prompt)

MediaWiki installation on a linux guest in the VirtualBox: how-to, tips & tricks

I’ve spend half of a day trying to get MediaWiki working on a VirtualBox for the internal project in the internal network. Looks like it’s done now and I want to share tips to help someone to spend less time in the future.

I’ve been installing and configuring MediaWiki 1.21 on the OpenSUSE 12.3, but all tips are valuable for any linux distro.

(more…)

Solving mouse delays and lags in linux

I’ve been experiencing strange mouse delays and lags some time ago and now I’ve become tired of it. I’m using OpenSUSE with 3.7.10 kernel and first thing I tried was upgrading the kernel (to 3.12) which was quite useless. Googling related to my distro also wasn’t helpful.

The trick was in laptop-mode-tools which I’ve installed earlier to make my laptop battery life longer. There is an usb autosuspend options which just suspended my usb wireless mouse. So setting

AUTOSUSPEND_USBTYPE_BLACKLIST="usbhid"

in the

/etc/laptop-mode/conf.d/usb-autosuspend.conf

and running

/etc/init.d/laptop-mode restart

was enough.

Problems when ejecting WD My Passport in Linux (OpenSUSE)

Struggled to safely eject my 1TB  Western Digital My Passport external hard drive in OpenSUSE. Googling regarding Western Digital was inefficient, because lots of people have been just saying not-such-a-good-things about WD products and nothing valuable regarding ejecting it.

Usual eject command had no success: hard drive continued to spin. I’ve even upgraded firmware to 1.49 on my Windows 7 machine at work. No succcess.

After some time googling I’ve found next working solution:

  • install udisks utility
  • run sudo udisks --unmount /mount/point from terminal
  • run sudo udisks --detach /your/device from terminal
  • profit

So, enjoy!