Archive | Configuration RSS for this section

Profiling With Gprof

As promised, today I’ll be talking about GProf.

What Is GProf?

Gprof is a profiling tool. There are two versions: the original written for BSD UNIX, and a re-implementation for Linux. There are some minor differences between the two that you can read about here. We are going to concern ourselves with the Linux version.

Gprof is a pretty bare-bones utility. In the spirit of UNIX it does just one thing well. It doesn’t have any fancy menus or exotic extras. You just run it and it goes.

Preparing Your Program

First things first, we need to compile and link our program with profiling enabled. Using gcc, this is easy; just add -pg to the compile and linking options. If you’re using NetBeans, this is simple as well.

In NetBeans, right click your project and click Properties

Click Build > C Compiler. In the Additional Options field, add -pg to the end.

Click Build > Linker. In the Additional Options field, add -pg to the end.

Click OK. You are now good to go. Clean and build your project and you are ready for the next step.

Run Some Test Cases

Here is where things get confusing. You’ve compiled your program, surely you have to run your application within gprof similar to how you ran Valgrind, right? Let’s give that a shot…

# gprof [your_program] gmon.out: No such file or directory

Hmm… I’ll save you some time: Google will tell you that gmon.out should be there, clearly you messed something up and you’re a bad person.

Here’s the secret: you aren’t supposed to run your program through gprof at first. You need to run your program by itself first and it will create gmon.out in the current directory upon termination. Repeated runs will replace the existing gmon.out file. Run your application and perform some test cases. Follow good test practices and really stress your program. Now, you are ready to generate your profile data. Make sure gmon.out is in the current working directory and then…

gprof [your_program] > [output_file]

GProf should return without error and there should be a new file. Open it up in your favorite text editor. As you can see, it contains a flat profile, and a call graph of your program. Below each is a description of the columns. You should be able to take it from here, but if you want additional information check out the GNU gprof webpage.

Oh yeah, and don’t forget to remove the -pg from your compiler and linker lines when you’re done; they’ll tank your performance.

DMP Photo Booth: Deep Magick

After working on DMP Photo Booth for a few months, the day came when I needed to implement actual functionality. It’s the day we all dread, but for me this was no longer some looming menace; it was time to stop fiddling around in my framework and actually build on it.

More specifically, it was time to figure out how to turn ~5 images and a background into a photo strip. After checking to make sure GLib and GTK didn’t provide this functionality (GdkPixbuf almost cuts it, but as far as I can tell, it can’t layer images over each other), I turned to google. After some time, I settled on my library: ImageMagick.

ImageMagick bills itself as sort of a command-line PhotoShop. I was suspicious as well, but that’s neither here nor there. The thing about ImageMagick that interested me is its language bindings. ImageMagick provides a library for many languages, including two for C: MagickCore for “Wizard-level developers” and MagickWand for us chumps. Being a chump, I decided to go with MagickWand.

NetBeans configuration

This was relatively straightforward. If you got GTK set up, this should be no problem for you. First, ensure you have the WagickWand development headers. On Ubuntu, this can be accomplished by the following command:

sudo apt-get install libmagickwand5 libmagickwand-dev

On my system, libmagickwand5 was already installed, so I downloaded the headers and got to work.

Next, in NetBeans click Tools->Options, click on the C/C++ tab, and click on Code Assistance. Add the location of the ImageMagick headers (/usr/include/ImageMagick for me). Click OK.

Next, we need to set up our project. Right click your project and click Properties. Click Build->C Compiler. Under Additional Options, add MagickWand to your pkg-config --cflags string. Click Build->Linker and do the same with your pkg-config --libs string.

You are now ready to conjure some magick!

Conjuring Some Magick

Now, let us put on our robes and wizard hats; it’s time to do some magick! Let’s go over a function that will overlay a resized image over a larger background. You can find the actual production photo strip function on Github.

