Showing posts with label locally. Show all posts
Showing posts with label locally. Show all posts

Thursday, 18 February 2016

How to Detect Connection Speed With JavaScriptIn Feburary 2016 18,

In Feburary 2016 18,
Open your web page to which you want to add the connection speed detection JavaScript in your text editor.
Add starting and ending script tags in the header area of the web page (after the starting
tag but before the ending
tag), for example:
Add the following code between the starting and ending script tags, replacing \'myimage.jpg\' with the file name of the image you want to use for the speed test. The \'?n=\' + Math.random() part of the address that is built and assigned to imageAddr tricks the web browser into fetching the image every time instead of using a locally cached version. Use an image with a file size of approximately 200 kilobytes.var imageAddr = \'myimage.jpg\' + \'?n=\' + Math.random() ;
Add the following code on the next line of the script to create the variables to store the test's start time, end time and download size. Set \'downloadSize\' to the size of the image file in bytes.var startTime, endTime
GO
var downloadSize = 200000 ;
Add the following code to set up the image that will be downloaded for the test. \'download\' is set up as an Image object. The action to capture the end of the download is assigned to activate when the image download completes. var download = new Image() ;
download.onload = function() {
endTime = (new Date()).getTime() ;
showResults ()
GO
}
Add the following code that runs the speed test. The current time is captured into startTime. The image address being assigned to download.src starts the image download.startTime = (new Date()).getTime() ;
download.src = imageAddr ;
Add the following function to the script that calculates displays the speed test results. First, it calculates the duration, converting milliseconds to seconds. Next, it converts the download size to bits, calculates the download speed, and converts the speed to kbps and Mbps. Finally, it pops up a message box with the results.function showResults () {
var duration = Math.round((endTime - startTime) / 1000) ;
var bitsLoaded = downloadSize * 8
GO
var speedBps = Math.round(bitsLoaded / duration)
GO
var speedKbps = (speedBps / 1024).toFixed(2)
GO
var speedMbps = (speedKbps / 1024).toFixed(2)
GO
alert (\'Your connection speed is: \n\' +
speedBps + \" bps\\n\" +
speedKbps + \" kbps\\n\" +
speedMbps + \" Mbps\\n\")
GO
}
Open the page in your browser, and test it to make sure the script works correctly. It may take a few seconds for the message box to pop up with the test results.
In Feburary 2016 18,

Tuesday, 16 February 2016

How to Convert Epoch Time in C++In Feburary 2016 16,

In Feburary 2016 16,
Include the C++ standard library's time functionality into your application. Add the following line to the top of your include list:include
Obtain the seconds elapsed since the epoch, and store it locally. Do this by calling time(), and storing the result into an object of type time_t. The time function also accepts a pointer to an object of type time_t as an argument, but it is simpler to store this object locally on the stack:time_t timeSinceEpoch = time(NULL);
Create a time structure to store the result of the time conversion. This structure is defined in the time.h header file as a structure named tm, and provides conveniently-named member variables for each component of the converted time:tm timeResult;
Use one of the built-in conversion functions to store the time_t value obtained earlier as a tm structure. For simplicity, the following code converts a time_t object into a UTC tm structure:timeResult = gmtime( &timeSinceEpoch );
In Feburary 2016 16,