Server Load for android 2.1

Server load is open source widgets for android that retrieve your current server average load and display it on a widget on your android home screen, you can add more widgets for each server. The widget will update every 30 min to display your server’s current average load. Check the php example for extracting your servers’ current load.

Program test on Galaxy s2

Download
Source Code

Get from Android Market

php file ex:

  1.  
  2. <?php
  3. $load = getServerLoad();
  4.  
  5. if( $load !== NULL ){
  6.     $load = explode(‘ ‘, $load[‘load’]);
  7.     echo $load[0];
  8. }
  9.  
  10. function getServerLoad(){
  11.     $os=strtolower(PHP_OS);
  12.     if(strpos($os, ‘win’) === false){
  13.         if(file_exists(‘/proc/loadavg’)){
  14.             $load = file_get_contents(‘/proc/loadavg’);
  15.             $load = explode(‘ ‘, $load, 1);
  16.             $load = $load[0];
  17.         }elseif(function_exists(‘shell_exec’)){
  18.             $load = explode(‘ ‘, `uptime`);
  19.             $load = $load[count($load)-1];
  20.         }else{
  21.             return NULL;
  22.         }
  23.  
  24.         if(function_exists(‘shell_exec’))
  25.             $cpu_count = shell_exec(‘cat /proc/cpuinfo | grep processor | wc -l’);        
  26.  
  27.         return array(‘load’=>$load, ‘procs’=>$cpu_count);
  28.     }else{
  29.         if(class_exists(‘COM’)){
  30.             $wmi=new COM(‘WinMgmts:\\\\.’);
  31.             $cpus=$wmi->InstancesOf(‘Win32_Processor’);
  32.             $load=0;
  33.             $cpu_count=0;
  34.             if(version_compare(’4.50.0′, PHP_VERSION) == 1){
  35.                 while($cpu = $cpus->Next()){
  36.                     $load += $cpu->LoadPercentage;
  37.                     $cpu_count++;
  38.                 }
  39.             }else{
  40.                 foreach($cpus as $cpu){
  41.                     $load += $cpu->LoadPercentage;
  42.                     $cpu_count++;
  43.                 }
  44.             }
  45.             return array(‘load’=>$load, ‘procs’=>$cpu_count);
  46.         }
  47.         return NULL;
  48.     }
  49.     return NULL;
  50. }
  51.  
  52. ?>
  53.  
  54.  
  55.  

ScreenShots :





Firefox chrome function : Read/write file on disk

tested on Firefox 7.0.1

  1.  
  2. const Ci = Components.interfaces;  
  3. const Cc = Components.classes;
  4.  
  5. function ReadWrite( data ){
  6.    
  7.                 try{
  8.                             Components.utils.import("resource://gre/modules/NetUtil.jsm");
  9.                             Components.utils.import("resource://gre/modules/FileUtils.jsm");
  10.  
  11.                             var file = FileUtils.getFile("ProfD", ["FileName.txt"]);
  12.                             var ostream = FileUtils.openSafeFileOutputStream(file );
  13.                             var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
  14.                                                      createInstance(Ci.nsIScriptableUnicodeConverter);
  15.  
  16.                             if( data ){
  17.                            
  18.                                     if ( !file.exists() ){
  19.                                             file.create( Ci.nsIFile.NORMAL_FILE_TYPE, 420);
  20.                                     }
  21.                                     converter.charset = "UTF-8";
  22.                                     var istream = converter.convertToInputStream(data);
  23.                                     NetUtil.asyncCopy(istream , ostream, function(status) {
  24.                                                     if (!Components.isSuccessCode(status)) {
  25.                                                             alert( "Error! :" + status );
  26.                                                             return false;
  27.                                                      }
  28.                                     });
  29.                                                                        
  30.                            }else{
  31.                                     var data = ;
  32.                                     var fstream = Cc["@mozilla.org/network/file-input-stream;1"].
  33.                                                   createInstance(Ci.nsIFileInputStream);
  34.                                     var cstream = Cc["@mozilla.org/intl/converter-input-stream;1"].
  35.                                                   createInstance(Ci.nsIConverterInputStream);
  36.                                     fstream.init(file, -1, 0, 0);
  37.                                     cstream.init(fstream, "UTF-8", 0, 0); // you can use another encoding here if you wish
  38.  
  39.                                     let (str = {}) {
  40.                                           let read = 0;
  41.                                           do {
  42.                                                 read = cstream.readString(0xffffffff, str); // read as much as we can and put it in str.value
  43.                                                 data += str.value;
  44.                                           } while (read != 0);
  45.                                     }
  46.                                     cstream.close(); // this closes fstream
  47.                                     return data;
  48.  
  49.                                }
  50.  
  51.         }catch(e){
  52. //                          alert( e);
  53.                             return false;
  54.         }
  55.     }
  56.  

