18 January 2011

Emacs Spell Check in Mac OS X

If you use emacs on a Linux or non-Mac Unix machine, it probably already has iSpell installed and configured so you could spell check in emacs (eg, use M-$).

In Mac OS X, you'll do well to use ASpell instead via CocoaASpell.

In Windows...I don't know.  There is an ASpell ported to Win32, but it is horribly out of date.

If you know a good emacs spell check solution for Windows, let me know in the comments below.  Thanks.

16 January 2011

Is it Impossible to Secure Home WiFi?

So for an unsophisticated, or lazy, home network user wanting to have a wireless home network, is there a way to secure the home wifi network?  It seems not.

You could use WPA-PSK security protocol with a long and random password, then it'll get hacked in 20 minutes for less than $2 in computing power.

You could put in a mac address filter, so that only those computers with a registered mac address can even get on the network to begin with.  But it turns out mac addresses aren't just easy to modify, but they are communicated on the wireless unencrypted in the open, so it can be easily spoofed.

Another measure is to go with static IP addresses and a restricted IP pool, so there's less chance someone can get an IP address to your network while you're connected.  But it turns out my wireless router is too cheap to let me set static IP addresses on the LAN.  sigh

So am I supposed to install a RADIUS server now?


Instead, I turned down the wireless router's signal power, since I don't even go far from the router when I use the wireless.  At least hackers will have to be physically closer, I guess.


And maybe I'll try to find another ethernet cable so I can just turn off the wireless entirely.  A lot less headache than trying to secure an open channel.

15 January 2011

Multi-threading Windows MFC Visual Studio C++ 2005

I was going to use Boost Threads, but then it turned out the MFC threads worked well enough for my purposes (I'm programming in Visual Studio 2005 in C++ using the MFC framework).

The documentation is a bit scattered, so here's what I found useful:
I didn't find the following useful, but what the heck, they looked useful enough:
If you are comfortable with the concept of threads, and you're just looking to find the language constructs to make them, here's the short of it:

If you want a thread that will make GUI elements to interact with the user, you'll want to check out Multithreading: Creating User-Interface Threads, but otherwise, it's quite simple.

Write a non-member function — it could be a regular function, or a static function of a class object, but it cannot be a "method"/instance function (sorry, I'm probably mixing up Java terminology here).

Then use AfxBeginThread to "spin" off a thread that wraps around the function you just wrote.  It'll execute your function on a thread.  There are options that allow you to make sure the thread object thus created does not auto-delete — you'll have to flag AfxBeginThread to not auto start the thread though, then use ResumeThread to start the thread after you've set m_bAutoDelete.

You don't want the thread object to auto-delete once the function it wraps around is done executing because you might want to keep tabs on the thread.  You might want to block execution until the thread(s) are done executing.  You can do this blocking with the WaitFor*Object(s) functions (documentation linked at top as well).

If the thread auto-deletes, the WaitFor* function can explode while trying to check if the thread is done executing.

You can throw off multiple threads wrapping around the same function.  If the function interacts with the outside world, you'll have to keep track of any synchronization issues yourself though.

01 January 2011

Emacs Fonts

I use emacs on Windows, Mac, and Ubuntu Linux, and I've been trying to keep my .emacs file in sync on all three platforms.  One thing that bothered me was the font.  It looked good on Ubuntu without my setting it, but when I go to Windows or Mac (in X11), the default font was just no good.

So to fix it, I went to Revisiting Programming Fonts to select the fonts I wanted: Consolas on Windows, and Inconsolata on Mac.  I installed those as you usually would in each respective operating system (emacs will use the system available fonts).

And then I put this in my .emacs file:

(if (string= (symbol-name system-type) "windows-nt")
    (set-default-font "-outline-Consolas-normal-normal-normal-mono-18-*-*-*-c-*-iso8859-1")
  (modify-frame-parameters nil '((wait-for-wm . nil))))

(if (string= (symbol-name system-type) "darwin")
    (set-default-font "-outline-Inconsolata-normal-normal-normal-mono-18-*-*-*-c-*-iso8859-1")
  (modify-frame-parameters nil '((wait-for-wm . nil))))

Now, I get Consolas font on Windows, and Inconsolata on Mac, and whatever was my default on Ubuntu that I didn't have to set manually!

If you don't know what fonts are available, it turns out you could find out in emacs by doing M-x set-face-font, then choose default, then hit the tab key twice to see the completion listing.  Scroll through the listing until you see the font name you want.  After noting down the name, just hit C-g several times to exit out of set-face-font so you could make the selection permanent by making the above adjustment in your .emacs file.