rm: argument list too long!

Posted: 21st January 2011 by shadyvb in Linux, tips

This morning i found out my server is down because the space was exceeded.. so i went to clear up some cache/backup files to free up some space.
At first, my tries to ssh the server failed, i guess the server was REALLY crowded that i didn’t hear my call, anyway, using the Plesk ‘Repair mode’ option, i successfully removed one large backup file, and restarted the server..

Anyway, what i’m writing about is that RM seem to have some limitation if you told it to remove a big list of files:
I used:
rm *.cache
and it gave the following message:
-bash: //bin/rm: Argument list too long

After stumbling alittle, i found this article :

http://www.moundalexis.com/archives/000035.php

and it solves that problem uses:
find . -name '*.cache' | xargs rm

hope this helps anybody stuck in my situation!

Fix serialized array errors

Posted: 10th January 2011 by shadyvb in php, wordpress
Tags: , , , ,

After spending 3 painful hours fixing options of cForms plugin for WP, after migration to live site, i’ve discovered this bit of code at php.net, which helped me fix the options array and get my forms back online.


$serialized = preg_replace_callback(
'!(?<=^|;)s:(\d+)(?=:"(.*?)";(?:}|a:|s:|b:|i:|o:|N;))!s',
create_function('$a', 'return "s:" . strlen($a[2]);'),
$serialized
);

Note: You might wanna add slashes for single quotes, if your string have some.

Browsing the VMWare docs, I’ve been able to find a better way to start VMWare machine automatically via FireDaemon ( Check the first post ).

The new and better way removes the nag screen of “Interactive Services message”, which is pretty anonying, at least to me.

To use the new built-in command-line tool, change the command lines in the Executable and Parameters fields as follows :


Executable : C:\Program files\VMWare\VMWare Workstation\vmrun.exe
Parameters : start "D:\path\to\virtual\machine\Ubuntu.vmx"

You can see that in the following screen :

Autostart VMWare using Firedaemon, Updated

Note: Change Parameters field to put the correct path to your machine’s VMX file, and perhaps you would need to change the Executable fields as well if you’ve a custom path for your VMWare Workstation installation.

I’ve been searching – for a good amount of time – for a way to send unicode message using Clickatell API’s .. i didn’t find any solution, though i found a lot people searching just like me for the same solution.

After a lot of searches, trails and testing .. I’ve found a solution posted by [ tried to find the source but couldn't remember ] that does some unicode conversion functions, from which i could find what i want.

I extracted the peace of code i needed, minified it, and here it is:

function d2h(a){return(a+0).toString(16).toUpperCase()}function str2cp(a){var c=0;var n=0;var d='';var e=false;for(var i=0;i0xFFFF){return false}if(c!=0){if(0xDC00<=b&&b<=0xDFFF){if(e){d+=' '}d+=d2h(0x10000+((c-0xD800)<<10)+(b-0xDC00));c=0;continue;e=true}else{return false}}if(0xD800<=b&&b<=0xDBFF){c=b}else{if(e){d+=''}cp=d2h(b);while(cp.length<4){cp='0'+cp}d+=cp;e=true}}return d}

You can download the file here unicode_cp.js [ Size : 430 Byte ]

Instructions :

1- Include the script into your page containing the form


2- Create a textarea as the message text , it’s better that it doesn’t have a ‘name’ attribute, so it won’t be submitted, it’s contents will be converted to code points and saved in a hidden input which will be actually submitted with the form.



3- Hook the encoding function to keypress event of the textarea#txt

window.onload= function() {
txtBefore= document.getElementById("txt");
txtEncoded= document.getElementById("encoded");
txtBefore.onkeypress= function(e){
// Allow only backspace [ delete ] button when character count is over 70
if (this.value.length>=70) {
if(e.charCode!=0){
return false;
}
}
};
txtBefore.onkeyup= function(e) {
txtEncoded.value= str2cp(txtBefore.value);
};
};

You can also create a checkbox to enable\disable conversion, in case the user wants to send the message in plain English, hence increasing the message limit, to do that add the following as the first line of onkeypress function :

if(uni_check.checked) return false;

and the following as the first line of onkeyup function :

if(uni_check.checked) { txtEncoded.value = txtBefore.value; return; }

you’d need to declare uni_check in your script like that :

 uni_check = document.getElementById('uni_check'); 

And this way you can submit your forms easily, and send all the SMS you want without no hassle, and with front-end conversion.

PHP Function to read folder contents recursively into a multidimensional array like a tree.

I’ve always longed to have a subdomain like myhomeserver.gr80.net to point at my home server ( obviously! ) .. but there is always fees for such services, like No-IP and DynDNS Pro ..

I figured out an easy way to have your own sub domain, pointing at your home server ( assuming you have a dynamic IP connection, or you wouldn’t need this tutorial ) ..

Requirements :

1- Free DynDNS Account
2- Domain Name, ( Domain Control Panel must allow you to create sub domains as CNAME entries, which is available on NetFirms )

Steps:

A) Configure your dummy free sub domain:

1- Create a Free account on DynDNS.org
2- After logging in, Choose “Add Host Services” , Add your desired sub domain ( which doesn’t really matter, it’ll be overridden eventually ) , activate the sub domain ..

Follow the screenshots here :
View ScreenshotView ScreenshotView ScreenshotView ScreenshotView Screenshot

B) Configure your Domain on Netfirms ( or whatever your registrar is )

