Category Archives: Uncategorized

Uploading file in iOS

Multipart form data and HTTP (body content) are most popular ways to upload files. In iOS, using AFNetworking 2.0, it is very easy to manage. Let’s jump:

1) Using multipart form data to form request:

    NSString *path = [[NSBundle mainBundle] pathForResource:@"MyFileToUpload" ofType:@"jpg"];
    
    NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"http://harit.kotharee.com/uploadMyImageMultipart.php" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
    {
        [formData appendPartWithFileURL:[NSURL fileURLWithPath:path] name:@"file" fileName:@"MyFileToUpload.jpg" mimeType:@"image/jpeg" error:nil];
    } error:nil];

2) Using HTTP POST to form request – here in this case A JSON request

    NSString *fileName = @"MyFileToUpload.jpg";
    UIImage *newImage = [UIImage imageNamed:fileName];
    NSData *data = UIImageJPEGRepresentation (newImage, 1.0f);
    
    NSString *strEncoded;
    if ([data respondsToSelector:@selector(base64EncodedStringWithOptions:)])
    {
        strEncoded = [data base64EncodedStringWithOptions:kNilOptions];  // iOS 7+
    }
    else
    {
        strEncoded = [data base64Encoding];        // pre iOS7
    }
    
    // have your own JSON or other format of request
    NSString *jsonRequest = [[NSString alloc] initWithFormat:@"{\"FileName\":\"%@\",\"ImageContent\":\"%@\"}", fileName, strEncoded];
    
    NSURL *url = [NSURL URLWithString:@"http://harit.kotharee.com/uploadMyImageHTTPbody"];
    
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
    NSInputStream *imageStream = [[NSInputStream alloc] initWithData:[jsonRequest dataUsingEncoding:NSUTF8StringEncoding]];
    
    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    // This is key part, instead of appending NSData, use stream when you expect the data to be larger
    [request setHTTPBodyStream:imageStream];

That’s pretty much done. Rest is simple and common for both ways:

    // handling operation response
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
    {
        NSLog(@"Cool! Let's proceed!");
    }
    failure:^(AFHTTPRequestOperation *operation, NSError *error)
    {
        NSLog(@"Oops! Handle gracefully!");
    }];
    
    [operation start];