Ban IP from logging in for 5 minutes after 10 failed logins

  1.  
  2.  
  3. if( login_limit() )
  4.    die( ‘Your IP has been banned from logging in for the next 5 minutes’ );
  5.  
  6.  
  7.  
  8. /*
  9.  * Counts login times by same IP
  10.  * returns true if limit reached or false if not
  11.  */
  12. function login_limit(){
  13.     //get real IP if user behind proxy noted by Sebastian Enger
  14.     $ip = isset($_SERVER[‘HTTP_X_FORWARDED_FOR’]) ? $_SERVER[‘HTTP_X_FORWARDED_FOR’] : $_SERVER[‘REMOTE_ADDR’];
  15.    
  16.     //user still banned from login
  17.     if( _cache( $ip . ‘banned’ ) )
  18.         return true;
  19.  
  20.     //number of seconds
  21.     $sec = 30;
  22.     //find ip info array in cache saved less than $sec ago
  23.     if( ($ip_info=_cache( $ip ))  && $ip_info[0] > time()-$sec ){
  24.        
  25.         //user login 10 times during last $sec
  26.         if(  $ip_info[1] > 10 ){
  27.             //ban user ip for the next 5 minutes
  28.             _cache( $ip . ‘banned’, 1, 0, 60*5 );
  29.             _cache( $ip, -1 );
  30.             return true;
  31.         }
  32.         //increase login retries +1
  33.         _cache( $ip, array(  $ip_info[0],   ++$ip_info[1] ), 0, $sec );
  34.         return false;
  35.        
  36.     }
  37.        
  38.     //add ip info to cache
  39.     _cache( $ip, array( time(), 1 ), 0, $sec );
  40.     return false;
  41. }
  42.  
  43. function _cache( $name, $val=NULL, $ttl=false ){
  44.         //memcached
  45.         global $mcdb;
  46.         if(empty($mcdb) )
  47.                 $mcdb = memcache_connect(‘unix:///etc/sockets/memcached.sock’, 0);
  48.        
  49.         if($val === -1){
  50.                 return memcache_delete($mcdb,$name);
  51.         }elseif( $val !== NULL ){
  52.                 return memcache_set($mcdb,$name,$val, false, $ttl);
  53.         }else{
  54.                 $retval = memcache_get($mcdb,$name);
  55.                 return  $retval ? $retval : NULL;
  56.         }
  57.  
  58. }
  59.  
  60.  

Support Egypt Revolution

Show your support for the Egyptian revolution by adding this code to your website and blog

  1. <img border="0" id="corner-ad" src="http://gadelkareem.com/tmp/jan25.jpg&quot; width="222" height="111" /> <style>#corner-ad {
  2.     display: block;  
  3.     width: 222px;  
  4.     height: 111px;  
  5.     position: fixed;  
  6.     top: -16px;  
  7.     right: -70px;  
  8.     -webkit-transform: rotate(45deg);  
  9.     -moz-transform: rotate(45deg);  
  10.     -o-transform: rotate(45deg);  
  11. }
  12.     top: -80px\9;  
  13.     right: -70px\9;  
  14.     *right: -70px;  
  15.     filter:  progid:DXImageTransform.Microsoft.Matrix(sizingMethod=’auto expand’, M11=0.7071067811865476, M12=-0.7071067811865475, M21=0.7071067811865475, M22=0.7071067811865476);  
  16.     -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(SizingMethod=’auto expand’, M11=0.7071067811865476, M12=-0.7071067811865475, M21=0.7071067811865475, M22=0.7071067811865476)";  
  17.     zoom: 1;  
  18. }
  19. </style>
  20.  

A Demo of this code can be seen on the top right of this page

Convert vBulletin DB encoding to UTF-8

great help @ http://mansurovs.com/tech/converting-vbulletin-to-utf-8

these are the exact commands that worked for me
#more-58" class="more-link"> more.. »

jQuery plugin : monnaTip 0.1

This the simplest tooltip jQuery plugin you can find around.

    features:

  • takes advantage of live(), mouseenter and mouseleave methods
  • tracks mouse movement
  • right and bottom viewport border tracking
  • can be applied on any element

DemodownloadGoogle code
#more-57" class="more-link"> more.. »

use name attribute for input instead of id for use with label

you need Jquery:

  1.  
  2. <label for="myinput"></label><input name="myinput" type="text" value="text here" />
  3. $(‘label’).live(‘click’, function(e){
  4.         if( $(e.target).is(‘:input’) ) return;
  5.         var i = $(‘:input[name="' + $(this).attr('for') + '"]‘)
  6.         i.is(‘:checkbox’) ? i.attr(‘checked’, !i.attr(‘checked’) ) : i.focus().select();
  7.     })
  8.  

Convert html to vbcode and post to vbulletin