void cast_magick_spell() { MagickWandGenesis(); ...

Before we can do anything, we must initialize MagickWand. “MagickWandGenesis()”, you ask? Of course the function would be called MagickWandGenesis, what kind of silly question is that?

... MagickWand * background_wand = NewMagickWand(); MagickWand * working_wand = NewMagickWand(); MagickWand * final_wand = NULL; ...

The MagickWand * is the main object passed around in a MagickWand application. Working with MagickWand requires some juggling of these pointers, which is why we have 3 of them.

... if (!MagickReadImage(background_wand, "/tmp/background.jpg") { ...

This function reads an image from a file. It returns MagickTrue on success, and MagickFalse on failure. If it returns MagickFalse, we have some clean-up to do…

... ExceptionType exception_error_code; char * exception_message = MagickGetException( background_wand, &exception_error_code); ...

MagickWand makes use of “Exceptions” throughout, so if a function fails, you can most likely pull an exception out of it using MagickGetException. Like any exception, it is up to you what to do with them. Since I’m using GLib, I’ve been wrapping them in a GError and propagating them up. This is actually very easy to do; your error code and message are already there. All you need to do is G_DEFINE_QUARK your error quark and throw it in there. For the purposes of this function, I’m just going to use printf, do some cleanup, and return.

... printf("Oh no! Exception %d: %s\n", exception_error_code, exception_message); MagickRelinquishMemory(exception_message); DestroyMagickWand(background_wand); DestroyMagickWand(working_wand); return; } ...

Nothing particularly shocking here. We printf our message, free the exception_message string using MagickRelinquishMemory, free our MagickWands using DestroyMagickWand, and return.

Assuming we make it past this block, background_wand now contains the background image. Next, we load the foreground image:

... if (!MagickReadImage(working_wand, "/tmp/foreground.jpg") { /* * Exception handling omitted * for brevity. You should still * do it here... */ } if (!MagickResizeImage(working_wand, [WIDTH], [HEIGHT], LanczosFilter, [BLUR])); { /* More error checking... */ } ...

After loading the foreground image, and doing our error checking we attempt to resize the image using MagickResizeImage. This function takes several parameters:

  • MagickWand * working_wand: The MagickWand to operate on
  • size_t [WIDTH]: the width to set the image to
  • size_t [HEIGHT]: the height to set the image to
  • FilterTypes LanczosFilter: the filter to use to resize. There are a list of them in the API documentation. Discussion of these is outside the scope of this post.
  • double [BLUR]: The blur factor to apply. 1.0 is no change. The further 1.0, the blurrier the resulting image.

Like many calls in this library, this function can return MagickTrue or MagickFalse. If it returns MagickFalse, something threw… Next, we adjust the position of the image…

... if (!MagickResetImagePage(working_wand, [RELATIVE_PAGE_SPECIFIER])) { /* * You'd think one of these wizards * could have written a function that * doesn't throw... */ } ...

This function takes some explaining. The second parameter: char * [RELATIVE_PAGE_SPECIFIER] is what’s doing the work here. This is a Magickally formatted string that looks like this: "100x100+15+15!". Let’s examine this as a printf formatting string:

"%dx%d+%d+%d!"

We have 4 integer tokens here. The first token is canvas width, and the second is the canvas height. Note that these will not resize the image, so don’t get any bright ideas about eliminating the previous resize call. The third and fourth tokens are offset from X and Y respectively. These are what we’re really concerned about here. This will allow us to position our foreground image over the background.

Also, don’t forget to check for exceptions!

... MagickSetLastIterator(background_wand); if (!MagickAddImage(background_wand, working_wand)) { /* exceptional! */ } ...

We’re almost there! Now we have to add the images from working_wand to background_wand. These MagickWand objects are lists of images. Like most lists, they have iterators. The call to MagickSetLastIterator sets background_wand’s iterator to the last image in the list. Any images add will be added after this image. next we call MagickAddImage which adds copies of working_wand’s images into background_wand. As before, don’t forget to check for exceptions.

... final_wand=MagickCoalesceImages(background_wand); if (!final_wand) { /* You guessed it! */ } MagickSetLastIterator(final_wand); ...

Now we need to combine all our images into one single image. This is accomplished by calling MagickCoalesceImages which returns a new MagickWand with all of our images combined into 1. The MagickWand used for this call remains unaffected. Obviously, if final_wand == NULL, something threw.

After this is done, we need to set the iterator of final_wand to the Last Iterator, or the next step doesn’t work as advertised…

... if (!MagickWriteImage(final_wand, "/tmp/final.jpg")) { /* wait for it! */ } ...

Shockingly, this function writes your new image to a file. Make sure you check your exceptions.

... DestroyMagickWand(background_wand); DestroyMagickWand(working_wand); DestroyMagickWand(final_wand); MagickWandTerminus(); }

…and were done! Clean up your pointers and call MagickWandTerminus to finalize the MagickWand library. If you browse to /tmp, you should have a newly created final.jpg if all was well!

Would I Do It Again?

Sure.

ImageMagick was a decently easy to work with library. The documentation wasn’t amazing, but it was tolerable. I’m still a little hazy on the use of the [RELATIVE_PAGE_SPECIFIER], but it’s working so far. One nice thing about the docs is that there are many examples. If the docs don’t explain something, you can look up an example and get an idea of how things work.

The only really big issue I have with this library is how it handles exceptions. This is an issue that I’ve touched on before; it is all too easy to forget to check a return code. I went down that road with DMP Photo Booth, and I’ve since rejected it. I spent an entire day refactoring my program to use GError.

MagickWand has exceptions, they’re just really easy to ignore. While writing this blog post, I caught several instances of unchecked return values in my 1 function that uses MagickWand. Tomorrow I plan to fix this, but it’s time I could be spending on something else.

If GError is Java’s checked exceptions with all it’s order and verbosity, then MagickWand’s exceptions are the Wild Wild West of C++’s unchecked exceptions. If you’ve spent any time working with C++, this has almost certainly bit you; some function doesn’t document if it throws, and your program magickally starts crashing because you didn’t catch something. Bad times are had by all. Sure, you could throw a try/catch block in main() and catch all exceptions to keep from crashing, but at that point your program is a dead man walking. Best to put it out of its misery…

Personally, if I ever write a personal project in C++ again, I’m likely to disable exceptions in my program; they’re just more effort than they’re worth. Maybe I’d even use GError in my C++ app if I could convince myself that I’m not a bad person for using a C library in C++.

Regardless, one blemish on an otherwise pleasant experience is no big deal. Here’s to a successful foray into the land of High Adventure!

Learning to Arduino: Push Button

Getting a little less abstract today, I’d like to talk about the Push Button. Sorry, that doesn’t have a fancy name. Try to contain your disappointment.

The push button is actually very simple in theory. Most push buttons have four contacts. Two of these contacts are connected at all times, and there is a normally open switch between the two “wires”.

push_button1

When the button is pressed, the contact closes. The tricky part comes in the implementation.

pinMode(pin, INPUT): REVEAL YOUR SECRETS!

You’d be yelling too if you’d spent as much time as I trying to figure this out.

A typical application of the Push Button, is in an arduino device. Arduinos have multiple digital pins that can be configured as inputs or outputs. Google Arduino Push Button Tutorial, and you’ll find several tutorials that suggest you implement something similar to this:

push_button

The thing that nobody is talking about: what is the voltage of the digital pin in input mode. This is the thing I’ve been spending the last few hours trying to figure out: how does this work? If the voltage is 0, nothing should happen when the button is not depressed. If the voltage is 5, then nothing should happen when the button is depressed. It turns out, according to my multimeter, that this pin is actually very slightly less than 0 Volts.

As you can see from my diagram, the digital pin is connected to the switch, and the opposite end is connected to a 10K Ohm resistor to ground. On the other side of the switch is 5 Volts. When the switch is open, electrons flow from ground (0 Volts) to the input pin (slightly less than 0 Volts) and digitalRead() returns LOW. When the Push Button is depressed, electrons flow from the input pin (slightly less than 0) to the 5 Volt pin, and digitalRead() returns HIGH.

All is again well in the world.

DMP Photo Booth: A Question of Configuration

Over the past few weeks, I’ve been busy laying the ground work for DMP Photo Booth. Creating NetBeans projects, shelling out the module libraries, creating unit tests, making sure everything compiles, making sure my API is sane… While doing all of this, it occurred to me that I need to provide a standardized way to configure modules. After all, one size not fitting all is the reason I went down this road in the first place.

Creeping…

I’ve decided that each module needs to have three functions added:

char * dmp_**_get_config_location(char * to_fill, size_t size); int dmp_**_edit_config(); int dmp_**_load_config();

For each of these, the ** stands for the module prefix, so tm for the trigger module, cm for the camera module, and pm for the printer module.

get_config_location

This function returns the path to the module’s config file. Logically, this file would be located in the same folder as the module, but I don’t want to make the rules if I don’t have to. This function takes an allocated char *, and a size_t that describes the length of said string, and fills the string with/returns the location of the module config. It is the caller’s responsibility to free this string afterward.

edit_config

This function instructs the module to edit it’s config. It is up to the module how they want to handle this, the core will not impose any requirements on this. The module could launch vi to edit a flat file, the module could launch a fancy editing interface, the module could open a web page, the module could just display the output of get_config_location in a popup. If the module doesn’t require configuration, it can just return DMP_PB_SUCCESS and be done with it if that’s what it wants.

load_config

This function instructs the module to reload it’s configuration. This idea is that after this function is called, the old config is purged and replaced with the new config.

Moving Forward

Nobody likes a constantly changing API. That said, I can’t promise at this point that it will not change. Things are still fluid, and that makes right now the best time to make changes. Better to refactor early than to be stuck with a mistake in the name of a concrete API.

Simple Unit Testing with NetBeans

As we all know, real software developers use Unit Tests to help sanity check their code. Like all things, Unit Tests have their pros and cons.

Pro: Good unit tests will help you detect when a code change has broken the build in some obscure way
Pro: Writing them will help you better understand how your code works together
Pro: They will simplify testing to just the click of a button
Pro: You will be one step closer to becoming a Priest of the Temple of TDD

Con: It just sounds like so much work

It is true, unit tests can be tedious to create, and it seems easier to just not do it. After all, while everybody isn’t perfect, I sure am, amirite?

Or, you could just be a good person and do your due diligence in making unit tests. You’ll thank yourself later. I know my very first unit test in DMP Photo Booth uncovered a typo that would have gone undetected for a long time, and likely given me a few gray hairs.

The good news, is that it’s really not that hard. With NetBeans, much of the boilerplate is automated. The even better news is that you don’t even have to come up with some fancy framework to make decent tests. I’ll tell you how!

Creating a Unit Test

First, in NetBeans, in the projects pane, right click the source file you’d like to create tests for. Click Create Test > New C Simple Test ...

Select the functions you’d like to create tests for, and click Next >

In the next step, there are two fields you need to be concerned with: Test Name, and Test File Name. Test Name is the name of your test package. You can think of this as a folder that holds your tests. I like to call mine [PROJECT_NAME]_tests. Test File Name is the actual unit test source code file. I like to call mine [FILE_TO_BE_TESTED_NAME]_tests. However you configure these fields, you should consider clicking Finish when you’re done.

When you click Finish, a new test file will be created. As it stands, if you run your test, it will always fail. You need to do some configuration.

First things first; each function has a corresponding test function with a signature of:

void test[FUNCTION_NAME] ();

Each test function requires some customization to work correctly. Each test function sets up for, and calls the function it is testing. Your job is to tell it how to do all of this. Give it some test data, and in the if block, tell it what should be returned. The idea is that if the result check resolves as false, the test has failed.

After you have set up the failure check, you should customize the failure message. You can do this by modifying the end of the printf within the failure message. At the end of the message, you should see a section that says message=error message sample. This is what is displayed by NetBeans upon a test failure. You should customize this bit to say something useful. Since this is printf, you can use token replacing to customize this. You could probably go with something to the effect of ... message=Test failed, returned: %d\n", result); and be in good shape.

Either way, when you’re done save and close your test file.

Running Your Test

Now the easy part: running your tests. This is as simple as right clicking your project in the Projects pane, and clicking Test. Your tests will run, and if all is well, they will all pass. If not, then you’ve caught an error early.

Either way: mission accomplished!

Configuring NetBeans for GTK Development

Tired of creating console applications in C? Me too. Normally, when it comes time to create a GUI application I turn to good old Java Swing. This is fine and all, but how can I be a proper hoity-toity C programmer who scoffs at the very notion of Java if I can’t even create a proper C GUI app? Clearly, this will not do…

While I do have some experience with QT in the past, I’ve decided to go with GTK. QT is a C++-only toolkit, and I’m not a huge fan of C++. QT also introduces a bunch of magic keywords and requires the use of a special pre-compiler. Meanwhile, GTK is a C library, and requires no fancy pre-compiler. But before I can do anything, I need to configure my environment…

Code Assistance

First, the easy part. You need to make sure you have the GTK development headers installed. If you’re running Ubuntu, this is a simple apt-get:

sudo apt-get install libgtk-3-dev

Now, the hard part. First, we need to launch netbeans. Click Tools -> Options and click C/C++. Click on the Code Assistance tab. Ensure you have the C Compiler tab selected, and the correct toolchain is selected in Tool Collection dropdown. Next, open a new terminal. Enter:

pkg-config --cflags gtk+-3.0

Did you see that gigantic list of paths? You’d better believe that you’re adding all of those to your Include Directories. For each folder, you need to click Add, enter the path in the File Name field, and click Select. When you’re done, your Include Directories should look similar to this:

Click OK when you’re done. Now, it’s time to create a new project. Click File -> New Project… Select C/C++ and Select C/C++ Application. Click Next >. Give your project a name. Ensure that C is selected in the dropdown next to Create Main File, and ensure you have the correct toolchain selected in the Tool Collection dropdown. Click Finish.

Project Properties

Now, it’s time to configure our project properties. Right click your newly created project and click Properties. Click on Build -> C Compiler. Remember in the code completion section when we typed that command and got that gigantic list? Luckily for us, unlike Netbeans, GCC knows what to do with that. In the Compilation Line -> Additional Options field, enter:

`pkg-config --cflags gtk+-3.0`

Note that those are `back qoutes`, not ‘single quotes’. To be clear, it’s the quote located on the ~ button. Next, click Build -> Linker. In the Compilation Line -> Additional Options field, enter:

`pkg-config --libs gtk+-3.0

Note that this line is –libs, not –cflags. If you enter this command, minus backquotes, on the command line, you’ll see it give a list of libraries instead of include paths. When you are done, click OK.

Drumroll…

Open up your main.c source file. At the top of the file, enter:

#include <gtk/gtk.h>

Wait for it…

Wait…
For…
It!

Did Yellow Jaggies appear? Congratulations, you’ve come across the same problem that’s had me troubleshooting for the last 4 hours, and that’s made me give up on GTK several times before. Luckily for you, I have the solution.

Hold Ctrl+Alt and click on include. This should open up the header with the missing inclusion. Find the red jaggies. Open a terminal and enter:

sudo find / -name MISSING_HEADER.h

If the file is not located at the correct spot, try re-installing the library. However, if it is found and in the correct position, then the issue is with code completion. Return to netbeans and click Tools -> Options and click C/C++. Click on the Code Assistance tab. Ensure you have the C Compiler tab selected, and the correct toolchain is selected in Tool Collection dropdown. Locate the offending library, and click Up until it’s at the top of the group of libraries that you just added. Click OK

Did the yellow jaggies go away? Congratulations, you’re done. Otherwise, you get to keep doing this until it works.

When All of That is Done…

Now, it’s time to try it out. For now, you can just copy and paste the Hello World implementation from the GTK+3 Reference Manual. Copy and paste the whole thing, overwriting your existing main function, build it, and run it. If all is well, you should see a window like this:

Pour yourself a glass of wine, and grab a tiny piece of cheese. You are one step closer to lording over the Java Plebians!

In Defense of Multiple Partitions in Linux

If you’ve ever installed Linux or UNIX, you’ve surely come across this idea: installing across several partitions. These days it’s not so common in many distros, but just a few years back everybody wanted you to do it. Reccommended partition tables included: /, /var, /var/log, /usr, /boot, /home, /tmp, SWAP, and /everyone/and/their/mother. The silliness knew no end. Lately, in the age of Ubuntu, distros have decided that this list could be reduced to: /, /boot and SWAP. I’m here to urge you not to go along with this.

Why not?

I’m glad you asked. If you do a quick google search for why you should have multiple partitions like this, you’ll see the usual enterprisey reasons. The words “security” and “disk quotas” will come up often. You might think that as an end user you don’t really care about these things. You’d probably be right. Indeed, in this day and age you tend to only see these crazy partitions schemes server operings systems like Solaris.

There is one thing that typical Linux end users do tend to do though: switch distros. With so many choices, it’s easy to want to try a different one. Maybe you’re tired of replacing Iceweasel with real Firefox, so you switch to Ubuntu. Maybe Mark Shuttleworth spoke ill of your mother, so you switch to Mint. Maybe you want real Java, which only comes packaged in a .rpm, so you switch to Fedora. Either way, if all your filesystems are in one partition you’ll be sorry.

One of the historical problems with Linux that has yet to be solved is cleanly upgrading and replacing distros. Some try to support in-place upgrades, but the process still involves prayer. Others have extremely convoluted processes that are much harder than starting from scratch. My personal home server is still running Debian Squeeze because the upgrade process sounds like so much work.

Oh Dear. What Should I Do?

The solution is simple. There is no need for the complicated partition schemes of yore. All you need to do is partition your system like so: /, /boot, SWAP, and /home. If you partition your system like this, then switching distros is simple. All you need to do is not touch this partition. You will be able to delete and recreate /, /boot, and SWAP, and leave /home untouched. This will ensure your data is safe. Obviously backups are in order when messing with partitions, but it’s a pretty safe bet if you decide to gamble on it. So long as you don’t use some crazy filesystem for /home, the new distro should be able to mount it seamlessly.

Configuring Netbeans for Arduino Development

After spending some time using Eclipse and Arduino IDE for Arduino development, I’ve decided enough is enough! No longer will I put up with the unbearable hardship of using some other IDE. It’s NetBeans or bust! Well, it was a long road, but I’ve made it. If you’d like to make it too, then I can help.

Arduino IDE

First, we need to install the Arduino IDE. On Ubuntu, this is a simple apt-get:

sudo apt-get install arduino arduino-core gdb-avr

When that is finished, run the Arduino IDE.

Click Add when prompted about Dialout permissions

Enter your password

Before we can continue, we must logout, then log back in for the updated permissions to take effect.

Verify it works

Open Arduino IDE

Click File -> Examples -> 01.Basics -> Blink

A new window should launch with code for the basic blink program.

Plug your Arduino Uno into your computer via usb port. Click Tools -> Serial Port and select the correct Serial port

Click the Upload button on the toolbar. If all is well, your Pin 13 LED should start blinking.

Netbeans configuration

Launch Netbeans

Click Tools -> Options

Click on the C/C++ tab

In the bottom left corner, click Add…

In the Base Directory: field, enter the location of your AVR tool collection. apt-get put mine at /usr/bin

In the Tool Collection Family: dropdown, select GNU

In the Tool Collection Name: field, enter Arduino. Click OK when done

The various commands will be populated with the standard GNU toolkit commands. This is not what we want. Change them all to their avr equivalents: avr-gcc, avr-g++, avr-as, and avr-gdb. There is no avr-make, so leave it as the standard make. Feel free to clear the QMake Command: field.

Click the Code Assistance tab. Ensure the Tool Collection: dropdown has your Arduino toolchain selected and that the C Compiler tab is selected

Add arduino libraries. These are:

/usr/share/arduino/hardware/arduino/cores/arduino /usr/share/arduino/hardware/arduino/variants/[VARIANT] /usr/share/arduino/libraries

Click C++ Compiler. Add the same libraries as above

Click OK

The Plugin

For our plugin, we’ll be using arduino-netbeans by Jaques Claudino

Click the above link, and navigate to Downloads. Download the latest Linux plugin.

When the download is completed, return to NetBeans.

Click Tools -> Plugins and click the Downloaded tab

Click Add Plugins…

Browse to the location of the downloaded plugin, select it, and click OK

Click Install

Follow the wizard.

When prompted about an untrusted certificate, we might as well click Continue. After all, we are downloading software made by Some Guy, it’s not going to be signed by VeriSign or somesuch.

Click Finish when done.

Click Close.

Verify it works

Click File -> New Project…

Select Arduino and click Next >

Give your project a name, and click Finish.

First, open up the Makefile for your project, we have some changes to make

As the comments at the top of the Makefile say, we need to make some changes. First set COM_PORT to be the correct serial port.

Next Set ARDUINO_BASE_DIR to the correct installation path. For me, that is /usr/share/arduino

Next, uncomment the correct configuration. Since I am using an Uno, there is no change for me. However, if you have a different board, comment the Uno section and uncomment the correct board.

We should officially be set. In your main.cpp, implement the blink program. I recommend copying and pasting the one provided by Arduino IDE that we used previously. Be sure you don’t delete the #include and extern HardwareSerial Serial; lines.

When you are ready, click Clean and Build. Then click Run. If all is well, your onboard Pin 13 LED should blink.

Just get on Github!

“Just get on github!” If you’re an up and coming programmer in this day and age, I’m sure you’ve heard this before. So you went to github, got an account, and then thought “now what?”

Maybe you typed git at the command prompt, and got some error about it not being installed. Maybe you even did step 1 below. Maybe you’ve now turned to google, and it was less than helpful. Or hopefully it brought you here and you find this slightly more than helpful. Either way, the first thing you need to do is install git.

If you’re using Ubuntu, or some other Debian based distro, that should be a simple apt-get:

sudo apt-get install git

It will want to install some extra stuff; let it. When it’s done you’re ready to get started. First, you need to tell it who you are:

git config --global user.email "[EMAIL_ADDRESS]" git config --global user.name "[NAME]"

This e-mail address and username will be used with your commits. You should use the same e-mail and username that your github account uses.

Next you need a repository. If you have one already, you can skip this step. Otherwise, login to your github account, and click New Repository.

Give your repository a name and a description. Check “Initialize this repository with a README”, and select a license. Click Create repository.

You should now be sitting at the page for your newly created repository. On the bottom right hand corner of the page, there should be a text field labeled “HTTPS clone URL”. Copy the provided URL, you’ll need that for the next step.

At your command prompt, cd to the directory where you want your repository located. Once there enter:

git clone [HTTPS CLONE URL FROM ABOVE]

You should now have a local copy of your repository. You should cd into your repository folder; for all operations below, you need to be sitting in this folder.

To add things to it, copy it into the repository folder and enter:

git add [THING_TO_ADD]

To commit changes to something you’ve added:

git commit -m "[COMMIT_MESSAGE]"

When you’re ready to push your changes back to github:

git push

You will be prompted for your github username and password.

At this point, you can login to your github page, and your repository should reflect any changes you made.

…And just like that, you’re on Github. Now, get to work!

Using Someone’s Programming: LibreOffice Math

For the last couple weeks, I’ve been completely absorbed in the calculus class I’m taking this month. I volunteered to write up the professor’s handwritten lecture notes for the class for extra credit. Unfortunately, that means trying to type things like:

…and…

into a word document… This is about as fun as you’d guess.

When I volunteered for this assignment, I figured I’d use LibreOffice Math for the formulas bit. The first thing I learned? LibreOffice Math is useless by itself for notetaking. The only thing it does is write equations, so don’t even bother trying to annotate anything in it. Luckily for me, Writer isn’t useless. After poking around, I figured out that you could embed Math formulas into a Writer document. I was off!

First, you need to show the insert toolbar. Click View -> Toolbars -> Insert

The button you are looking for on your new toolbar is:

When you click that, the bottom of your Writer window will be taken over by Math. Insert your formula and click out when your done. The Math pane will disappear. When you are done, you can export your document to .pdf, thereby ensuring anybody can view it, not just people who can open a .odf file.

To export, click this button: , which should be on the Standard toolbar.

Example: Integral

The code for the Integral example above is:

int from 0 to 29 {{e^{-5 x} abs{lnx}} over {x^-x} dx}

Going through that step by step:

int from X to Y {...} Creates the integral sign, bounded by X and Y. X is the bottom bound, and Y is the top. If you omit from X to Y and just enter int {…}, your integral will be unbounded.

NOTE: use {} to group things. If you don’t, it can make life difficult. Sometimes things will work, sometimes they wont. Obviously there are rules, but you can either remember said rules, or just put things in braces. I chose the latter, I have enough problems right now…

X^Y Creates an exponent: X to the power of Y. Using braces you can put pretty much anything in an exponent.

X over Y Creates a fraction: X/Y. Once again, group things in braces, or know true fear.

abs{X} The absolute value of X

Example: Bounded Brace:

The code for the bounded brace example above is:

[1,000,000,000^{x^2}]binom {1,000}{-1,000}

Notable things in that:

Inside the brace is an example of a nested exponent.

binom {X}{Y} Places X directly on top of Y. There doesn’t appear to be support for a bounded brace, however the effect can be simulated using the binom command. This example is a good illustration of why you use braces. If you leave it off, Math will set 1,000-1,000 as the top number.

Formatting:

Math supports many formatting options. Some I’ve found useful:

underline{X} underlines X. Useful for showing answers and things of that nature.

newline inserts a newline

rightarrow inserts a right arrow. Yes, left up and down work too.

` and ~ inserts a small and large space. Math ignores whitespace, so if you want to insert whitespace, this is the way to go.

NOTE: Make sure you type ` (on the same button as ~), not ‘ (on the same button as “)! The second one will only succeed in putting a random apostrophe in your formula!

In conclusion:

There are many more commands, as well as a simple to use pallet of options. If you want to know how to do something, just find and click the button and it will be inserted at the cursor. Once you get the hang of it, Math is actually a pretty easy program to use.

Just be careful: I’ve noticed that sometimes my formulas delete themselves from my Writer document. I haven’t been able to determine what causes it, but if I do, it may just become my first contribution to LibreOffice!