Friday, December 11, 2009

Gnome-shell in Ubuntu 9.10

Even though gnome-shell is really only a preview of what is to come for gnome 3.0 and it's still buggy and sometimes not completely stable perhaps, I really like it.

When I first saw the screenshots I was less then impressed, I thought it didn't at all look like anything new or innovative, but rather messy and confusing. But me being ever interested in new things and all I just had to give it a try (the gnome-panel look was starting to bore me).

Installing was easy
sudo apt-get install gnome-shell
and starting it afterwards was easy too
gnome-shell -r
Though first I had to disable compiz, which I don't really use anyway.
I was also using avant-window-navigator, which disappeared on me but still kept part of my notification area to itself. So the time after that I first closed AWN and all was as it should be.

I didn't feel like having to manually start gnome-shell every time I logged in so I started looking into a way to replace metacity and gnome-panel with gnome-shell and found that this could be done by editing you gconf (with, for example, gconf-editor) and setting the /desktop/gnome/session/required_components/windowmanager key from metacity to gnome-shell.

Of course, since it is a composited window manager you need a video card and driver that can handle screen compositing.

Wednesday, December 9, 2009

mod_rewrite with Fedora 10 and ISPConfig for WordPress

This relates to Fedora 10 and ISPConfig 3.0.1 set up as described in this HowtoForge post

One of my colleagues recently got interested in offering our clients Wordpress as a content management system, so he's been trying it out.
Yesterday he found out that if he wanted to change the permalink style in Wordpress he needed write access to .htaccess, which he didn't have because the user rights haven't been set up very well there.
So I gave him write access by using
chown apache:apache .htaccess
Unfortunately this resulted in a 500 Interal Server Error.
Looking at the error log for the website I tried this for it let me know that RewriteEngine directives were not allowed in the .htaccess.
Since I didn't want to mess with the base configurations of ISPConfig I started looking around for other options. Eventually I found that I had to add something similar to this to the Apache directives field under options under the website's settings
<IfModule mod_rewrite.c>
<Directory /var/www/[sitename]/web/>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</Directory>
</IfModule>
Of course [sitename] should be replaced with the name of your website.

It all works after I restarted the apache server myself, but I do not know if that is completely necessary. Also it might take a few seconds before ISPConfig finishes editing the configuration file.

Tuesday, September 22, 2009

Higher Resolution in Fedora 11 with proprietary NVidia Drivers

Ugh... I have been screwing around with this since the beginning of time... Or at least since I installed Fedora for the so-manieth time. Finally though I found out what I had to do.

Following this guide, I was able to easily and correctly install the drivers. I used to build them myself, but that got me worse results then anything.
To sum up, though:
# switch to super user (root)
su
# install rpmfusion repository
rpm -Uvh \
http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm \
http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
# install the driver (I have an i686 pc, you might need a different architecture, like 64_32 or something similar)
yum install kmod-nvidia xorg-x11-drv-nvidia-libs.i586
# reboot to make changed take effect
reboot

This only got me a 1024x768 resolution, though... Which pissed me off...

I started looking around the internet for a way to fix it in the xorg.conf itself, which I'd done on Fedora 9 before, but didn't remember how (the reason I'm writing this right now), but didn't actually find what I was looking for.

In the end I found 2 supposed fixes, one added a Modes option to the "Display" section of the "Screen" section, and another was to add a DisplaySize option to the "Monitor" section.
Well, I found out I needed both, so I added DisplaySize 1280 1024 to the "Monitor" section and Modes "1280x1024" to the "Display" subsection of the "Screen" section.

Now it's working again, running at 1280x1024 with screen compositing (so I can run gnome-do with docky theme, which I'm trying out for a while).

Friday, September 11, 2009

A simple gnome-blog test

I've been looking for some way to post blog entries from my desktop for a while now, I've come across Drivel (which crashes when I try to log in to blogger with it), can't find a Bleezer package at work (just checked it, first time I heard of it today) and no other gtk/gnome client seems appealing.


Let's see what this gnome-blog app does.


Not much so far, bold or italic seems the be the only options available to me at the moment, let's see about HTML:


to install gnome-blog in Ubuntu 9.04 use

sudo apt-get install gnome-blog
and the rest should then be self-evident.

Tuesday, September 8, 2009

Removing a service manually in Windows Server 2008

I was writing a test Windows Service and accidentally removed it through the Programs and Features dialog, which removes the files, but doesn't actually remove the service from the service list. So when I tried to install the 2nd version of this test service it was complaining that it already existed.

I looked around a little and found that I could delete the Service from the registry in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\[Your service]. I deleted the key (the little folder thingy) and it did show some change, but my service was still there and the newer version still wouldn't install.

