Strings 

March 8th, 2011

Just a small thing encase anyone else finds this interesting as such.. but you cannot add a set of ” ” strings together in c++ without declaring one being a string.. for example

cout << "hi" + "bye" << endl;

the error would be

error: invalid operands of types ‘const char [3]’ and ‘const char [4]’ to binary ‘operator+

because c++ treats them both as char[] variables and not as a string, so you need to wrap one up into a string for it to work

cout << string("hi") + "bye" << endl;

Why -> and not *name.type 

March 8th, 2011

When you are coding with pointers in c++ and you want to access the function/variable from that pointer deferenced, how come you cannot use something like below.

struct typeT{
   int value1;
};
 
typeT* tt = new typeT;
*tt.value1;

it is because the access element of the variable tt is higher in the compiler and thus it tries to equate

tt.value1

first, which is not a good thing because the tt has not been de-referenced and thus it is just a memory address pointer to the actual object. so you need to do

(*tt).value1

because like in maths the () will be equated first and then the access element part “.” and thus to make it easier

tt->value1

will change to

(*tt).value1

within the compiler.

Moonlight 

March 8th, 2011

Within kubuntu (or ubuntu derived setups) you can have a moonlight development .. aka the silverlight open source version that will run on linux.

if you install the

monodevelop-moonlight

and also the

monodoc-moonlight-manual

packages, the last one is the manual if you need some help, but the first one will allow the monodevelop development environment have the moonlight plugin which creates a project to develop silverlight applications in.

Curly brackets 

March 8th, 2011

It all depends on your type of coding, but I for style I do prefer to put array data within a separate part of the echo statement, for example.

$arr = array("first" => 1, "second" =>2);
 
echo "this is the first value " . $arr["first"];

but of course you can put the arr object within the echo statement as long as you { .. } it out, which is kinder similar to using the ” . as such,

echo "this is the second value {$arr["second"]}";

both work, but because of the array object uses the “..” for the hash key, then you will need to use the { .. }

X session cannot start /tmp 

March 8th, 2011

If you get a error like

Error: X session cannot start /tmp 
Error: unable to write to the /tmp

or similar errors to the above when trying to log into KDE

it could be because you have run out of inodes (the disk structure that allows you to create new files) or hard drive space.

I had this same problem, and after doing

apt-get clean

to clean out of the temporary files that apt-get has used

and also since I am compiling up my own kernels, I deleted some of the

/usr/src 
 
linux-source
linux-source-2.6.32

directories and then I was able to start up X, which is great.. something of a better error would have been better.. cannot create file, make sure that you have the space!!. sort of thing..

also sometimes if your X session does not start, if you delete your home directory (The user’s home directory that you are trying to login to) .Xauthority

e.g.

rm ~/.Xauthority

because that is sometimes a lock on the xsession.

Rewrite Engine 

March 8th, 2011

Because I own the codingfriends.co.uk, but would like to point that to the www.codingfriends.com

Here is a good way to make it so that any requests to the domain name codingfriends.co.uk (rewrite condition of the host record) will redirect to www.codingfriends.com with a redirection of HTTP 301 (moved permanently).

RewriteEngine On
RewriteCond ${HTTP_HOST} !^(www)\.codingfriends\.co\.uk 
RewriteRule (.*) http://www.codingfriends.com/$1 [L,R=301]

Save that to the .htaccess root directory file. Hope that helps.

Delete object from array within javascript 

January 12th, 2011

Someone asked me whilst doing a job how to delete parts of a array within javascript, so just like other object oriented languages, you can have a array of data objects and each one can be accessible and removable. To achieve this with javascript you use the delete method as below.

var myArray = new Array();
myArray[0] = "first value";
myArray[1] = "second value";
 
// and to delete the second value
delete myArray[1];