Your Ad Here

Fibonacci sequence .....

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

ANSWER WILL BE PUBLISHED ON : 06/07/11

Solution Of Adding Multiple Trouble

ANSWER ==== 233168
#include<iostream>
using namespace std;
int main()
{
long long int old , ne , sum;
sum = 0;
for(int k=0;k<1000;k++)

    if(k%3==0 || k%5==0)
    {  
        sum = sum + k;
    }
}
cout<<sum;

return 0;
}

Adding Multiple Trouble


If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

Solution On --- 5/07/11

10,000 Unique Pageviews Celebration

To All the people , from authors to commentators to just visitors , code-globe community has received a windfall of page-views since its launch in 2009 , adding my page-views of dotnetsnippets.co.cc (old version) the page-views would add upto 15000(approx) .. :).
I have momentarily started working hard for a C++ competition held at Vadodra organized By Computer Society Of India and will be posting C++ challenges in next of my posts .

HTML & Javascript Way2Sms Api.....

This is the thing.... I Have only used html and javascript 2 authenticate the way2sms servers . Actually the whole thing is due to ubaid.tk servers which have been configured by me . you can send the sms from ur website to any mobile . Here is the code enjoy...
<html>
<head>
<title>HTML Sms Api By great 'Vaibhav Maheshwari' </title>
<script type="text/javascript">
function loadIframe(iframeName, url) {
if ( window.frames[iframeName] ) {
window.frames[iframeName].location = url;
return false;
}
return true;
}
</script>
<style type ="text/css">
iframe{
visiblity:hidden;
}
</style>
</head>
<body>
<a href="http://ubaid.tk/sms/sms.aspx?uid=ur_mobile_no&pwd=ur_mobile_password&msg=ur_message&phone=to_whom_u_wannasend_to&provider=way2sms" onclick="return loadIframe('ifrm', this.href)" >Send Sms</a>
</form>
<iframe style="visibility:hidden;" name="ifrm" id="ifrm" style="visiblity:hidden;" frameborder="1">Your browser doesn't support iframes.</iframe>
</body>
</html>
Just Replace the details in this section of your html file. 'uid=ur_mobile_no&pwd=ur_mobile_password&msg=ur_message&phone=to_whom_u_wannasend_to;' . I hope u like the code . Will be posting ...

Create Thumbnail Of A Image C#


There are several situations in website development that deals with images and to display it in Thumbnail sizes. Its really hectic to display the thumbnail images without any distortion and to maintain the quality same as the original image is not also easy. So this article is contributed to those web programmers struggling to create thumbnail images using several logics. This article explains the two ways of creating thumbnail images, which we considered the best.

To upload images to the server, we need a File Upload control and a button control. Asp.Net simplifies the process of uploading images to the server with the FileUpload control. To start with, place a FileUpload control and a button control on your webpage. For readability, change the text of the button control as ‘Upload’.
Method 1:

In this method, we are going to use Size Structure class library. It is a .NET class library structure, stores an ordered pair of integers, normally the width and height of a rectangle. By using this Size Structure we are going to scale the original image, to its appropriate thumbnail size without any disturbances in the quality of the thumbnail image. Size structure class library is available in System.Drawing namespace.

To achieve this, we have a write a general method called ‘NewImageSize’. This method takes 3 parameters such as the original height, original width of the original image and the target thumbnail size you want to resize the original image.
public Size NewImageSize(int OriginalHeight, int OriginalWidth, double FormatSize)
{
Size NewSize;
double tempval;

if (OriginalHeight > FormatSize && OriginalWidth > FormatSize)
{
if (OriginalHeight > OriginalWidth)
tempval = FormatSize / Convert.ToDouble(OriginalHeight);
else
tempval = FormatSize / Convert.ToDouble(OriginalWidth);

NewSize = new Size(Convert.ToInt32(tempval * OriginalWidth), Convert.ToInt32(tempval * OriginalHeight));
}
else
NewSize = new Size(OriginalWidth, OriginalHeight); return NewSize;
}
By passing those parameters, the above method will be proportionately scale the original image and returns the exact size of the thumbnail. We can use this new size to create the thumbnail images and store it in the server.

