Ubuntu TidBits

Sometimes we need to download files from a remote host to our local pc through a terminal. SCP is a good tool to do this job. SCP is a secure remote file copy program which copies files between hosts in a network. To use SCP for file downloading allow the following command:

$ scp -P 9999 user@myhost.com:/path/to/file .

The -P tells the port of the host to connect in. As SCP uses SSH to do the copying things so “user@myhost.com” is the username and hostname of the remote host from which we are doing the download. After that we added a colon “:” and next is the path of the file which we want to download. The last dot “.” is the path in the local host where the file will be downloaded. The dot “.” means the current dir where the command is being applied. If you want to download in the /home dir then apply the command like this:

$ scp -P 9999 user@myhost.com:/path/to/file /home

To know more about SCP just see its manual which contains various other important info which may need in several other special cases. To see the manual of scp just type “man scp” in your terminal. Hope this small piece of info will help you.

Tags: ,

Ubuntu: How to check if a script is running or not

Programmers like me who work in shell scripting sometimes they need to know if a script is still running or not. This mainly happens when two script are dependent on each other and the second script cant run until the first script finishes executing. Ubuntu has nice commands line tool using which you can very easily find that if a script is running or not. I will use three commands using pipe. The first command is

$ ps -ef

The ps command shows the snapshot of the currently active process. The param -e shows ALL the processes that is active and -f means that it will show the full format of listing for example it will show the UID, PID, PPID, tty, command, time associated with each process.

The next command is:

$ grep firstscript.sh

Here firstscript.sh is the script that is we are looking for if its running or not. This command simply looks all the running processes for if any process is running from firstscript.sh or not. If it finds any process that matches the script name then it will return the details for the process in the full format as we specified in ps -ef. So apply the commands like

$ ps -ef | grep firstscript.sh

But in the beginning of this post I told about three command, here we have seen two commands so far. What abut the other command. Yes here is the other command. The above piped command return a result no matter the script is running or not. This is because when you applying the above command with grep, it will find a match and return a result for “grep firstscriptl.sh” command it self as it matches a search criteria. So how to be sure that our specified script is running or not. The above command will return a single row of result if it did not find that any process is running with the name firstscript.sh, but will return two rows of result if it finds that script firstscript.sh is running. You may guess by this time why two rows of result and why one. Yes you are right. The command will return two rows of result when it finds the script is running because one row is the actual result and the other row is for the command itself. On the other hand it will return one row of result when the firstscript.sh is not running because then the command only get a match of itself. So it will be problematic to parse the result again and see whether the script is running or not. To do this job we will need the third command which is:

$ grep -v grep

This command tells grep to doesnt include those result that contains the grep command. So our final command will be like this:

$ ps -ef | grep firstscript.sh | grep -v grep

Try this above script. It will only returns row of result when it finds matched script is running. It will return an empty string result when no matches found. So if you need any time to see if any process is running specially need to check if any script is running then you can easily use the above command to get your things done.

Tags: ,

Converting a file from unix mode to windows mode

Unix and Unix based OS’s like linux uses newline “\n” as the line break in a ascii text file where as windows uses carriage return “\r” and newline “\n” as line break. So a file generated on Unix which is also meant to be used in Windows then Linux has a great tool called unix2dos. To use this tool just use the following command:

$ unix2dos /path/to/file

You can add a parameter -p to preserve the access and modification time of the original file like

$ unix2dos -p /path/to/file

If you need the opposite action then you can use dos2unix.

Tags:

Dictionary web service

ObjectGraph has a very nice and simple dictionary implementation. They also have a ajax interface to access it. But they dont have any API for it for third party access. I played with it for sometime and convert it into a web service which is now possible to integrate in any site. If you feel interest then you can check it here.

Tags: , , , ,

BD Weather: My new facebook app

I have written another facebook app. This simple app using Yahoo Weather API and showing Bangladesh’s different cities weather forecast. In this app I also keep the city selection option so that anyone can select his own city. His selected city’s weather forecast will be shown on his profile and also on the app homepage. If you feel interest you can add this app here.

Daily Prayer Timing

I have found a great service at islamicfinder.org. Its daily prayer timing. Now anyone can show the daily prayer timing on his own website. IS just a piece of html code to put on the website. I put here the code for the city Dhaka, Bangladesh.

<iframe

src=”http://www.islamicfinder.org/prayer_service.php?country=bangladesh

&city=dhaka&state=81&zipcode=&latitude=23.7231&longitude=90.4086

&timezone=6&HanfiShafi=1&pmethod=1&fajrTwilight1=10&fajrTwilight2=10

&ishaTwilight=10&ishaInterval=30&dhuhrInterval=1&maghribInterval=1

&dayLight=0&page_background=&table_background=&table_lines=

&text_color=&link_color=&prayerFajr=&prayerSunrise=&prayerDhuhr=

&prayerAsr=&prayerMaghrib=&prayerIsha=&lang=”

frameborder=0 width=175 height=280 marginwidth=0 marginheight=0scrolling=”no”>

</iframe>

You can see it in the action here.

What is this???