using vbulletin files :

  1.  
  2. chdir(‘/path/to/forum’);
  3. define(‘THIS_SCRIPT’, ‘login’);
  4. require_once( ‘./global.php’);
  5. require_once( DIR . ‘/includes/functions_wysiwyg.php’ );
  6.  
  7. echo convert_wysiwyg_html_to_bbcode(‘<i>hello world</i>’);
  8.  

using external function :
#more-55" class="more-link"> more.. »

Sitemap Creator 0.2 beta

Sitemap Creator crawls/spiders your website creating XML sitemaps compatible with the standard sitemaps.org protocol supported by Google, Yahoo!, MSN and MoreOver. The script pings Google, Yahoo!, MSN and MoreOver bots to download the sitemap file, then tracks the bot and sends you an email on every scan to your Sitemap and gives you a full report of the Search Engine respond.
Sitemaps are created from a CSV file which could easily be edited using any text editor before creating the sitemap. #more-53" class="more-link"> more.. »

Configure sendmail to accept emails only if “from”, “to” or specific field matches

you can exclude an email address or even a host that is spamming you using the access file located in your etc directory, the bad news is that it does not support regex or even wildcards. #more-52" class="more-link"> more.. »

Remotley start programs on your Linux Desktop

It is very easy to start programs remotely on your windows desktop from another computer but running X11 application on Linux from another ssh session would start a new X11 session on your remote machine, that was a problem for me and here is how I solved that….. #more-51" class="more-link"> more.. »

Sort Unix processes on ps by highest memory usage

just a snippet, –sort is not good for me..try
ps -eo pmem,pcpu,rss,vsize,args | sort -k 1 -r | more
#more-50" class="more-link"> more.. »

Sitemap Creator 0.2a: Create sitemaps 09 valid for Google, Yahoo, MSN, Ask.com and moreover sitemaps

New Sitemap Creator Beta available
Sitemap Creator 0.2a is different from version 0.1, The script now is able to crawl/spider your website, create your sitemaps, ping Google, Yahoo, MSN, Ask.com, moreover.com with the location of your sitemaps and send you alerts by email when sitemaps are created or crawled by the search bot. The crawler saves sitemaps data into an easy to edit CSV file.

Download (build 20070109) :
sitemap_creator.tar.gzsitemap_creator.zip
#more-49" class="more-link"> more.. »

Adding FAlbum URLs to XML-Sitemap WordPress Plugin

As I mentioned on my previous post yesterday about Fixing FAlbum Plugin that I’m trying to add support for Google XML Sitemaps Plugin to FAlbum so that all URLs including albums, photos and tags would be added to Blog’s Sitemap which would be crawled by Google, Yahoo and MSN . #more-48" class="more-link"> more.. »

Fixing Flickr FAlbum rewrite rules, thumbnails, javascripts and more …

This is not working anymore

FAlbum is a WordPress Plug-in that adds your Flickr photo albums to your blog without redirecting the viewer to Flickr or leaving your blog. It is very useful and unique, I have always needed that plugin on my blog, however, some features needed a lot of digging into the code to fix or to get it working. So, I am going to describe a step by step installation of this plugin then will show how to fix. #more-47" class="more-link"> more.. »

BPEL4WS Series

Process Modeling

Abstract

In this article, we will walk through modeling a sample process using the Business Process Execution Language for Web Services. This article uses Sybase PowerDesigner as the modeling tool and J2EE 1.4 as the programming and deployment platform. The article assumes basic knowledge of BPEL4WS, UML, WSDL and J2EE technologies.

#more-46" class="more-link"> more.. »

GoodBye IE6..please don’t come back!

Since IE6 was released it has been a pain for every designer, the browser has its own world leaving behind web standards, forcing designers to add hacks, extra code and scripts just to fix its stupid bugs, bugs and more Bugs. #more-44" class="more-link"> more.. »

Dynamic Content Caching using Lighty + mod_magnet + lua

*Updated 11 Jan 2007 to include luazlib, fix lighty config file and add zlib decoding to cache.lua for older browsers
Since I read the documentations for mod_cml, I was very excited to use this module since caching using PHP running as FastCGI is not helping much during server peak load. However, mod_cml was replaced by mod_magnet which is more flexible and gives more control over request handling in Lighttpd. This Article will focus on caching your PHP scripts using Lua and mod_magnet under Lighttpd, #more-42" class="more-link"> more.. »

Compressing your HTML, CSS and Javascript using simple PHP Code

Although Compression is a very important method of making your pages lighter and easier for users to download, it’s definitely going to cost you more CPU and on high load servers it’s not recommended unless you already know how to cache your HTML pages. #more-41" class="more-link"> more.. »

Google rank is the 14th on “search” query while Live is the 1st

is it a googlebot failure? or Google is not into SEO ?
check : http://www.google.com/search?q=search #more-40" class="more-link"> more.. »


 Top