## Best WAMP for Web Development (2013 Edition)

I just wanted to put out there one guy’s opinion on the best WAMP package in 2013. I’ve had the chance to use all of the following, and here’s my rating from best (1) to worst (5). I should say first thought that all of them are very good and relatively easy to set up:

1. EasyPHP
2. WampServer
3. Zend Server
4. Uniform Server (aka UniServer)
5. XAMPP

People on StackOverflow recommended UniServer and Zend Server, but I found UniServer difficult to use and configure and Zend Server too bulky what old-school framework-free PHP development. When I want to set up a web server, I’ll usually configure everything myself as opposed to using one of these WAMPs. But for simple development it’s nice to have something that takes under a minute to install and set up.

EasyPHP was the last thing I tried, because the name was frankly confusing (at the time, though it makes perfect sense now), but it turned out to be the easiest and most intuitive WAMP I’ve ever used. Basically, the reason I love it is super lighweight and auto-restarts every time you change the config file (httpd.conf, php.ini, etc).

This is just one guy’s opinion, but I wanted to put it out there in case it might help a fellow web developer.

Posted in Programming, Tools, Web Development | | Leave a comment

## Convert String to Qt Keycode in C++

I came across the need to convert a string representing a key on the keyboard to a keycode enum like Qt::Key (or anything else). Example conversions would be:

"Ctrl" to Qt::Key_Control
"Up" to Qt::Key_Up
"a" to Qt::Key_A
"5" to Qt::Key_5

As you see the above includes not just alpha-numeric keys but modifiers and special keys. Qt has this parsing functionality in QKeySequence’s fromString static function:

QKeySequence fromString(const QString & str, SequenceFormat format);

You might as why I need this conversion. Well, I have a data file generated by GhostMouse. It’s a log of what I type via the keyboard. Here’s an example of me typing ” It “:

{SPACE down}
{Delay 0.08}
{SPACE up}
{Delay 2.25}
{SHIFT down}
{Delay 0.11}
{i down}
{Delay 0.02}
{SHIFT up}
{Delay 0.03}
{i up}
{Delay 0.05}
{t down}
{Delay 0.08}
{t up}
{Delay 0.05}
{SPACE down}
{Delay 0.12}
{SPACE up}

Unfortunately, QKeySequence does not acknowledge a “Ctrl” key by itself as a key. So, I add a non-modifier key to the sequence and then subtract it from the code in that case. Here’s the complete function that should get the job done:

uint toKey(QString const & str) {
QKeySequence seq(str);
uint keyCode;

// We should only working with a single key here
if(seq.count() == 1)
keyCode = seq[0];
else {
// Should be here only if a modifier key (e.g. Ctrl, Alt) is pressed.
assert(seq.count() == 0);

// Add a non-modifier key "A" to the picture because QKeySequence
// seems to need that to acknowledge the modifier. We know that A has
// a keyCode of 65 (or 0x41 in hex)
seq = QKeySequence(str + "+A");
assert(seq.count() == 1);
assert(seq[0] > 65);
keyCode = seq[0] - 65;
}

return keyCode;
}
Posted in Programming | Tagged , , , | Leave a comment

## The Future of Qt

There must be a million articles written with the title “The Future of Qt”. Qt (pronounced “cute” by everyone except me) is a cross-platform framework for developing applications with a strong graphical component (or not).

Qt uses C++ but extends it in a few powerful ways that blew my mind when I first begun to internalize them. A lot of programming languages have magical powers. The question is how easy and natural it is to access those powers. To this day, I struggle any time I have to use the Boost Graph Library without first drinking a couple of cups of coffee.

Anyway, Qt has been kicked around a bit, starting out at Trolltech, then purchased by Nokia, and now sold by Nokia to Digia. This reminds me of watching Brett Favre or Michael Jordan switch teams at the end of their careers. You don’t care where they go, you just hope they keep playing.

I’m a big supporter of Qt. I believe it’s the best choice for most small teams of C++ developers on both Linux and Windows.

## Some Tips on How to Use Google Search

Here are some tips that I often use in searching for information on Google, and after talking to my dad a month or so ago, I realized that these are not obvious things, but they do make my life a bit easier.

## Search by Year

This is probably the biggest one for me, because for a lot of the information I search for, the date of the content is proportional to its value to me. It’s an undeniable fact that not only the content, but the presentation of the content online gets noticeably better year to year. So, put a year or a range of years into your query like this:

2010..2012

## Exact Phrase

Use quotes! If you use quotes around a phrase, Google will put more emphasis on the exact phrase and not just on the individual keywords that make up the phrase. So, again, use quotes:

"African swallow"

## File Type

Sometimes I’m looking for pdf’s or mp3′s or some abscure file format, and that where the “filetype” label works its magic:

filetype:pdf

## Other Powerful Stuff I Never Use

There are a few query operators that I always loved the idea of, but never find myself actually using. Here are some examples off the top of my head…

Search for terms in the title tag of the page. Basically, this is for when you know that a page you really want might have this term or phrase in its title:

intitle:"African swallow"

You can exclude terms from a search via the – operator, but somehow I always end up doing manual pruning of results vs explicit exclusion in the query:

"African swallow" -"Monty Python"

## Be Yourself

All that said, I think that Google has been very effective at guessing at the intention of the regular user. So while you should try to help Google out, also don’t try to be clever. Try to think like an average somewhat-tech-inclined Joe Blow would because that is who Google is optimizing its search engine for.