1- After Logging to your panel, Choose “Add”
2- Add the desired sub domain ex: myhomeserver.mydomain.com
3- Choose CNAME type, and add your DynDNS Free sub domain .

Follow the screenshots here :
View ScreenshotView Screenshot

C) Configure your router \ software to use the created DynDNS

1- You can find a tab in your router setup called ( Dynamic DNS \ DDNS \ DynDNS ) .. where you should enter your account credentials on DynDNS.org ( the account you just created ).
Or if you do not have a DDNS-enabled router, you can always go with software like DirectUpdate , it’s the best one i’ve tried, always fulfilling my needs..

Voila! you now have a fully working FREE Dynamic DNS service on your own domain! Enjoy!


I’ve been around searching for a good tool to check share-sites files if they’re still alive or dead..

During my check, I’ve stumbled upon RS’s own link checker at http://rapidshare.com/checkfiles.html .. found that they’re using a simple API provided from RS ..

I’ve used their API before for uploading stuff from my linux machine, the whole API provided by RS was a tiny Perl script used to upload files and keep the logs saved.. it just did the job then..

But now, they’ve expanded their API to good extents .. Now you can do a lot of things using simple API calls to their website.

Anyway, back to my main target, which is a link checker for Rapidshare files..

I’ve created this small function to help me check files the easy way, for i’ll be integrating it in WordPress at a friends website soon ..

Here you are the function :

function rs_check($url){
	if (!$url) return false;
	$files_pattern= '/\/files\/([^\/]*)\//';
	$filename_pattern= '/\/files\/.*\/(.*)/';
	preg_match($files_pattern, $url, $matches_id);
	preg_match($filename_pattern, $url, $matches_name);
	$res= file_get_contents("http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=checkfiles_v1&files={$matches_id[1]}&filenames={$matches_name[1]}");
	list($fId,$fName,$fSize,$fServerId,$fStatus,$fShortHost,$fmd5) =explode(',',$res);
	return ($fStatus==1 || $fStatus==2);
}

and you can simply call the function using the following example :

if(rs_check($url)){
 echo 'This is a valid working link!';
}else{
 echo 'This is not a valid link anymore!';
}

I’ll be enhancing this with a Javascript JSON Server API .. but i guess I’ll enjoy my vacation first! ;)

You can preview my link checker from this demo Rapidshare Link Checker Demo, and the file is available for download and including from here Rapidshare Link Checker API .

Does anyone know about APIs of similar websites that can be used the same way ?

Sewing a lot of intranet applications at the NGO, i found it a must to work around electricity blackouts .. and there is a plenty down there ..

So, i managed to get the server starting-up when electricity is back .. using a BIOS setting that lies there in almost all the modern Motherboards nowadays..

But came to the bigger problem, running the machine on windows start ..

This could be easy if you’re the only user of your machine, with no password, having the automatic log-on in effect .. but if you are on a server where you have to enter a password to log-on , this would be kinda clingy ..

Googling alittle, i found a utility which can be used to run windows application as services , and set to start on windows boot rather user log-on .. It’s called FireDaemon [ Download it HERE, or Google it ] ..

I started installing Firedaemon .. opened the GUI afterwords, it looks like this :
1

Then i began creating a new service, specifying VMWare main executable ( vmware.exe ) as the server application, and ( -x “Drive:\Path\to\VM\machine.vmx” ) as the parameter, as you can see in the picture :
3

Voila! Close FireDaemon, and restart your computer to make sure everything is OK.

UPDATE on 18/02/2010 : Use the internal built-in tool vmrun.exe to achieve better results, and to remove the nagging screen of Interactive Services message. Check out the updated post.

Long I’ve searched for a method to center elements vertically using CSS or even deprecated HTML codes.. but never found a proper way to do it ..

Now i figured an incredibly easy way to do it using Javascript, with my beloved jQuery..

You only have to assign one CSS value to the box you want to center:

.centeredBox{ position: absolute }

After including jQuery from Google Code ( or from your own local folder if you like ) :

Use the following function to center the elements:

function setPosition(){
	var tasks=$('#tasks');
	var h=$(document).height(), th= tasks.height();
	tasks.css("top", (h-th>0?((h/2)-(th/2))+'px':0) );
	var w=$(document).width(), tw= tasks.width();
	tasks.css("left", (w-tw>0?((w/2)-(tw/2))+'px':0) );
};

As a final step, you would need to add the following lines in your js file , so it applies the center hack each time you resize your window :

window.onload=function(){setPosition()};
window.onresize=function(){setPosition()};

And you’re now set to enjoy the final.

Final HTML markup:









Here I am - this is me There's no where else on earth I'd rather be Here I am - it's just me and you And tonight we make our dreams come true

See the demo here : Centered Box

Inspired by the Flash Menu at ADATA‘s website ( Memory manufacturing firm ) , i tried to simulate the effect using jQuery.

First i had a menu in HTML :


then applying some styling to make it a horizontal menu that go at the top of the page :


after integrating latest version of jQuery hosted at Google Code using the following code :

i added the following markup to create the targeted effect:
UPDATE: Now using stop() to prevent repetitive animation, Thanks Allan for your notice.


first line is to make sure child div’s are positioned just under their main link , then second line makes the hover effect by invoking the animate function to control both opacity and left property of the child div.

You can check the example here: Fading Sliding Menu.