Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Tuesday, August 25, 2009

Code::Blocks "process terminted with signal 255 (0 minutes, 0 seconds)"

Yesterday after I came home from work I thought I'd try working on a project I've been working on this past weekend.
I was away from home this weekend, so all the work I'd done had been on another computer, in a virtual Ubuntu installation, so I hadn't yet tried it at home.

Trying to build it went fine. Running it from a terminal went fine. Even compiling and running on another Ubuntu installation (my work laptop, non-virtual) went fine, but Code::Blocks reported to me that whenever I tried running my application on my Fedora 11 home installation that it terminated with signal 255.
I couldn't find what was wrong, I knew the application worked since I tested it in another terminal window and if I debugged it it'd go great up to the point where it met with a cin or cout.
Being tired from a really long day (getting up at 5:00am, get on train at 6:25am, get off train at 8:30am and at work 8:50am), I gave up fairly quickly.

This morning though the itch got worse and I just had to investigate further.
After about a minute of looking around I found someone at the Ubuntu Forums asking about the exact same thing and it turns out that the problem was that xterm wasn't installed. So a simple
su -c "yum install xterm"
was enough to fix the problem.

Now I can start developing my application again!

Tuesday, July 21, 2009

My custom RDP script

I have a crazy situation. I work at a .Net company, but my installed OS is Linux (Ubuntu Jaunty atm). This is ok though, I asked my boss first, because we use Remote Desktop to do almost all actual work.
Now we move around from time to time. So sometimes I have a different printer I need to share with the server. And since I also want to share a single folder with the server (not my entire filesystem like the TerminalServer client would like), so I decided to write a bash script to help me decide where I am.

startremote.sh:
#!/bin/bash

# Ask where we are, since we don't know where we might end up we add 'other'
# which will default to no extra parameters
srem_WL=$(zenity --list --text="Were Are You?" --radiolist --column="Pick" --column="Locations" TRUE location1 FALSE location2 FALSE other)

# Only do something if cancel wasn't pressed
if [ -n "$srem_WL" ]; then

# The user on the server, I use $USER because I know that on this PC I'll
# always be logged in under the same name as on the server
srem_usr=$USER

# The IP address of the server
srem_ip=0.0.0.0

# The size I want my screen to be
# I add the -g here because one might want fullscreen (with -f)
srem_geo="-g 1910x1120"

# The shares I want to send along
srem_share="-r disk:ShareName=/path/to/some/share"

# The start of my execute command
srem_ex="rdesktop $srem_geo $srem_share"

if [ -n $srem_WL ]; then
# Here we define the configuration differences for each location
case $srem_WL in
location1)
srem_ex+=" -r printer:MyPrinterForLocation1"
;;
location2)
srem_ex+=" -r printer:MyPrinterForLocation2"
;;
esac
# Since other has not been added to the case list it won't add anything
fi

# The end of our execute command
srem_ex+=" -u $srem_usr $srem_up"

# EXECUTE
$srem_ex
fi
You could of course also always share both printers, rdesktop won't complain if it isn't connected, but I'm always looking for stuff to program. And this way you can kind-of create different profiles for different locations.

Wednesday, June 3, 2009

No more C++ today

Alas, I was not able to write what I wanted to today, so I will not be able to post anything explaining what the hell I'm doing.
I will try again tomorrow though, maybe I'll be able to find some more then.

I know there's 2 people per year or something that stumble down here, but in case someone just happens to stumble down here tonight, here's my problem:
I've made a very simple class with only a few properties. I put this class in a set and when I try to do this:
myClass myclass;
mySet.insert(mySet.end(), myclass);

of course in what I'm working on this class is filled with data, but this is just a quick post. I might be missing something, since I'm tired and the NetBeans error messages confuse me.

Anyway, maybe a night of sleep and a day of work will improve my thinking capacity.
I think it might have something to do with comparison, since one of the messages I see when looking at Netbeans' output it seems to say that it doesn't have a > operator for __y > __x.

Hmm, must quit now, more to follow tomorrow.

Tuesday, June 2, 2009

C++: Some more stuff

I thought it might be best to write some extra info on the stuff I wrote yesterday about reading and writing stuff from and to files.

