Wednesday, April 30, 2014

Paste unformatted text in Word on Mac OS

This will be short and not very computer science-y, but I was making a list by pasting a bunch of items from various places on the web and Word kept formatting it according to the HTML (which I went around by first pasting the text in the Chrome bar and then copying that, because otherwise my lists would turn out wrong even if I did "match formatting"). Anyway, here's the smart way to do it.

Say we want to use Command+Shift+V to paste unformatted text (I think that's what it does in Windows by default-- well replace Command by Control obviously).

  • copy some internet formatted text (this bullet point works just fine)
  • go to Tools->Macro->Record New Macro...
  • type a name for the macro (can leave the default), eg: "PastePlainText"
  • click (on the exact center of) the "Keyboard" in "Assign macro to"
  • press "command" "shift" "v" on your keyboard in sequence
  • click "Assign" first
  • click "OK"
  • Go to Edit->Paste Special and select "Unformatted Text", click OK
  • Go to Tools->Macro->Stop recording
  • Go to Tools->Macro->Macros and highlight your "PastePlainText" macro, and click Edit
  • Replace "wdPasteDefault" with "wdFormatPlainText", save and return to Word (there's a blue W Word symbol in the toolbar there, click on that)
  • And, you're done!

P.S.: I thought there was a way to assign this by using System Preferences -> Keyboard shortcuts but I just tried and that only works for actual Menu items, so the best that could do is open the "Paste Special" menu, so this is a far better solution.
P.P.S.: I learned this by watching this video. Not sure what that person gains if you click on the link, so do so, but I never got exactly why I'd watch a video instead of reading 5 bullet points (with images if something is very complicated). So, click on the video and then close it I guess. But thanks to the author anyway!
P.P.P.S.: I ended up using Ctrl+Shift+V because the other combination was already assigned to something (not sure what, didn't want to dig into it)

Tuesday, April 29, 2014

Mac OS Finder Sidebar - Want the bookmark icons colored? Read on!

I just restarted my computer and was stuck again in no-color land for my Finder Bookmarks. I do not get their choice of making them all, well, basically the same. I know they wanted to be slick and all, but I find it just so confusing (and I miss previous Finder versions where the color of your icon could tell you automatically what you needed to click on). But enough of the editorial: if you're here you probably feel the same!

To get your wonderful color-coded icons back, you need to install a small program. You could download SIMBL, but I remember having problems with it, so download EasySIMBL.
Then download ColorfulSidebar and follow their instructions (basically open EasySIMBL and drag-and drop the ColorfulSidebar bundle there or in the SIMBL plugins folder). Make sure the bundle file is checked in the list, and also check "use SIMBL" at the top.

I think you may have to restart Finder (Either login and logout of Mac OS X, or just kill the Finder through the Terminal to relaunch it: killall Finder) though it worked automatically for me this time (I didn't go through the install process again, I just had to check "use SIMBL" after restarting my Mac).

Enjoy the colors!

Tuesday, February 25, 2014

SyntaxHighlighter

I mentioned in my previous post that I'm using  SyntaxHighlighter. Well, it took some configuring!
First off, I followed this tutorial. But then nothing would happen. Turns out, at least for me, the SyntaxHighlighter.config.clipboardSwf link got converted to the HTML encoding of the quotes, no matter what I did. Then I eventually found out that you need to write like this to prevent encoding (with the CDATA)

And then, all of my links kept getting forwarded to https://alekgorbatchev... (instead of http://) which meant that nothing worked when I tried to preview the page. Turns out this is because of the new browser "feature" that looks for secure webpages if viewed from a secure webpage. And if I previewed the page, blogger (or is it Google Chrome) automatically makes it secure (since the new post page is secure). So if you want to preview it, you should manually remove the https. It has no effect on people viewing the page, since they are viewing the non-secure version when they look at your blog. In any case, this is the final version of what I have before my </head> tag (notice the lack of http: and the agorbatchev.typepad.com/pub/sh/3_0_83 instead of alexgorbatchev.com/pub/sh/current/):



Monday, February 24, 2014

Netbeans and CppUnit on Mac OS X Mavericks

To continue logging my progress with NetBeans.

I wanted to get into this whole unit testing business, since there's never been a class I actually used that for, and a lot of actual jobs want you to know it. So, since NetBeans is my current IDE of choice (I actually do not have a reason  for this, except that I managed to make GDB and C++ work on it) and since the project has a logical folder called "Test Files", I decided to give it a try.

I'm mostly using this guide, but it's sort of misleading, since it's doing CUnit and I wanted to do CppUnit. So, I followed that guide to install CUnit, and then I went on to add a CppUnit, oops. Turns out those two are different, so I had to install the CppUnit also. Which was confusing on Mac OS (I downloaded the file but couldn't figure out how to configure it on the first go through). 

Then I remembered that I have Homebrew installed, so I decided to take full advantage of that. So, I did a:
brew install cppunit
which worked out-of-the-box.

And then I went on following the guide. I wrote the equivalent of their example (yeah, removed the .h includes essentially)
#include <cstdlib>
#include <iostream>

using namespace std;

long factorial(int arg) {
    long result = 1;
    int i;
    for (i = 2; i <= arg; ++i) {
        result *= i;
     }
    return result;
}

int main(int argc, char** argv) {
    printf("Type an integer and press Enter to calculate the integer's factorial: \n");
    int arg;
    cin>>arg;
    cout<<"factorial("<<arg<<") = "<<factorial(arg)<<endl;
    return 0;
}

And then I right-clicked on the cpp file, selected Create Test -> New CppUnit Test, and then selected my cpp file (at the top of the options, which automatically also selected the factorial function). I left everything else default, per the tutorial.

And then I happily right clicked the Test Files logical folder, and selected Test from there, only to get a bunch of errors. Turns out Homebrew doesn't put the cppunit files where Netbeans expects them.

Turns out the newtestclass.h file contains this include
#include <cppunit/extensions/HelperMacros.h>
And the compiler has no idea where to look for that. This was an easy fix:
Preferences -> C/C++ -> Code Assistance -> C++ Compiler

Select Add on the right-hand-side, and add this:
/usr/local/Cellar/cppunit/1.12.1/include
So, that gets rid of the warning, but then the big error came.
/bin/sh: cppunit-config: command not found
along with many other information.

But! If I went to my terminal and ran
cppunit-config
it worked!

So, I googled forever for an answer, which took me through the netbeans.conf file to no avail. The only thing that worked was starting Netbeans from the terminal.


Note: I should now have syntax highlighting here, thanks to Awesome code syntax highlighting made easy and SyntaxHighlighter (which is the main reason I quoted that much code). But it took me forever to get this to work, I'll make another post right after this one.

Monday, January 27, 2014

Netbeans C++ and GDB on Mac OS X Mavericks

I'm starting to use an IDE for the first time since basically high school (I used Visual Studio for a school project briefly but reverted to just using a make file because my Mac is more powerful and new than my PC after only 2 class projects), and I decided to use Netbeans (after some search this seemed to be more appropriate for my small project needs than Xcode).

But lo and behold, Macs/Xcode/Command Line Tools no longer support GDB, and GDB is the "supported" debugger in Netbeans (they have an option for Clang, but I found that out later). So, if you have Mavericks and want to use GDB to debug your C/C++ projects in Netbeans, this is what worked for me!

Install homebrew. You can do this with MacPorts or by just downloading GDB and building it, but I used homebrew cause that's what I had installed.

Download GDB using homebrew. Now, this is the command that you should use (there are many bad links out there): 
>> brew install https://raw.github.com/Homebrew/homebrew-dupes/master/gdb.rb

Now, basically follow what this link says. I'll write exactly what I did below in any case.

Start Keychain Access application (/Applications/Utilities/Keychain Access.app)

Open menu /Keychain Access/Certificate Assistant/Create a Certificate...

Choose a name (gdb-cert in the example), set Identity Type to Self Signed Root, set Certificate Type to Code Signing and select the Let me override defaults

Click several times on Continue until you get to the Specify a Location For The Certificate screen, then set Keychain to System.

In Keychains -> System in the main window, right click on your certificate and select Get Info.

Open the Trust item (down the page), and set Code Signing to Always Trust.

Quit Keychain Access.

Kill all taskgated processes. Note that these need sudo:
>> sudo killall taskgated

Now, find your copy of gdb, if you used homebrew to install version 7.6.2 do this:
>> cd /usr/local/Cellar/gdb/7.6.2/bin

And codesign it:
>> codesign -s gdb-cert gdb

One last step, if you want to actually be able to use gdb in Netbeans and get a debugger is missing or invalid error, go to NetBeans->Preferences->C/C++->Build Tools and set Debugger Command to /usr/local/bin/gdb.