In the click event of the Upload button, write the following code.
if (FileUpload1.PostedFile != null)
{
string ImageName ="SampleImage.jpg";
FileUpload1.SaveAs(Server.MapPath("Images\\") + ImageName);
string ThumbnailPath = (Server.MapPath("ThumbnailImages\\") + ImageName;

using (System.Drawing.Image Img =
System.Drawing.Image.FromFile(Server.MapPath("Images\\") + ImageName))
{
Size ThumbNailSize = NewImageSize(Img.Height, Img.Width, 150);

using (System.Drawing.Image ImgThnail =
new Bitmap(Img, ThumbNailSize.Width, ThumbNailSize.Height))
{
ImgThnail.Save(ThumbnailPath, Img.RawFormat);
ImgThnail.Dispose();
}
Img.Dispose();
}

Here we take the image path from the FileUpload control and save the original image inside “Images” folder. Then we declare another path to save the thumbnail image.



To know the original height and width of the Original Image, we have to create an Image instance and load it by using the ‘FromFile’ method. Passes the Height and Width to the NewImageSize method along with your desired Thumbnail size in pixel. In the above code, the thumbnail size is 150 pixels height and width.

So the proportionate thumbnail size will be returned to ThumbnailSize Size Structure. Now the Original Image and the size for the thumbnail is ready with us. Last we are going to create another Image object as ImgThnail, which is initialized as a BitMap Image with the Height and Width of the Thumbnail size. Now call the Save method of the ImgThnail object, to store the Thumbnail Image in its appropriate size and location. Finally, call Dispose method, this will release the all the resources used by the Image objects.


Method 2:

The second method is by using the GetThumbnailImage method of the Image class. This method returns the thumbnail image for the given original image. The syntax for this method is


public Image GetThumbnailImage
(
int thumbnail_Width,
int thumbnail_Height,
delegate GetThumbnailImageAbort callback,
IntPtr callbackData
)

The GetThumbnailImage method takes 4 parameters such as the width of the thumbnail, height of the thumbnail image in pixels, an unused delegate and a handle or pointer that must be always Zero. This method retrieves the original image, creates a thumbnail by scaling the original image.

To create thumbnail by this method, first we to have to create a dummy delegate function, which always return false value. The syntax for the delegate function is as follows

public bool ThumbnailCallback()
{
return false;
}


Then in the Upload button’s click event write the following code.

if (FileUpload1.PostedFile != null)
{
string ImageName =”SampleImage.jpg”;
FileUpload1.SaveAs(Server.MapPath("Images\\") + ImageName);

string ThumbnailPath = (Server.MapPath("ThumbnailImages\\") + ImageName;
System.Drawing.Image.GetThumbnailImageAbort myCallback =
new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);

using(System.Drawing.Image TargetImage =
System.Drawing.Image.FromFile(Server.MapPath("Images\\") + FileName))
{
using (System.Drawing.Image Thumbnail =
TargetImage.GetThumbnailImage(100, 200, myCallback, IntPtr.Zero))
{
Thumbnail.Save(Server.MapPath("Images\\") + ImageName);
Thumbnail.Dispose();
}
TargetImage.Dispose();
}
}


By using the FileUpload control’s Save method, we store the original image in the Server. Then we are creating a CallBack delegate by using GetThumbnailImageAbort method. This method provides a callback to the Delegate ThumbnailCallback, when the GetThumbnailImage stops its execution in a premature state. If this happens it will return a true value else it will return always false. Might be it is beyond the scope of this article, we shall leave it here.

Next we are create 2 Image objects such as TargetImage and Thumbnail. The first one TargetImage is to retrieve the original Image and the second Thumbnail is to create Thumbnail Image. Call the GetThumbnailImage method of the Thumbnail object to create a thumbnail image by passing the parameters such as width, height, dummy delegate callback and a handle with Zero value. By calling the Save method of the Thumbnail Image object, we can create thumbnail. Finally we call the Dispose method, to release the resources used by our Image objects.


Point to Remember:

If you look carefully in the above block of codes in both the methods, we are creating the all Image objects within a ‘using’ statement. What does this really do?

The answer is simple. The using statement ensures that Dispose method is called without failure. Eventhough we don’t call Dispose explicitly, it is enough to enclose the statement with the using statement. The purpose of using it here is that we create Image objects and access Images that is stored in the server location. So after using the Images, if do not release it completely than it will create some Exceptions. In other case, if an Exception occurs in intermediate of the Image processing, then the .NET framework cannot release the resources used by the Image object. It will raise an Exception as follows

The process cannot access the file because it is being used by another process.

So when you enclose the Image objects between using statement, then the Images and other files used within the using statement block will be released perfectly even though exception is raised. So we always recommend you to use using statement.


The information provided in this article is only simple methods of creating thumbnail images at run-time or on fly. But there can be other methods, which will create thumbnail with simple technique and excellent quality. So we request our readers to provide them to us, so as to help other novice Asp.Net developers.

Way 2 Sms Api Demo & Source Code

Well many people asked how to implement the Way2Sms Api and Code and hence I provide them the Code.
DEMO :
Instructions : Enter Your Way2Sms Mobile Number , Way2Sms Password , The person you want to send and the Message . Message will be sent from your Way2Sms Account
I Have Used Free Hosting provided to me by applied Innovations . For Quick Sms You can visit my link (without copyrights) Over HERE . Thanking Applied Innovations For providing free Hosting Space .


Source Code :DOWNLOAD IT FROM HERE

Steps To Use It In Your Application :
Step 1 : In Your Default.aspx Page Add This HTML code
<iframe runat="server" style="visibility:hidden;" id="sms" ></iframe>
Step 2: Add a asp:Button in the in your application also add a click event which is going to fired u when u click the button . The Code Is :
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Send Sms" />

Step 3 :Now In the Code-Behind of this file that is Default.aspx.cs we add the event of button . Which loads the Api In the Iframe and the message gets sent . We Are using ubaid.tk servers for better performance .... The Code-behind Code : protected void Button1_Click(object sender, EventArgs e)
{
sms.Attributes.Add("Src", "http://ubaid.tk/sms/sms.aspx?uid=ur_mobile_no&pwd=ur_mobile_password&msg=ur_message&phone=to_whom_u_wannasend_to&provider=way2sms");
}

Download The Code and Enjoy........................... Cheers

Hacking FTP Of Website Part 2

Well this is the second part of my tutorial in which i am going to explain how to use Nikto And Hydra GTK . This is the easy part of tutorial the hard part was installing.

How To Use Nikto ?
Open Terminal and type
nikto -host somewebsite.com

How to use Hydra ?
Use the Ip address given by Nikto as the target Ip instead of website name and all , the rest of the procedure u can get in the video below .
This Video Tutorial shows u how

Hacking FTP of a Website Part 1

Disclaimer :The Following Code is only for Educational purposes

What I am Going to teach ?
Hacking a ftp of a website using Brute-Force Attacking Or Dictionary Attacks. Brute Force Attack means randomly trying all the alphabets as username and Password while dictionary attack means using given list of usernames and passwords.

The Requirements :-
I personally used Ubuntu 10.10 Maverick Meerkat but i will be also explaining that of Lucid Lynx Ubuntu 10.04. Any Of the mentioned OS will Do . In short let me tell you how i am going to hack the FTP. First , I am going to install the Hydra and Xhydra in Ubuntu and then Nikto . Both the tools are used in Ubuntu in order to test the "how strong the ftp password is " but around 30% of the websites could be easily hacked by this method . Many Websites still have no FTP passwords !!

NOTE : I am assuming That you have not modified any of the ubuntu source files and hence won't run into errors . Even If you Do please mention it in the Comment box below.

Installing Nikto

System > Administration > Synaptic Package Manager
Search Nikto in it . And install it on your computer That's pretty simple

Installing Hydra In Ubuntu 10.04

Follow the steps given below to install Hydra 5.7 in Ubuntu Lucid Lynx 10.04

Step 1. Paste the following code in terminal . It installs the required softwares .
sudo apt-get install build-essential linux-headers-$(uname -r) libgtk2.0-dev

Step 2 Download and extract the THC-Hydra tarball
wget -c http://freeworld.thc.org/releases/hydra-5.7-src.tar.gz
tar -xvzf hydra-5.7-src.tar.gz
cd hydra-5.7-src

Step 3 Now you are ready to compile:
./configure
make
sudo makeinstall

Now Close The terminal and press alt + F2 and type xhydra and press enter . A window like the one in image below will open up .

We Have successfully installed the Hydra , HydraGTK(xhydra) and Nikto :) .

Installing Hydra In Ubuntu 10.10

Go Here For How to install Xhydra in Ubuntu 10.10 .

Using Cookies In ASP.NET

Well Cookies are used to store values less than 14 KB . In later tutorial I am going to explain how to make comment box using Cookies , In this tutorial i m gonna tell u about how to Write and Request Cookies .

CODE :
To Write Cookies In Csharp From Code-Behind
Response.Cookies["BackgroundColor"].Value = "Red";

To Request Cookies From another Page
(Request.Cookies["BackgroundColor"].Value);
Will Be Posting Further.....

Play .wav Extension Sound In Asp.Net (Javascript)

How To Play .WAV Sound Files In Asp.NET Using Javascript . The Code is in Html Format .

CODE:

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
<title></title>
<script type="text/javascript">
var soundObject = null;
function PlaySound() {
if (soundObject != null) {
document.body.removeChild(soundObject);
soundObject.removed = true;
soundObject = null;
}
soundObject = document.createElement("embed");
soundObject.setAttribute("src", "sounds/sound.wav");
soundObject.setAttribute("hidden", true);
soundObject.setAttribute("autostart", true);
document.body.appendChild(soundObject);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type = "button" onclick = "PlaySound()" value = "Play Sound" />
</form>
</body>

</html>

Twitter Type Textbox Glow




The Html Code :
<style type="text/css">input[type=text]:focus,input[type=password]:focus,textarea:focus{outline:none;border-color:rgba(82,168,236,.75)!important;box-shadow:0 0 8px rgba(82,168,236,.5);-moz-box-shadow:0 0 8px rgba(82,168,236,.5);-webkit-box-shadow:0 0 8px rgba(82,168,236,.5);}</style>

<input id="txtText" type="text">

Getting X And Y Axis Co-ordinates (Javascript)

DEMO :


Source Code :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function GetScreenCordinates(obj) {
var p = {};
p.x = obj.offsetLeft;
p.y = obj.offsetTop;
while (obj.offsetParent) {
p.x = p.x + obj.offsetParent.offsetLeft;
p.y = p.y + obj.offsetParent.offsetTop;
if (obj == document.getElementsByTagName("body")[0]) {
break;
}
else {
obj = obj.offsetParent;
}
}
return p;
}
</script>
<script type = "text/javascript">
function GetTextboxCordinates() {
var txt = document.getElementById("txtText");
var p = GetScreenCordinates(txt);
alert("X:" + p.x + " Y:" + p.y);
}
</script>
</head>
<body>
<form id="form1">
<input id = "txtText" type = "text" /><br/><br/>
<input value = "Get Coordinates" type = "button" onclick = "GetTextboxCordinates()" />
</form>
</body>
</html>


The above code has been tested in the following browsers
Internet Explorer FireFox Chrome Safari Opera

* All browser logos displayed above are property of their respective owners.

Webparts In Firefox

DOWNLOAD THE CODE OVER HERE It works In Firefox

DEMO :
DEMO By What I think about.net

Default.aspx Code Snippet


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register assembly="Microsoft.Web.Preview" namespace="Microsoft.Web.Preview.UI.Controls.WebParts" tagprefix="dotnetsnippets" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<a href="http://www.dotnetsnippets.co.cc"> <h2>Code Provided By dotnetsnippets.co.cc by Vaibhav Maheshwari</h2>
</a>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<dotnetsnippets:WebPartManager ID="WebPartManager1" runat="server">
</dotnetsnippets:WebPartManager>
<dotnetsnippets:WebPartZone ID="WebPartZone1" runat="server">
<ZoneTemplate>
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
</ZoneTemplate>
</dotnetsnippets:WebPartZone>
<dotnetsnippets:WebPartZone ID="WebPartZone2" runat="server">
</dotnetsnippets:WebPartZone>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>


Default.aspx.cs Code Snippet

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (ApplicationInstance.Context.User.Identity.IsAuthenticated == true)
{
// set the display mode to "Design" to allow drag and drop .This works In Firefox
WebPartDisplayMode mode = WebPartManager1.SupportedDisplayModes["Design"];
if (mode != null)
{
WebPartManager1.DisplayMode = mode;
}
}
}
}
}

DOWNLOAD THE CODE OVER HEREIt works In Firefox

Where is Microsoft.Web.Preview.dll ???

DOWNLOAD IT RIGHT OVER HERE

Well , I was literally crying when i searched for this term on google . It resulted about ajax control Toolkit , ATLAS , Forum link but after half an hour of browsing I did found where it was ?
So I have uploaded it on my Google docs folder and make it available to you .

How 2 Use It and all is described in my next tutorial which shows you how to enable web-parts drag and drop in Mozilla firefox . Unfortunately in Visual Studio 2010 also microsoft has not updated this BUG .

DOWNLOAD IT RIGHT OVER HERE