Posts tagged with "guide"


C++ for loops with multiple increments

How I've been doing it:

for (; s1Begin != s1End; s1Begin++) {
    if (*s1Begin != *s2Begin)
        return false;
    s2Begin++;
}
return true;

And how I saw my UTS lecturer Gordon Lingard do it:

for (; s1Begin != s1End; s1Begin++, s2Begin++)
    if (*s1Begin != *s2Begin)
        return false;
return true;

Provided one has overloaded the == operator:

if (mind == blown)
    cout << rubenerd.post() << endl;

As for the photo? I didn't make it, it's from Wikibooks. Or at least, it used to be in 2007. Well played in any case ;).


Jekyll dates, timestamps require timezones

Crew from the USS Relativity, a timeship from Star Trek

No, I'm not referring to dating Jekyll, I'm already taken. I'm also not referring to those fruits that oddly enough I don't care for.

I couldn't figure out why posts with a defined date weren't appearing in my local Jekyll install. In the YAML matter, I'd written it as such:

date: 2005-01-24 12:00:36

Some more astute readers may already see the problem, but I was scratching my head late at night wondering why.

Turns out, you need to define the timezone:

date: 2005-01-24 12:00:36 +1000

It makes sense. If my base is UTC, that time I defined above wouldn't have happened yet, and I had configured Jekyll to not post items from the future. I mean, I'm not part of the USS Relativity's crew or anything.


Dealing with UTF8 in Perl

If you have Perl warnings enabled (like a good developer), chances are you've seen something like this when executing your script:

Wide character in print at ./[file].pl line [x].

As with everything in Perl, there are Many Ways™ to deal with this.

The first is to include the following line along with your regular Perl boilerplate. I always write my scripts and text files in UTF8, so this merely enforces UTF8 output.

binmode(STDOUT, ":utf8");

This will deal with those warnings, and let you get on with your work.

An alternative is to enforce UTF8 for STDIN and STDERR, as well as STDOUT with this line.

use open qw/:std :utf8/;

And of course, there's always a trusty environment variable.

export PERL_UNICODE=SDL

Install jekyll-import with --pre for now

Updating to the latest version of Jekyll, I got the following error when attempting to migrate a WXR file:

You must install the 'jekyll-import' gem before continuing.
* Do this by running `gem install jekyll-import`.
* Or if you need root privileges, run `sudo gem install jekyll-import`.

Sure enough, along with an entirely new site, Jekyll now uses importers instead of migrators, which reside in their own gem. Unfortunately, attempting to install this resulted in a new error.

ready % gem install jekyll-import
ERROR:  Could not find a valid gem 'jekyll-import' (>= 0) in any repository
ERROR:  Possible alternatives: jekyll-ebook, jekyll-epub, jekyll-reposter, module-import

It turns out that jekyll-import is still technically in beta, so needs to be installed thusly:

ready % gem install jekyll-import --pre

At the time of writing, this works in my bog standard RubyGems environment on Mac OS X 10.8.3, with the following dependencies and docs installed:

Fetching: fastercsv-1.5.5.gem (100%)
Fetching: nokogiri-1.5.9.gem (100%)
Building native extensions.  This could take a while...
Fetching: jekyll-import-0.1.0.beta1.gem (100%)
Successfully installed fastercsv-1.5.5
Successfully installed nokogiri-1.5.9
Successfully installed jekyll-import-0.1.0.beta1
3 gems installed
Installing ri documentation for fastercsv-1.5.5...
Installing ri documentation for nokogiri-1.5.9...
Installing ri documentation for jekyll-import-0.1.0.beta1...
Installing RDoc documentation for fastercsv-1.5.5...
Installing RDoc documentation for nokogiri-1.5.9...
Installing RDoc documentation for jekyll-import-0.1.0.beta1...

Using TextExpander with Perl? Hell yes!

After hearing about it on my beloved 5by5 Back to Work, I finally started using TextExpander. Today, I realised it can be used with my lifehacking language of choice.

Way of the future

TextExpander lets you assign blocks of text (or even images) to a shortcut you assign. For example, when I type ;nc it expands out to all my ncurses boilerplate. ;sig expands to my name, address, email, EARLs and phone numbers. You could leave it at that, and be crazy productive.

But you don't have to stop there. If you create a new shortcut and choose choose "Context: Shell Script" from the top of the editing box, you can write shell scripts to process stuff. I ignored it initially, largely for the same reason I eschew (gesundheit) most Western fast food. I can eat it, but I prefer other things.

Earning some Siracusa cred

On a hunch this morning, I decided to test the limits of this "Context: Shell Script" box and enter some Perl (which of course I inserted with its own TextExpander shortcut!):

#!/usr/local/bin/perl [...]
print("Hello, world");

When I typed my ;test shortcut, Hello was inserted in it's place.

Oh. My. SCIENCE.

That's right, TextExpander took the output from this Perl script, and used it in the substitution. Think of the possibilities. No, seriously, think of them.

I've used Perl scripts, a Dock shortcut and the Mac pasteboard to automate and send results to where I want since 2004. Now I'm going to go through them all and see how I can make TextExpander shortcuts for all of them.


Use FTP to download Firefox betas

Firefox-tan

So I wanted to to download the Firefox beta. I tried half a dozen times, and was either given a "connection reset by peer" error, or a stub file that's clearly too small to be a web browser. Well, links aside.

Fortunately, the public Mozilla FTP server works just fine, and seemed faster anyway.

For what it's worth, the Mozilla FTP server is fun just to browse in. There's a treasure trove of classic software there, including the original Phoenix browser us early adopters eagerly downloaded back in the day :).

Update: Typos pointed out by Clara.