After a little more looking around I found out that to fix it I could use sc delete [YourService] to fix it. And it did!

Next time, though, I really should use the installer I used to install it to remove it...

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!

Wednesday, August 19, 2009

Low Resolution in Fedora 11 with Nvidia drivers

Finally, after hours of looking and working I have finally again found how to set the resolution to what I need (have 1280x1024, had 640x480). I've had trouble with my resolution in Fedora before, but I don't ever remember it being this much of a pain, but then again I don't remember much about it at all, wish I'd remembered how I fixed it.
So to help me remember and perhaps even help someone else work around it, here's how I finally got it working.

I'm now using the Nouveau driver with a generic LCD Panel 1280x1024. I tried setting this in
system-config-display
many times, but it just wouldn't accept my monitor.
So in the end I looked at
system-config-display --help
and noticed
--reconfigure
, which doesn't base the new configuration file on an old one.
Using this option and setting my driver to nv and my monitor to generic 1280x1024 and then
su -c "init 3"
[log in]
su -c "init 5"
got me the right resolution again. However the nv driver is just a little too basic, so I thought I'd try the same thing with the proprietary driver, so I did everything exactly as before, only I used the driver nvidia instead of nv.
Now again X wouldn't start at all, so I ran
livna-config-display -a
to get it to my old low-res configuration, and then I tried it a third time, this time using the nouveau driver (which I've heard is better then nv) and that worked!

I know that supposedly you're also able to use xorg.conf to set certain Modes values for your display, but this didn't do anything for me at all in fedora, did help me in ubuntu, but then there I got the weirdest resolution.

finally I can look at a normal screen again.

Now I should get going to work, I'm gonna be really late (this really bugged me!)

Tuesday, August 18, 2009

Convert .VOB to .WMV with ffmpeg in Linux

A fairly simple command gets the job done:
ffmpeg -i filename.vob -vcodec wmv2 -acodec wmav2 -sameq -s 720x576 filename.wmv

Tuesday, July 21, 2009

SyntaxHighlighter follow-up

Something about SyntaxHighlighter has just caught my attention.

As I'd mentioned in my post about it I started out from an older version. I noticed there are a few more brushes then I'd initially added.

I added
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCpp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCSharp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCss.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushJava.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushJScript.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushSql.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushXml.js' type='text/javascript'/>
But the list consists of
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushAS3.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushBash.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCSharp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCpp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushCss.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushDelphi.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushDiff.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushGroovy.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushJScript.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushJava.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushJavaFX.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPerl.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPhp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPlain.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPowerShell.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushPython.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushRuby.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushScala.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushSql.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushVb.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.320/scripts/shBrushXml.js' type='text/javascript'/>
Wow that's quite a few. You can add any/all of these along with or instead of the ones I'd posted before. Each one is needed for it's respective language, of course.

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.

Friday, July 17, 2009

SyntaxHighlighter with Blogger

Since I post some code from time to time in this blog and I like the idea of syntax highlighting I looked into adding SyntaxHighlighter to my page. I'd found this post by someone else explaining how to do it, but by now this was a little outdated.

So now I thought that I might do this too, since I seem to have gotten it working. Here's what I did:

  1. (Using blogger) log in and go to Layout -> Edit HTML
  2. Insert this code right before the </body> tag:
    <link href='http://alexgorbatchev.com/pub/sh/[VERSION]/styles/shCore.css' rel='stylesheet' type='text/css'/>
    <link href='http://alexgorbatchev.com/pub/sh/[VERSION]/styles/shThemeDefault.css' id='shTheme' rel='stylesheet' type='text/css'/>

    <script src='http://alexgorbatchev.com/pub/sh/[VERSION]/scripts/shCore.js' type='text/javascript'/>

    <script src='http://alexgorbatchev.com/pub/sh/[VERSION]/scripts/shBrushCpp.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/[VERSION]/scripts/shBrushCSharp.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/[VERSION]/scripts/shBrushCss.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/[VERSION]/scripts/shBrushJava.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/[VERSION]/scripts/shBrushJScript.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/[VERSION]/scripts/shBrushSql.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/[VERSION]/scripts/shBrushXml.js' type='text/javascript'/>

    <script class='javascript'>
    //<![CDATA[
    function FindTagsByName(container, name, Tag)
    {
    var elements = document.getElementsByTagName(Tag);
    for (var i = 0; i < elements.length; i++)
    {
    if (elements[i].getAttribute("name") == name)
    {
    container.push(elements[i]);
    }
    }
    }
    var elements = [];
    FindTagsByName(elements, "code", "pre");
    FindTagsByName(elements, "code", "textarea");

    for(var i=0; i < elements.length; i++) {
    if(elements[i].nodeName.toUpperCase() == "TEXTAREA") {
    var childNode = elements[i].childNodes[0];
    var newNode = document.createTextNode(childNode.nodeValue.replace(/<br\s*\/?>/gi,'\n'));
    elements[i].replaceChild(newNode, childNode);

    }
    else if(elements[i].nodeName.toUpperCase() == "PRE") {
    brs = elements[i].getElementsByTagName("br");
    for(var j = 0, brLength = brs.length; j < brLength; j++) {
    var newNode = document.createTextNode("\n");
    elements[i].replaceChild(newNode, brs[0]);
    }
    }
    }
    //clipboard does not work well, no line breaks
    // dp.SyntaxHighlighter.ClipboardSwf =
    //"http://alexgorbatchev.com/pub/sh/[VERSION]/scripts/clipboard.swf";
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
    //]]>
    </script>
The SyntaxHightlighter.config.bloggerMode = true; is used to be able to use line breaks in your code snippets with blogger.

If you go here you can select your [VERSION] and if you then go to [VERSION]/styles/ you can see some shTheme*.css files where you can select the theme you would like to use.

Tuesday, July 7, 2009

An IComparer

In .Net you can very easily create a special class to handle comparing of (custom) objects. All you have to do is implement the IComparer or IComparer interface and implement it's one simple function: Compare.

So write a class that implements it:
public class MyComparer : IComparer<MyObj>
{
public int Compare(MyObj x, MyObj y) {
// If, for example you're working with an int:
return x.IntProperty.CompareTo(y.IntProperty);

// If, perhaps, it is a string:
return string.CompareTo(x.StringProperty, y.StringProperty)
}
}
The value you return must be negative if x is less then y, 0 if x is equal to y or greater then 0 if x is greater then y.

This can of course be used with things like MyCollection.Sort(new MyComparer()), really handy if you have strange objects.

Thursday, July 2, 2009

SQL Null

I am seriously confused by whatever it is that makes SQL (At least PL/SQL and T-SQL) consider null in a completely different way then anything else.

If I write a query
SELECT *
FROM table1
WHERE column1 = 0
Then of course if column1 hasn't been filled yet it won't return anything since null != 0

Sooo, then why is it that this query
SELECT *
FROM table1
WHERE column1 != 1
Won't return anything at all either.

I understand that null is not really like anything else, but to exclude it when looking for something in a certain column seems odd to me, or am I missing something?

Thursday, June 25, 2009

My Reflection

The other day I had some trouble with ASP.Net. I was saving a class I'd written into the ViewState (I did this a long time ago, I know now that that might not be the best idea) and it was giving me errors saying that the ViewState was corrupted somwhere around saving it into or loading it from the ViewState.

I had to fix this, but I still needed all the information inside the class. Even though I knew that it was not the right thing to do really and in the end proved to be seriously useless since another measure I took apparently removed the need of saving it in the ViewState altogether.

I did find a solution that worked before the other thing started to take over. I wrote 2 functions, one to save the info in the object into the ViewState and one to load it again.
using System;
using System.Reflection;

namespace My.NameSpace
{
class MyClass
{
private void savetoViewState(MyObj saveobject)
{
Type t = saveobject.GetType();
foreach (PropertyInfo info in t.GetProperties())
{
object value = info.GetValue(saveobject, null);
if (value != null && test.GetType().Namespace == "System")
ViewSate["myobj_" + info.Name] = value;
}
}

private MyObj loadfromViewState()
{
MyObj myObj = new MyObj();
Type t = myObj.GetType();

foreach (PropertyInfo info in t.GetProperties())
{
object obj = ViewState["myobj_" + info.Name];
if (obj != null)
info.SetValue(myObj, obj, null);
}

return myObj;
}
}

class MyObj
{
public string Name
{
get;
set;
}

public int Number
{
get;
set;
}
}
}
In the save function we get the type of the object we're working with, because the type class has some very nice reflection functions, among which are GetProperties(), GetMethods(), GetContructors and many more.
We use the GetProperties method to get all the properties and we loop through them in a foreach loop. Now we can examine each property seperately.

We get the value of the property by calling the PropertyInfo.GetValue() method which requires the object from which to get the property (our argument in this case) and an object array of index values, so that you can, I'm guessing, get a or multiple items in an array. The index must be null of you're getting non-indexed properties.

Then we check if our value is null, because if it is we don't need to save it, and we check to see if the namespace of the property's type is System, which in my case made sure that I was only saving properties that were of type System.String or System.Int32 etc and not Some.NameSpace.In.My.Project.

Finally if our property's value gets through these checks, we save it in the ViewState with a prefix to identify it as part of our object.

In the load function we do something very similar. First we instantiate a new instance of our class and we again get the type of it.
Then we loop through all it's properties, much like we did in the save function.
Now, though, we get a value from the ViewState, which should correspond to what we saved in there before. Now if there is a property that we didn't save then getting it from the ViewState will of course result in null, so we check if the value if null. If it's not then we call the PropertyInfo.SetValue() method which needs the instance of the object it must place the value in, then the value that it must place and again like with GetValue() an object array of indexes.

Once we've looped through all the properties, it should again be filled with all the relevant information and we're good to get to work on it again.

This is my first little bit of Reflection that I've written to date. I know it's not much, but since I didn't know if MyObj was going to stay the way it was and I wanted it to work regardless. I also didn't feel like going ViewState["myobj_name"] = myObj.Name; over and over, since the object I was working with had many more properties than this example.

In the line with if (value != null && test.GetType().Namespace == "System") I had just gotten the value of the property, if it had one at all, and then I'm checking to see if the type of that property's namespace equals "System", this is because in the object I was working with also had a few properties that were connected to lazy-loaded database entities, which in turn also had these, and if I wanted to save these then it would have been a serious disaster (Damn how did I ever think that writing an object like that in the ViewState would just work...).

Anyway, it's fun to see how easy a simple reflection function can be. I'd read about it when I studied for my certificate exams and I saw some of it at the Microsoft Dev Days this year, but it always seemed complicated and strange to me. All the more reason to try it out somewhere.

Friday, June 5, 2009

SVN+SSH username trouble in Netbeans 6.5

Haha, I was having trouble with SVN in Netbeans. It was trying to log in with the wrong user. I could checkout fine by editing the tunnel parameters in the checkout window, but after that if I tried updating it'd use my local username instead of the one I use on the server.

After looking around a bit I found the answer!
In the checkout window, when asked for the url of your svn server, add your username to the url twice. so
svn+ssh://username@username@ip.address.of.server/location/of/svn/repository
should do the trick, apparently Netbeans only removes the first username@ from the url. I tested it and it does seem to work.

Thursday, June 4, 2009

Quick mail post

Linux has an excellent command: mail, now who can guess what it does?

Anyway, I was searching how to send something with this today even though I've looked at this before, it somehow got screwed up.
We only have mail on our server (and sendmail, but that seems way more complicated) and we need to send an attachment and have a sender address.

After looking around for a while I found this:
uuencode $writefile $readfile |\
mail -s "$subject" $recipient -- -r "$sender"

sorry if you don't like the use of variables in explanations, but this seemed easiest.
$writefileis the filename as the person recieving the email will see it (can be same as $readfile)
$readfileis the filename as it is stored on your hard drive
$subjectis of course the subject of the mail you are sending
$recipientis the email address of the person you're sending it to
$senderis the email address that others will see in the From: field in their mail

uuencode should encode the file so that it will show as an attachment instead of just binary giberish or plain text, but for me, in thunderbird, this doesn't work.
the '|' of course means that you're using the left command as input for the right one
and mail is the mail command.

Wednesday, June 3, 2009

No C++ at all today

I've only done a little bit of work on whatever it might be that I am working on today, but I did make some promising progress. I decided I might not be able to use the map and instead might use the vector, the only problem with vector is that it doesn't seem to have a find() function or anything similar.

I will work on it some more tomorrow and try to write some more.

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.

Blue Dragon

A while ago I finished playing through Blue Dragon on the XBOX360. I've told myself that I should write something about each game I finish to improve on my writing skills.

Now Blue Dragon is a fun game that unfortunately suffers from some faults. It has a very typical story, typical main-character and of course the trademark look and feel from Akira Toriyama, creator of Dragonball.
Being from Akira Toriyama it is fun to walk around the world and see all the different species of creatures living together and co-operating with each other.

The battle system is old. It is unfortunately very repetitive and can get on your nerves from time to time. The thing that really bugged me is that none of the characters in the game have any real weapons or armor, so nothing changed on them through the entire game.
Monster fights are fun though, but they are (to me at least) too much of a hassle to get together all the time.
Balance is a little out of whack though, mostly Disc 1 is easy and you don't really have any trouble with anything or anyone, then Disc 2 becomes slightly annoying since there are a lot of fights and they take a few turns, and though the battles have ok animations they take a while to execute and you start falling asleep after a while, this is the point where I left my XBOX on for 2 weeks without playing.

Story is fun, but nothing spectacular. Boy and friends want to save village, they get lost, they get back, they leave for a big 'ol adventure.

I don't really have much else to say. I liked playing it, I loved getting through it (finally) and that's about it, it's not very remarkable in any respect (other then it's made by Akira Toriyama).