In case of multipart request, we need to pass absolute URL of file. Of course, we can get it for bundle as well as camera roll. The deal with multipart request is that actual content of file is not loaded on iOS as data objects at runtime. Rather, HTTP (protocol) handles the it (add breakpoint at line #5 in [1] and debug!), so is a nice and probably best way to use for large size data, without worrying about memory issues.

Cast your vote or don’t, if you wish so but know rule 49-0 well

There is a fake email spreading over Internet which is misleading. I had been victim of this email quiet a long time back, and I believed!

Today I come to know about the fact.

Rule 49-0 does not cancel or reschedule polling evenif I don’t wish to go for or against any party.

Copy of an email misleading the facts:

Did you know that there is a system in our constitution, as per the 1969 act, in section “49-O” that a person can go to the polling booth, confirm his identity, get his finger marked and convey the presiding election officer that he doesn’t want to vote anyone!

Yes such a feature is available, but obviously these seemingly notorious leaders have never disclosed it. This is called “49-O”.

Why should you go and say “I VOTE NOBODY”… because, in a ward, if a candidate wins, say by 123 votes, and that particular ward has received “49-O” votes more than 123, then that polling will be cancelled and will have to be re-polled. Not only that, but the candidature of the contestants will be removed and they cannot contest the re-polling, since people had already expressed their decision on them. This would bring fear into parties and hence look for genuine candidates for their parties for election. This would change the way, of our whole political system… it is seemingly surprising why the election commission has not revealed such a feature to the public….

Please spread this news to as many as you know… Seems to be a wonderful weapon against corrupt parties in India… show your power, expressing your desire not to vote for anybody, is even more powerful than voting… so don’t miss your chance. So either vote, or vote not to vote (vote 49-O) and pass this info on…

Copy of an email clearing the facts:

This is a hoax that has been floated by an irresponsible dimwit by mails and pasted as-is by an irresponsible blogger.

Every one knows that Indian Constitution does not mention about any Section, but only Articles. In Indian Constitution there is no Sec. 49-0, leave alone Article 49-0. Article 49 of the Constitution of India deals with protection of historical monuments. The news further states that it is as per the 1969 Act. Which is the so called 1969 Act?

The fact is as follows:

Section 49-O is a section coming under the Conduct of Election Rules, 1961. It has nothing to do with the Constitution of India. It reads as follows:

“49-O: Elector deciding not to vote. – If an elector, after his electoral roll number has been duly entered in the register of voters in Form-17A and has put his signature or thumb impression thereon as required under sub-rule (1) of rule 49-L, decided not to record his vote, a remark to this effect shall be made against the said entry in Form 17A by the presiding officer and the signature or thumb impression of the elector shall be obtained against such remark.”

This is only a provision for abstaining from voting or at the best negative voting. It does not provide for cancellation of polling if the 49-0 votes are more than the candidate’s majority or provide that the candidature of the contestants will be removed and they cannot contest the re-polling, since people had already expressed their decision on them.

In fact in the PROPOSED ELECTORAL REFORMS by the Election Commission of India, which was forwarded to the Prime Minister of India on 05/07/2004, the following reform was proposed;

“7. NEGATIVE / NEUTRAL VOTING

The Commission has received proposals from a very large number of individuals and organizations that there should be a provision enabling a voter to reject all the candidates in the constituency if he does not find them suitable. In the voting using the conventional ballot paper and ballot boxes, an elector can drop the ballot paper without marking his vote against any of the candidates, if he chooses so. However, in the voting using the Electronic Voting Machines, such a facility is not available to the voter. Although, Rule 49 O of the Conduct of Election Rules, 1961 provides that an elector may refuse to vote after he has been identified and necessary entries made in the Register of Electors and the marked copy of the electoral roll, the secrecy of voting is not protected here inasmuch as the polling officials and the polling agents in the polling station get to know about the decision of such a voter.

The Commission recommends that the law should be amended to specifically provide for negative / neutral voting. For this purpose, Rules 22 and 49B of the Conduct of Election Rules, 1961 may be suitably amended adding a proviso that in the ballot paper and the particulars on the ballot unit, in the column relating to names of candidates, after the entry relating to the last candidate, there shall be a column .None of the above., to enable a voter to reject all the candidates, if he chooses so. Such a proposal was earlier made by the Commission in 2001 (vide letter dated 10.12.2001).

(A petition by the People’s Union for Civil Liberties seeking such a provision filed at the time of the recent general elections is pending before the Hon’ble Supreme Court)”

This is the actual fact. Please do not spread messages without verifying the authenticity

So, it’s true that major (18+) Indians can vote for none, but it doesn’t mean voting will be cancelled if similar counter is larger!

Here is a news item published

References:

  1. Election Commission of India Press Note
  2. The Conduct of Elections Rules, 1961
  3. 49-O on Wikipedia

Inspiration

As I was passing the elephants, I suddenly stopped, confused by the fact that these huge creatures were being held by only a small rope tied to their front leg. No chains, no cages. It was obvious that the elephants could, at anytime, break away from their bonds but for some reason, they did not.

I saw a trainer near by and asked why these beautiful, magnificent animals just stood there and made no attempt to get away. “Well,” he said, “when they are very young and much smaller we use the same size rope to tie them and, at that age, it’s enough to hold them. As they grow up, they are conditioned to believe they cannot break away.

They believe the rope can still hold them, so they never try to break free.” I was amazed. These animals could at any time break free from their bonds but because they believed they couldn’t, they were stuck right where they were.

Like the elephants, how many of us go through life hanging onto a belief that we cannot do something, simply because we failed at it once before?

Java VM Options

Ignoring VM options costs a lot.

Here is an example:

In NetBeans (Java IDE), an option in Project Properties set for Run like this -Dendian=big will return System.getProperty(“endian”) as big.

However, when, from terminal the application is run by java –jar x.jar (ignoring -Dendian=big), the application will return null when System.getProperty(“endian”) is being called, and so forthcoming NullPointerException etc.

VM Option can be set like below:

-Dname=value

E.g. “endian” property can be set by -Dendian=big

New year 2008

We, Indians are, perhaps the luckiest persons in the world. We celebrate a new year after Pateti, another new year after Mahorram, another after Diwali, and a new year in daily practice after Christmas! It’s a challenge to any foreigner – you name it, we celebrate it!!!

It is possible only because we have selected secularism in our constitution.

I find this, as an opportunity to wish all that the new year drives dreams in successful manner!

The Next Social Network: WordPress

Could open-source blogging platform WordPress serve as your next social networking profile? Chris Messina, co-founder of Citizen Agency, thinks so. He’s started a project called DiSo, for distributed social networking, that aims to “build a social network with its skin inside out.” DiSo will first look to WordPress as its foundation.This could be the next step towards the unified social graph that some technologists wish for. WordPress suits the purpose because it provides a person-centric way of coming online, offers an extensible architecture, and already has some features — such as an OpenID and a blogroll plugin — that can be pressed into social networking service. And its users represent exactly the sort of audience that might appreciate the permanent, relatively public identity that DiSo aims to offer.

Why blogs and not Facebook or MySpace

In contrast to social networking, blogging offers a person-centric way for individuals to come online. A social network like Facebook gives you your own place online, but it’s not really your own place. As Copyblogger Brian Clark recently said in a blog post, “For me, there’s really no appeal in spending a lot of time creating ‘user-generated’ content via a social networking application. That’s like remodeling the kitchen in a house you rent.”

Clark was responding to an ongoing conversation launched by blogger and cartoonist Hugh MacLeod, who proposed that blogging is far more important to him than social networking. Bloggers including Stowe Boyd and Darren Rowse seconded the idea. This growing disenchantment with social networking and return to blogging suggests that in the future we could see a migration, at least among tech bloggers, towards more distributed social networking — along the lines of what Messina envisions.

WordPress, why and how

WordPress is ideal for experimenting with a distributed social network. It has a plug-in architecture that makes it easy to extend. And people who use it are already comfortable to some extent with coming publicly online as individuals. Though there are, of course, WordPress installations that don’t represent just one person, in many cases they do.

Messina, along with Steve Ivy and Will Norris, is exploring how WordPress can serve as a social networking profile. To that end, a blog needs a way to identify itself to other blogs and share its contact lists, ideally in a privacy-protected manner. The OpenID identity standard can serve as a distributed identifier for both a person’s blog and the blogs of people to which that person is related. Messina and his partners plan to develop a WordPress plugin that exposes the contact list. An OpenID plugin for WordPress already exists; it was developed by Will Norris.

Not everyone wants unified social networking

WordPress-as-social-network, like the unified social graph meme, will most likely appeal to those who want to create one strong identity online. But not everyone does. Blogger danah boyd has written about how some people use social network identities in an ephemeral manner. Those who prefer a more multilayered and multifaceted depiction of themselves online might prefer to create multiple social networking profiles on different sites, representing themselves in different ways as the situation demands.

But those who already use WordPress probably want to build a strong and persistent online presence and identity. Plus they’re the geeky sort, with whom with the idea of a unified, distributed social network might resonate. And at least some of them are refocusing on blogging. The next hot social network might just be built out of blogs.

%d bloggers like this: