Google
 

Saturday, September 10, 2011

File upload over web is broken!

XKCD had a nice comic on 'File Transfer' yesterday.


The comic neatly illustrates the woes of transferring files. However this makes one realize another side of the story:

File upload over web is broken!

Have you realized that every browser now has more-or-less functional download manager and features like pause/resume. Even almost all web servers support partial file download, and the feature is exploited by myriads of download accelerators out there.

But how about file uploads? You choose the file, hit the Upload button, and wait! No such thing as progress bars, upload pause/resume and, obviously, upload-accelerators are out of question.

This was okay some years back, when the web was mostly one way business. Not anymore! Nowadays we upload videos, photos and a lot of other large sized files. And how the browsers support the process?




And that's it! Some versions back, there wasn't any such indicator available altogether.

There are workarounds though, like using Flash or Java. Or even better using HTML5. But the whole upload process needs some serious overhauling.

Saturday, September 03, 2011

Weird behaviour while rotating image in C#

I was working on an image processing code in C#. Had to rotate an image by few degrees around a specified point. This can be done either by transformation or matrix method.

private Bitmap rotateImage(Bitmap b, int x, int y, float angle)
{
//create a new empty bitmap to hold rotated image
Bitmap returnBitmap = new Bitmap(b.Width, b.Height);

//make a graphics object from the empty bitmap
Graphics g = Graphics.FromImage(returnBitmap);

Matrix m = new Matrix();
m.RotateAt((float)angle, new PointF(x,y));

g.Transform = m;
g.DrawImage(b, 0, 0);

return returnBitmap;
}

However this wont work properly. It rotates the image, but strangely enough at the same time scales it down too (on larger images).

After some digging into MSDN, found this page, http://msdn.microsoft.com/en-us/library/1bttkazd.aspx, which says:

GDI+ may automatically scale an image as you draw it, which would decrease performance. Alternatively, you can control the scaling of the image by passing the dimensions of the destination rectangle to the DrawImage method.
So to avoid scaling, the above DrawImage line should be changed to

g.DrawImage(b, 0, 0, b.Width, b.Height);

I have no idea why any function would have "automatic" behaviour. But this is how it works. Weird.

Monday, July 11, 2011

Obfuscated awesomeness in C

Recently I've been bumping into obfuscated tiny C codes that does magic. Codes that are couple of lines in length but require pages of explanation on how it works.

There are lots of these in The International Obfuscated C Code Contest page, but here are some of the cool ones I've found in other places. (I'll update this list as I bump into more)

Yahoo! Logo ASCII Animation in six lines of C
20fps, antialiased ASCII art animation of the Yahoo! logo in six lines of C.

Donut animation
Donut animation with, well, donut shaped code. More impressive version here.

Spelt Number to Decimal
Spelt number (like, one, four, etc) in four lines of C

Brainfuck interpreter in 2 lines of C
For those who didnt know Brainfuck is a programming language.

Tuesday, June 14, 2011

NTC PSTN Number to Name

NTC's website has a nice feature called Telephone search. This is particularly handy when you get a call from landline (PSTN) number and have no idea who's calling. Ofcourse you can go to the site and search, but the following bash script makes it faster.

#!/bin/bash

#
# Nepal Telecom PSTN Number to Name search
#

if [ "$1" == "" ] ; then
echo "Usage: " $0 "phone_number"
exit
fi

# Prefix 01, if not provided
if [[ $1 =~ ^01 ]] ; then
NUMBER=$1
else
NUMBER="01$1"
fi

wget -q http://ntc.net.np/telsearchRes.php
--post-data "searchFor=name&telno=$NUMBER&submitted=Search" -O - | html2text | grep "$NUMBER" | tr '_' ' ' | sed 's/ [\ ]*/ /g'

Save the file, chmod it as executable.

To use,
./telsearch 5544132
| 1 |015544132|Ntc |Cellular Mobile And New S|Jawalakhel|

Saturday, May 14, 2011

Fixing overused touchpad with sticky note

If you're like me who spends more time with laptop than anything/one else, you'll end up with touchpad like this:

Due to overuse, the outer coarse layer wears off and touchpad starts acting funny. Plus it's difficult to slide your finger over it.

Fix? Stick a sticky-note over the touchpad. This surprisingly works!