Changing timezones in CentOS, Fedora, FreeBSD, Yuki

I knew how this worked in FreeBSD, and fortunately it works in the Red Hat world as well. First, make a backup of your existing timezone file, the create a symbolic link to your timezone. I've seen people copying the file instead, but I feel safer linking.

# mv /etc/localtime /etc/localtime.back
# ln -s /usr/share/zoneinfo/Singapore /etc/localtime

I'm tempted to set my timezone to Reykjavík, it's HOT in Sydney today. Nagato Yuki has the right idea. A-heh-hem.

UPDATE: @dai1311 on Twitter says that this also works on Arch Linux. Incidentally, his avatar is of Yuki!


14 years later, he tried SciTE

SciTE

I thought I'd tried every conceivable editor from the IBM E Editor to Vim and everything in between, but I'd never used SciTE before. #herpderp!

And you call yourself a hacker

SciTE is a simple, cross platform text editor with a tabbed interface, syntax highlighting for all the major suspects and a trippy icon. It also reads like "science" which is just too cool. It was originally developed by Neil Hodgson in 1998 to demonstrate the open source Scintilla editing library, but is now a fully featured application in its own right.

MacPorts has the latest version, and it's also available on the App Store. Fedora 17 had a fairly dated 2.x version in its repos, so I downloaded the latest and greatest 3.2.3 release and built it. The tarball also came with the latest version of Scintilla.

% sudo -s
# tar xzvf scite*tgz
# cd scintilla/gtk or scintilla/qt
# make
# cd ../../scite/gtk or /qt
# make
# make install
# exit

The output from make install. On Xfce it doesn't matter that it only installed a 48x48px icon in pixmaps, but this won't cut it on Gnome 3!

[root@nia]/usr/local/src/scite/gtk# make install
install -m 755 -d /usr/bin /usr/share/scite
install -m 755 ../bin/SciTE /usr/bin
for files in ../src/*.properties ../doc/*.html ../doc/SciTEIco.png ../doc/PrintHi.png; \
do \
install -m 644 $files /usr/share/scite; \
done
install -m 755 -d /usr/share/applications /usr/share/pixmaps
install -m 755 SciTE.desktop /usr/share/applications/SciTE.desktop
install -m 644 Sci48M.png /usr/share/pixmaps/Sci48M.png

Impressions

The beautiful, simple Geany IDE which I've been using for many years uses the same Scintilla library that SciTE does, and there is a bit of a family resemblance in the layout of the editing area.

On the Vim/Emacs continuum of kitchen-sinkness, SciTE falls more on the Vim side. The initial configuration is fairly sparse, and it's up to you to customise it the way you want. The first things I did were turning on line numbering and the status bar, which helpfully shows which column the cursor is in, and what type of newline is being employed (in my *nix case, LF). No doubt these can be customised.

SciTE languages

User configuration is stored in various *properties files which you can conveniently access from the Options menu. I haven't had time to look into this so far.

In terms of usability, it employs all the same key shortcuts we're used to in other applications, such as CTRL+S for save. I'll admit in Geany I never have this problem, but in SciTE I keep reaching for that escape key to start hammering away my Vim shortcuts. Perhaps it's the minimalist interface ;).

Pushing onto my editor stack

For someone who otherwise likes minimalism and doesn't install things unless he really needs them, the last thing I need is another editor. On this ThinkPad right now I have Gvim, Geany, LaTeXila, NetBeans, JASSPA MicroEmacs, Torvald's me, Bluefish and Leafpad from Xfce. I've also been told to try Sublime Text, and I have Chocolat on my Mac. I'll commit to one eventually ^_^;;


XAMPP: Couldn’t start MySQL

Running a fresh XAMPP install on Fedora 17 this morning, I kept getting this error. I even RTFM!

I can't guarantee if this will work for you, but I re-extracted the archive with the -p to preserve file permissions:

# xvpfz xampp-linux-1.8.1.tar.gz -C /opt

Now MySQL in XAMPP starts:

# /opt/lampp/lampp start
Starting XAMPP for Linux 1.8.1...
XAMPP: Starting Apache with SSL (and PHP5)...
XAMPP: Starting MySQL...
XAMPP: Starting ProFTPD...
XAMPP for Linux started.

I'm thinking I should have a separate blog for tips like this. My neglected university hosted site, perhaps?

As an aside, the XAMPP icon in this post is by anekdamian on DeviantART. Much nicer than the default icon.


Running XAMPP on Fedora x86_64

XAMPP is currently only availably as 32 bit application. Please use a 32 bit compatibility library for your system.

Aaaaaaaah!

The problem

We've all seen that famously misspelled error message when attempting to install XAMPP on our 64 bit desktop Linux machines. I wonder how many people using XAMPP are still on 32 bit? I suppose enough to justify keeping it 32 bit. Speaking of which, this Kingston biscuit is falling to bits. Munch munch.

Here's the install scenario that will result in that error.

# tar xzvf xampp-linux-[version].tar.gz -O /opt
# cd /opt
# ./lampp start

Chemists have solutions

Other guides I've come across ask you to install a slew of things, and changing the launch script. For me on Fedora 17 x86_64, I was able to run it just by installing this:

# yum install glibc.i686

This also pulls in nss-softokn-freebl.i686.

Now you can run XAMPP without modification:

# tar -C /opt
 sudo ./lampp start
XAMPP: SELinux is activated. Making XAMPP fit SELinux...
Starting XAMPP for Linux 1.8.1...
XAMPP: Starting Apache with SSL (and PHP5)...
XAMPP: Starting MySQL...
XAMPP: Starting ProFTPD...
XAMPP for Linux started.