Search This Blog

Showing posts with label source code. Show all posts
Showing posts with label source code. Show all posts

Wednesday, January 26, 2011

Getting twitter feed while Twitter is blocked

I don't know if u know what is going on in Egypt but there is lots of problems with the government and they blocked twitter.

anyways, I think I do know how to get over it, the matter is simple, try to get any of twitter's IPs' and then connect to it using the IP

The problem with it is, the browsers will use it The IP as a Host in the HTTP header, I have tried with many plugin to use something else but I always get "the redirect code" but when I did telnet on the IP and Wrote the http my self it did work :D "how do write HTTP :D"
anyways, I looked for a simple client and I tried something and it is 100% working



#define PORT 80

#define HOST "128.121.243.228"

#define DIRSIZE 8192000

#define HTTP_HEADER "GET /statuses/user_timeline/Neo_4583.json HTTP/1.1\nHost: twitter.com\n\n"


char* strToSend = HTTP_HEADER;

char hostname[100];

char dir[DIRSIZE];

int sd;

struct sockaddr_in pin;

struct hostent *hp;

strcpy(hostname,HOST);


if ((hp = gethostbyname(hostname)) == 0) {

exit(1);

}

memset(&pin, 0, sizeof(pin));

pin.sin_family = AF_INET;

pin.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr;

pin.sin_port = htons(PORT);

if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {

perror("socket");

exit(1);

}

if (connect(sd,(struct sockaddr *) &pin, sizeof(pin)) == -1) {

perror("connect");

exit(1);

}


if (send(sd, strToSend, strlen(strToSend), 0) == -1) {

exit(1);

}

if (recv(sd, dir, DIRSIZE, MSG_WAITALL) == -1) {

exit(1);

}else {

// The data is ready to be served

printf("%s\n", dir);

}

close(sd);



"Next step, modify the HTTP header in the browser so it works correctly with twitter"
Enjoy the code
Thanks for your time

BR
Ahmed Essam

Friday, November 19, 2010

iOS SDK Text To Speech in one line

Peace be upon you

How are you guys? I am so glade that I am writing to you, todays post will be short and hopefully useful.

While I was digging in iOS's private frameworks one library caught my attention, "VoiceServices" after some playing around it I found that there is away to use the "VoiceOver" capabilities out of its context, Here is video explaining the whole thing.


Here is the code for it.

[[[NSClassFromString(@"VSSpeechSynthesizer") new]autorelease] startSpeakingString:@"I like to speak everywhere"];


As you can see, with this line u can make the iOS speak whatever to you, just find useful use for it, something to read the twits or RSS feeds.


Enjoy :)


BR

Ahmed Essam

Thursday, November 04, 2010

Extending TBXML

Peace be upon you

How are you my beloved reader :)? I hope things is going Ok with you.

today I have added something to the library "TBXML" to extend the functionality to help reading XML in easier way.
Here is link for the library http://tbxml.co.uk/

the functions that I have wrote simply reads the XML and turn it into "Dictionary (Hash table)" the functions that I have wrote neglects the attributes, such code will help transforming the complex hierarchy of XML into dictionary that has key value (the value code be string, array or another dictionary )

Here is the code that I have added to the library (Add this code to the class "TBXML")


+ (NSMutableDictionary*) getXMLNodeInDictionary:(TBXMLElement *)element {

NSMutableDictionary* retDict = [NSMutableDictionary new];

do {

if (element->firstChild) {

if ([retDict valueForKey:[TBXML elementName:element]]==nil) {

[retDict setObject:[self getXMLNodeInDictionary:element->firstChild] forKey:[TBXML elementName:element]];

}else if ([[retDict valueForKey:[TBXML elementName:element]] isKindOfClass:[NSMutableArray class]]) {

[[retDict valueForKey:[TBXML elementName:element]] addObject:[self getXMLNodeInDictionary:element->firstChild]];

}else {

NSMutableArray* arr = [NSMutableArray new];

[arr addObject:[retDict valueForKey:[TBXML elementName:element]]];

[arr addObject:[self getXMLNodeInDictionary:element->firstChild]];

[retDict setObject:[arr autorelease] forKey:[TBXML elementName:element]];

}

}else {

[retDict setObject:[TBXML textForElement:element] forKey:[TBXML elementName:element]];

}

} while ((element = element->nextSibling));

return [retDict autorelease];

}


+ (NSMutableDictionary*)getXMLFileInDictionary:(NSString*)filenameWithFullPath{

NSString* str = [[NSString alloc]initWithContentsOfFile:filenameWithFullPath];

TBXML * tbxml = [TBXML tbxmlWithXMLString:str];

if (!tbxml.rootXMLElement) {

return nil;

}

return [self getXMLNodeInDictionary:tbxml.rootXMLElement];

}




Thanks for your time :)


BR

Ahmed Essam