Check memory and hard drive usage on linux

Here are two very useful commands to see available memory and hard drive space on linux

To see available memory we will use free

  2. # -h give us the output on a format readble for humans :)
  3. $ free -h
  5.              total       used       free     shared    buffers     cached
  6. Mem:          7.8G       3.6G       4.2G         0B       356M       924M
  7. -/+ buffers/cache:       2.3G       5.4G
  8. Swap:          18G         0B        18G

Yo see hard drive usage we will use df

  3. # the same h stands for human readble
  4. $ df -h
  6. Filesystem      Size  Used Avail Use% Mounted on
  7. /dev/sda3       193G   20G  163G  11% /
  8. udev            3.9G  4.0K  3.9G   1% /dev
  9. tmpfs           1.6G  1.1M  1.6G   1% /run
  10. none            5.0M     0  5.0M   0% /run/lock
  11. none            3.9G  1.5M  3.9G   1% /run/shm
  12. none            100M   12K  100M   1% /run/user
  13. cgroup          3.9G     0  3.9G   0% /sys/fs/cgroup

Run on ubuntu 12.10 linux

Thanks to mono we can run on our linux machines (i have to test some code), to do that we will use XSP, here the description took it from mono website.

XSP is a standalone web server written in C# that can be used to run your ASP.NET applications with minimal effort. XSP works under both the Mono and Microsoft runtimes. The code is available from our download page (look for XSP web server) or from the Anonymous SVN repository (module name: xsp).

To nstall it:

  2. #install XSP
  3. sudo apt-get install mono-xsp2
  5. # i have to use so, i installed the Visual Basic.NET Compiler
  6. sudo apt-get install mono-vbnc

Once installed, just start XSP from the directory where your code is located, after that you can browse to http://localhost:8080 to see your web pages

  2. $ cd /home/rene/asp/
  3. $ xsp2
  4. xsp2
  5. Listening on address:
  6. Root directory: /usr/share/asp.net2-demos
  7. Listening on port: 8080 (non-secure)
  8. Hit Return to stop the server.
  9. Application_Start

Crypting data using 3des on c#

Today i have to use c# to crypt some data using 3des, so here is a pretty basic example to do it, i test it using mono.

  2. using System;
  3. using System.Security.Cryptography; // used for TripleDESCryptoServiceProvider
  4. using System.Text; // used for Encoding.ASCII.GetBytes
  6. public class Test
  7. {
  8.         static public void Main ()
  9.         {
  10.                 TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider(); // i create the 3des object
  11.                 byte[] key = Encoding.ASCII.GetBytes("123456781234567812345678"); // the key should be 24 chars long
  12.                 string data = "Here goes the data to encrypt";
  13.                 des.Mode = CipherMode.CBC; // We’ll use CBC
  14.                 des.Key = key; // I set the key
  15.                 byte[] iv = des.IV; // I store the randomly generated IV since i will need for decrypt
  16.                 byte[] inputArray = UTF8Encoding.UTF8.GetBytes(data);
  17.                 ICryptoTransform cTransform = des.CreateEncryptor();
  18.                 byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length);
  19.                 // i will print as readble data
  20.                 Console.WriteLine( (Convert.ToBase64String(resultArray)) );
  21.                 Console.WriteLine( (Convert.ToBase64String(iv)) );
  22.         }
  23. }

Edit less files using Jedit

When you try to edit a less file on jedit, by default there is no color scheme at all, that makes editing css files extremely hard.

To change the way jedit color code the actual file go to “Utilities > Buffer Options” and on “Edit mode” select the color scheme to css.

If you don’t want to do these each time you edit a less file, lets tell jedit to treat *.less files as css files, to do this, “Utilities>Options” and then choose “Editing” on “Change settings for mode” select css, then uncheck “use defaul settings” and chane “File name glob” to “*.{css,less}”.

Block spammers by IP

If your website is being attacked by spammers, you may want to block those users from your website. first thing we will do is to see how many connection by IP we have in our server, we will do this using netstat.

  2. netstat -ntu | awk ‘ $5 ~ /^[0-9]/ {print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n

Once we have the IP address to block, we will use .htaccess to block those ip address like:

  2. order allow,deny
  3. deny from
  4. deny from
  5. deny from
  6. allow from all

Use google docs to embed PDF documents and PowerPoint presentations on your site

If you want to embed a PDF file or a Powerpoint presentation on your site, a pretty easy way to do it, is just go to, introduce the pdf url, click on “Generate Link” and you will get a url to share with your users, where they can see the pdf file on the web or get the html code to embed on your web site

If you want to create the html code on you own is pretty easy just insert an iframe that points to and pass two parameters url= and embed=true and that’s it now you have a pdf embeded on your site

  2. <iframe src="" width="600" height="780" style="border: none;"></iframe>

PHP Cheat Sheet (V2) Creative Commons License (Attribution, Non-Commercial, Share Alike).

Via : Embeddable Google Document Viewer

Google Maps Operation aborted on IE

If you are getting an annoying message like this

“Internet Explorer cannot open the Internet site”
“Operation aborted”

When trying to see a web page that contains a google map.
And right after the message pop ups Internet Explorer shows an empty page here are some tips to help you fixing this issue

First thing you’ll have to do. Is to move all the code used to generate the map to a function and call it once the page is loaded

  2. function loadMap() {
  3.         // JS code to create your map
  4. }
  5. window.onload=function() {
  6.         loadMap();
  7. }

If you are using prototype you can use

  2. document.observe("dom:loaded", loadMap );
  4. OR
  6. Event.observe(window, ‘load’, loadMap, false);

Or you can add an onload attribute to your body tag

  2. <body onload="loadMap()">

If you are using polylines you should add vml namespace to your header and should look like this

  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3.    "">
  4. <html xmlns="" xmlns:v="urn:schemas-microsoft-com:vml">
  5. <style type="text/css">
  6. v\:* {
  7. behavior:url(#default#VML);
  8. }
  9. </style>

Loading the javascript needed to generate the map as an external file , and adding defer attribute so internet explorer will wait until it loads the page before executing the Javascript. It has the same effect than moving your JS code to the bottom of the page.

  2. <script src="maps.js" type="text/javascript"  defer="defer"></script>

It can be also a problem with a base tag messing wiht IE more info on