Skip to content

Instantly share code, notes, and snippets.

View toranb's full-sized avatar

Toran Billups toranb

View GitHub Profile
[request setAllHTTPHeaderFields:headers];
- (void)startHttpRequestWithCookie:(NSArray *)authCookies
{
NSURL *url = [NSURL URLWithString:@"http://toranbillups.com/phone/AddSuggestion"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSData *requestData = [@"name=testname&suggestion=testing123" dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary* headers = [NSHTTPCookie requestHeaderFieldsWithCookies:authCookies];
[request setHTTPMethod:@"POST"];
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString* responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[viewController returnHtmlFromPost:responseString];
[responseString release];
}
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSHTTPURLResponse *)response {
NSURL* redirected_url = [request URL];
NSString* querystr = [redirected_url absoluteString];
if (response != nil) {
NSArray* authToken = [NSHTTPCookie cookiesWithResponseHeaderFields:[response allHeaderFields] forURL:[NSURL URLWithString:@""]];
if ([authToken count] > 0) {
NSString* dashboard_url = @"https://www.memberselfservice.com/frmDashBoard.aspx";
if ([querystr isEqualToString:dashboard_url]) {
@toranb
toranb / developerfail.m
Created October 27, 2011 23:23
Code that was not test driven
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
if (responseString == @"") {
[viewController callBackWithMovieDescription:@"failed to load details"];
}else{
NSString* desc = @"";
@toranb
toranb / gist:2372372
Created April 13, 2012 00:41
Auto workon virtualenv bash script based on current directory name
workon_virtualenv() {
if [ -e .git ]; then
current_dir="${PWD##*/}"
if [ -e ~/virtualenvs/$current_dir ]; then
deactivate >/dev/null 2>&1
source ~/virtualenvs/$current_dir/bin/activate
fi
fi
}
@toranb
toranb / original_animatedown.m
Created June 14, 2012 01:55
Initial animate view down method (without blocks)
- (void)animateViewDown:(NSUInteger)size
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
CGRect rect = self.view.frame;
rect.origin.y -= size;
rect.size.height += size;
self.view.frame = rect;
@toranb
toranb / new_animatedown.m
Created June 14, 2012 02:06
updated animate view down method (now with blocks)
- (void)animateViewDown:(NSUInteger)size
{
[self animateView:^(CGRect frame)
{
frame.origin.y -= size;
frame.size.height += size;
return frame;
}
];
}
@toranb
toranb / nodeHttpProxy.js
Created August 1, 2012 20:00
Express and Apache
var httpProxy = require('http-proxy');
var http = require('http');
var express = require('express');
httpProxy.createServer(function (req, res, proxy) {
var nodeVhosts = ["www.site.com"]
var host = req.headers['host'];
var port = nodeVhosts.indexOf(host) > -1
? 8080
@toranb
toranb / withnew.js
Created August 3, 2012 22:43
How the new keyword works in javascript part 1
var Animal = function(omnivore) {
this.omnivore = omnivore;
}
var human = new Animal(true);
console.log("the human is an omnivore " + human.omnivore);
//this will print "the human is an omnivore true"