First thing is that I started off with a header (*.h) file. For those who really don't know C++ (pretty much like me then), these files are used to kind of 'define' the corresponding source files.
What we did in there was let whichever other file includes this one know that the source file that should come with this header file contains 1 class with 2 public functions, both returning void.

We then write those functions in the *.cpp file (which we should have named the same as the .h file, except change it's extension from .h to .cpp). In this file we use className::functionName to indicate that this function we're writing belongs the that previously (in the .h file) defined class. The '::' being the scope operator, you can use it to tell what which variable belongs to within your code.

I also seem to have forgotten to post the actual main.cpp file, sorry for this, It was late and I was both rushed and tired, but here it is:
#include "filerw.h"

int main()
{
FileRW filerw;
filerw.read();

return 0;
}
We include our header (.h) file so that the compiler knows where to look for that class we instantiate.

Now this is where it gets kind of weird for me. I'm used to writing in C#, so that first line would create a warning that filerw was never instantiated and at runtime an exception that filerw is null. Here though this seems enough to declare and instantiate. We then call the read() function from the class we wrote and it should work.

Our application will return 0 to let everything involved know that it exited correctly, any other value would mean that our application crashed.

As you can see I don't do anything with the write() function. We could, you could add a line write("anything"); there and it should do what you expect (append "anything" to the end of the file, if the file didn't exists yet, it should now have been created).

So I think this is all I can tell you right now, I'll try to write some more once I've written some more code.

Monday, June 1, 2009

C++: Reading from and writing to a file

Me being the idiot that I am, I am not satisfied that I have just recently finally really gotten my random wallpaper script working with Python. Nooo, now I feel like a sell-out since I'd already written it in C++ once and unfortunately lost that somehow.
So now that it works in Python, of course I just had to decide to write it in C++ again too.
I found, though, that I am severely lacking in C++ knowledge. All the tutorials I followed almost a year ago now (I think it was at least 3) have all been next to lost from my mind.

Fortunately I had decided on completing a very simple task for today, since it was already 10pm when I started on this: Read all lines from a file and be able to write a line to a file, the rest will come later.

I started out with creating a header file that looked like this:
#include <string>

class FileRW {
public:
void add(std::string filename);
void read();
};
Declaring a class called FileRW and 2 public functions: add, read

Now for the simplest of implementations of these functions we're going to read a file with read() and add a line with write()

first we have to include
#include <iostream>
#include <fstream>
#include <string>
#include "filerw.h"
That last one is, of course, to include the header file I wrote before, which I called filerw.h

to keep it simple we'll also be
using namespace std;
otherwise we'd be writing std:: everywhere, which is just not so much fun really...

then the functions:
void PaperConfig::read() {
string line; // string where a line will be stored

// Open the file for reading
ifstream myfile("test.txt");
// If the file was opened
if (myfile.is_open()) {
// Until it reaches the end of the file
while (!myfile.eof()) {
// Get the next line
getline(myfile, line);

// If it's not an empty line, print it
if (line != "")
cout << line << endl;
}

// Close the file
myfile.close();
}
// If the file was not opened
else
cout << "Unable to open file";
}
We use ifstream (in file stream?) to open the file for reading.
We use the line variable as a temporary variable to store each line we read in so that we can write it to the console (or do something else with it). We use myfile.is_open() to check if the file could be opened, if not then it'll tell us and we use myfile.eof() to check if we have anything left to work with.
If the currently read line does not equal "" (an empty string).
When we're done we close the file.
void PaperConfig::add(string filename) {
// Open file for writing and set the append flag
ofstream myfile("test.txt", ios::app);

// Write filename to file
myfile << filename << endl;

// Close the file
myfile.close();
}
Here we use the ofstream (out file stream?) to open the file for writing and the ios::app flag to tell the stream to append whatever we write to the end of the file.
Then we write our parameter string to the myfile object like we write a lot of other things to cout and we add an endline character (endl)
Finally we close the file, this way we don't keep things in memory we don't need to.

Now I hope I have explained enough in this post, I don't often write things like this (in case you don't get it this is my version of a tutorial, but even I can't really call it that because it is writting in about 30 minutes) so if you see room for improvement please let me know. I will try to write more things like this in the future and hope to get better at writing, C++ and software development in general.