Posted in Tools, Web Development | Tagged , , , | Leave a comment

## Include Full BibTeX Entry Inside Text

This isn’t rocket science, but you can insert BibTeX entries as you go, instead of (dumping all the references at the end in a “References” section. It’s useful when writing many chaotic pages of notes as you crawl through dozens of publications on a particular topic you’re researching, or when making a slide presentation in Beamer.

\usepackage{bibentry}

\begin{document}

% don't show the full list of references
\nobibliography*

% include the bibtex file
\bibliography{database}

% reference individual bibtex entry 'bla'
\bibentry{bla}

% define the style of the bibentry citation
\bibliographystyle{style}

\end{document}

Another way is to use the biblatex package. Note, that at least in Ubuntu, you need to biblatex doesn’t come even with the full install of texlive-all and needs to be added seperately in the repository as a package of the same name.

% 'style' can be defined as options to this command
\usepackage{biblatex}

% \jobname is the name of this file

\begin{document}

% full bibliography section if you like
\printbibliography

% 'bla' is the bibtex entry label
\fullcite{bla}

\end{document}
Posted in Programming | Tagged , | Leave a comment

## Backward Compatibility in C++ Libraries

Backward compatibility is an important design goal of a software system that says that a new version of the software should play nice with the old version. As an example, Microsoft Windows has done a remarkably good job (in my opinion) of achieving backward compatibility over the years, while seemingly not planning ahead to any reasonable degree. Yes, that’s a compliment disguised as a criticism, or visa versa.

It seems that developing standards for a technology help make backward compatibility much easier to achieve in the future. This is probably due to the fact that getting a bunch of intelligent egos to agree on a standard requires a lot of discussion of the future, in the process helping clear out the cloud of uncertainty that is the cutting edge of tomorrow.

That’s why it’s always surprising to me when a well-established C++ library officially breaks backward compatibility as in this latest example from Boost. It’s certainly easier to fix a design flaw by starting over. Whether this is the right approach for the long term success of a project is another question. In this case, I just smile, nod, and go back to update the old code to the new API.

## WampServer vs XAMPP

This is not an Earth shattering post. Moreover, it’s not an objective one, that is, it is based on my experience and my experience only.

WAMP is a bundle of Apache, MySql, and PHP (though often also Perl and/or Python) for Windows. These are the things you need to run a dynamic website (in my case, for development and testing) on your computer in Windows. The idea is that a WAMP bundle makes the process of downloading, installing, and configuring the individual components easy and quick.

The two most popular WAMP tools are XAMPP and WampServer. I used XAMPP for a couple years, but it started disconnecting me from the internet recently for some unknown reason (that is probably my fault). I tried to fix it, and couldn’t especially given the conditions under which the problem arose were hard to pin down precisely.

So I installed WampServer instead last week, and I have to say that the basic task of turning everything on and off, tweaking configuring, enabling modules, changing versions of individual components, etc is a lot easier in WampServer. By “easier” I mean it’s more intuitive. The little menu that pops up from WampServer icon in the taskbar has all the options you need and none you don’t.

There may be people out there that have had a different experience, but I know I myself was wondering whether grass is greener on the other side, and in this case it was!

Posted in Tools, Web Development, Windows | Tagged , , , , , , , , | 8 Comments

## Sorting a Sorted List in C++

It came to my attention that I didn’t know how well STL sorting algorithms performed on a vector of values that are already sorted. One would hope it would be close to $latex O(n)$. This page does a comparison of various algorithms on vectors that are sorted to varying degrees. However, I’m interested in the case when the vector is fully sorted. A simple $latex O(n)$ would remove the need to run the sorting algorithm on a list that’s already sorted. It makes perfect sense that the STL implementation of std::sort does not perform this check. I confirmed this fact by running the following simple test:

for(int s=0; s<=10; s++) {
const int n = 1000 * 1000 * 10 * s;
vector<int> v(n);
iota(v.begin(), v.end(), 0);
std::sort(v.begin(), v.end());
std::is_sorted(v.begin(), v.end());
}

The results with no optimization turned on:

The results with -O2 optimization:

Conclusion: if you expect that the list might be sorted more often than not, run std::is_sorted on it first.

Posted in Programming | Tagged , , , , | Leave a comment

## Auto Save Files in Emacs

I’m resolving to make more frequent and regular posts on this “research” blog that’s so far has been just a place where I write down some basic tips and tricks that have to do with tools I use in programming (which is just one part of my research life). I’m not sure it’s ever going to be more than that. I take an enormous amounts of notes offline, but never quite make the effort to convert those notes into a form that I’m comfortable making public.

Anyway, to the topic of the post… auto-save functionality in Emacs. By default, Emacs auto-saves a buffer with changes in it to the same directory as the file opened in the buffer, but adds a character such as # or ~ to the beginning or end.

This auto-savin’ can be turned off with:

(setq make-backup-files nil)

But today I turned it back on, and decided, since I use SVN anyway for versioning, that I will auto-save into the same file. This is achieved with the following:

(setq auto-save-visited-file-name t)

Also, I turned up the rate at which Emacs auto-saves the files.

(setq auto-save-interval 20) ; twenty keystrokes
(setq auto-save-timeout 10) ; ten idle seconds