X session cannot start /tmp

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

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

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];

Adding floats together with commas and decimal places

Someone contacted me about adding some numbers together with comma’s and dots within there values, here is the email via the contact me page.

“Please I need a javascript code that can enable me add two or more numbers containing dot(.) and/or comma (,) together. For example, 122.34 + 233.56. Or/And 233,239.34 + 323,322.44. Thanks in advance.”

Here is the code that will accomplish the request.

<html>
<script type="text/javascript" >
       function load()
       {
               var value1="233,122.34";
               var value2="233.56";
               alert(parseFloat(value1.replace(",",""))+parseFloat(value2.replace(",","")));
       }
 
</script>
<body onload="load()">
</body>
</html>

The main part is the parseFloat and replacing the “,” with nothing “” to remove the none float characters via the object replace method.

CKEditor – adding custom style sheet

Within the CKEditor editor you can add in custom style sheets to assist with styling of the content within the editor and here is how you do it

CKEDITOR.config.contentsCss = '/css/mycssfilename.css' ;

After you have created the instance of the CKEditor you just need to add in to the configuration the contents cascading style sheet file.

CKEditor – auto save

A follow on from the previous post CKEditor custom dialog you can auto save the content with sending a AJAX call to another page that will save the content and also give back a updated time of that content saved.

I created a function called autosave(), that will call itself every 20 seconds (20000 milliseconds). This will get the data (getData()) from the CKEditor instance called content and then go some JQuery to do the actual AJAX function which in-turn calls the url autosave.php (can be any backend page that will deal with saving the data) and once the backend page has completed then update the HTML element with the ID of lastsavetime to the new time that is returned from the webpage.

function autosave()
{
   var t = setTimeout("autosave()", 20000);
 
  var content = escape(CKEDITOR.instances.content.getData());
   if (content.length > 0)
   {
       $.ajax(
       {
           type: "POST",
           url: "autosave.php?method=saveCKEditor",
           data : "content="+content,
           cache: false,
           success: function(message)
           {
               $("#lastsavetime").empty().append("Last saved : "+message);
           },
       });
   }
}
$(document).ready(function(){
    autosave();
}); ";

CKEditor – custom dialog

The CKEditor is a great WYSIWYG and the best thing is that you are able to customize the interface to have buttons on the toolbars, here is a way that I created a custom button with custom image attached to it.

The editor is created with

var editor = CKEDITOR.replace( 'Content');

So from now on in the variable editor is linked to the CKEditor instance, to setup the plugins to load when the CKEditor is created you call the pluginsLoaded function

 editor.on( 'pluginsLoaded', function( ev )
         {
           if ( !CKEDITOR.dialog.exists( 'statisticsDialog' ) )
                 CKEDITOR.dialog.add( 'statisticsDialog','/statistics.js');
           // Register the command used to open the dialog.
           editor.addCommand( 'statisticsAddCmd', new CKEDITOR.dialogCommand('statisticsDialog' ) );
           editor.ui.addButton( 'Statistics',
                    {
                        label : 'Statistic',
                        command : 'statisticsAddCmd',
                        icon : '/statistics_small.png',
                    } );
});

The first part will check to make sure that there is not dialog already created with the same name, and if not then load the javascript file that is the custom built dialog. The second part is adding the command (the button clicked) to be linked to the custom dialog, and the third part is to add the actual button to the user interface (editor.ui). The addButton function links to the command to bring up the custom dialog.

Here is the custom dialog code that will be called when the user interface button is clicked.

CKEDITOR.dialog.add( 'statisticsDialog', function( editor )
{
      // Load data asynchronously.
       return {
               title : 'Pick a statistic',
               minWidth : 400,
               minHeight : 200,
               onOk : insertOntoEditor,
               contents : [
                       {
                               id : 'tab1',
                               label : 'First Tab',
                               title : 'First Tab',
                               elements :[
                                       {  id : 'graphselect',
                                               type : 'select',
                                               items : [ ["option1", "link to image"] ] ,
                               }]
                       }
               ]
       };
} );

The dialog, will load up a screen and have a one drop down box that will allow the user to choose from the options (will you need to insert more options, or dynamic created options if you wanted to) and once the OK button is clicked (onOK) it will call this function below

function insertOntoEditor()
{
       elem = this.getContentElement('tab1','graphselect');
       value = elem.getValue();
       if (value != -1)
       {
               var writer = new CKEDITOR.htmlWriter();
               var fragment = CKEDITOR.htmlParser.fragment.fromHtml( '<img src="http://'+document.domain+elem.getValue()+'"/>' );
               fragment.writeHtml( writer )
 
               // need to wrap up the graph image insertion into the ckeditor
               CKEDITOR.instances.Content.insertHtml(writer.getHtml());
       }
}

This will basically insert some code into the CKEditor from the drop down box, the “link to image” you will need to insert a link for the insertion.