9 24947 73800 67013 22247 75838 25476 64051 92535 44010 79958 29902 10309 36080 29565 65805 59610 04761 31215 55730 58464 90245 42650 47654 19020 97669 79058 27672 54479 29026 15806 67487 15669 67166 87781 57814 83854 68287 40682 13904 67694 27809 51774 59820 81094 86314 67725 76296 25700 34225 39582 11451 17842 91740 45553 09456 56656 94021 03759 68977 73451 04671 90634 46067 80985 34559 34820 44157 14816 57162 38608 28858 17169 58496 15443 47147 17468 37130 67595 48487 67748 85808 57871 52804 52544 45185 14554 00990 77754 62950 81187 75475 30309 83715 00921 63396 73550 74023 20792 65361 38198 56821 64290 88393 77520 34003 89763 76817 57525 73830 19258 20025 81510 26027 05890 15776 50741 43699 96094 31568 75063 73190 13957 51137 39703 54348 50125 49547 23327 01638 55657 41076 13665 71062 37313 81467 23947 48016 44140 19101 17652 51658 04943 86331 54249 62629 14669 95839 17451 38490 99874 71792 19924 10890 08377 21531 72208 39399 15256 26033 08218 86493 76486 29057 95218 59625 40238 05015 74916 87847 49595 14067 79716 41442 56177 00893 14434 31033 74926 49945 42376 05488 47535 72035 26522 45033 22204 06079 81403 63983 02277 61020 68141 50686 48044 14240 60444 06283 01398 64769 78379 87206 77957 75093 73326 18306 88079 82986 41139 82175 45839 62020 38076 38912 47662 14024 75684 74970 96215 51877 76519 38293 93829 16289 70249 27861 35251 47577 79950 57624 30296 43554 45908 07280 68740 85602 14543 84040 25497 68674 36610 61273 16136 87598 96159 56528 42717 90118 81855 20030 27876 63574 14244 48193 15465 81365 97545 26948 00024 72273 60759 69740 25941 32640 07957 87636 47625 72106 73953 32727 35323 67734 37482 19929 34353 33570 60205 44225 60727 55269 17620 69944 62858 63033 62376 58179 19922 94687 74606 54079 39081 00678 46811 45451 00140 77359 59030 82174 66081 91617 57146 32510 66116 02434 73929 52411 31428 23141 78142 01482 91477 44880 96088 28685 48764 37625 41174 25032 16172 79213 37680 27111 83068 26615 37800 60583 71192 08568 15305 35668 98368 07610 51991 79393 46318 22097 57424 53436 75856 13835 07837 86370 00208 23013 21031 53921 93901 69044 67224 39733 68770 64579 43679 15843 44429 94727 94609 36250 96255 12982 47823 57845 73105 57062 43933 60651 78915 81461 01769 15741 71556 37896 69760 40534 14369 79289…

m39 = 213,466,917-1

It has 4,053,946 digits in decimal

Its the largest known prime number. Very interesting. Here is the glimpse of that number. To see the full number, please visit http://www.math.utah.edu/~pa/math/largeprime.html

Preloading images using JavaScript

Now a days, website design using images becomes popular trends. As Internet speed increases, designers can now use images for website design more freely and frequently. But if our targeted user base has slow connection, then they may experience a broken site. Images are loaded part by part. Web browsers start to build the output as soon as it start to get the html. So the user may see a broken site as all the design images on that page is not loaded first. To overcome this problem we can use JavaScript. We can use JavaScript to preload the design images for any page at the very first moment of loading the page. We can put the JavaScript code below inside our <head> tag so that the images are started to load as soon as the page started to load. After that we can use the images in normal way. If we put the CSS codes after that, then the page will be built without any broken look.

<script type="text/javascript">
   image01 = new Image();
   image01.src = "http://mywebsite.com/images/1.gif";
   image02 = new Image();
   image02.src = "2.jpg";
</script>

If we have many images for any page, then we can use array to load
images. For example,
<script type=“text/javascript”>
if(document.images)
{
imgPreloader = new Image();
ImageUrl = new Array();
ImageUrl[0] = “http://myweb.com/images/topbar.png”;
ImageUrl[1] = http://myweb.com/images/sidebar.png;
ImageUrl[2] = “images/mainbanner.jpg”;
for(i = 0; i <= count(ImageUrl); i++)
{
imgPreloader.src = ImageUrl[i];
}
}
</script>

This preloading technique can be used for any photo album or gallery where we can preload the
next or previous images of the current image so that the user does not have to wait much
when he see a slideshow or browse images using next/previous links. You can view such
album in Picasa by Google or at facebook. We can use Ajax with this to avoid the page loading in viewing photo albums.

Definition of Web2.0

The good and clear definition of Web2.0 at Wikipedia

Web2.0 Tag Cloud

Web2.0 Tag Cloud

JavaScript : Submit form conditionally

Javascript lets you submit a single form, conditionally, to different script. Here, we’ll learn how to achieve this. First, let us go through a simple form:
<form method=”post” name=”frm1″ onSubmit=”javascript: decide_action();” action=”">
<input type=”radio” name=”ch” value=”one” /> Choice 1<br />
<input type=”radio” name=”ch” value=”two” /> Choice 2<br />
<input type=”radio” name=”ch” value=”three” /> Choice 3<br />
<input type=”submit” name=”s1″ value=”Submit” />
</form>
As you can see, this form displays three radio buttons. The objective is, send the form to a script according to the radio button selected. Since some Javascript action needs to take place once the Submit button is clicked, we invoke decide_action() function through the onSubmit attribute of the <form> tag. Although we include the action attribute, it is left blank. The other form fields are the usual ones. Now let us dive into the cryptic world of the actual script that steers the submission.
<script language=”javascript”>
function decide_action(){
if(check_buttons()==true){
if(document.frm1.ch[0].checked==true){
document.frm1.action=”one.php”;
}else if(document.frm1.ch[1].checked==true){
document.frm1.action=”two.php”;
}else{
document.frm1.action=”three.php”;
}
document.frm1.submit();
}
}

function check_buttons(){
var ok=false;
for(i=0; i<3; i++){
if(document.frm1.ch[i].checked==true){
ok=true;
}
}
if(ok==false){
alert(”Select at least one option.”);
}
return ok;
}
</script>