Skip to content

Instantly share code, notes, and snippets.

/*
Using data serialization for client server communication
CPKeyedArchiver
CPKeyedArchiver is the easiest way to serialize your data into some string value for client/server communication (for example using CPURLRequest and CPURLConnection objects).
*/
-(void) sendAsynchRequest
@dbrajkovic
dbrajkovic / .gitignore.m
Created February 16, 2011 22:53
gitignore file for Xcode Projects
# Mac OS X Finder and whatnot
.DS_Store
# Sparkle distribution Private Key (Don't check me in!)
dsa_priv.pem
# XCode (and ancestors) per-user config (very noisy, and not relevant)
*.mode1
equest URL:http://test.stocktwits.com/api/account/verify_credentials.json
Request Method:GET
Status Code:200 OK
Request Headers
Authorization:Basic YXBwbGV0ZXN0ZXI6YXBwbGV0ZXN0ZXI=
Cache-Control:no-cache
If-Modified-Since:Thu, 01 Jan 1970 00:00:00 GMT
User-Agent:Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-us) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4
X-Requested-With:XMLHttpRequest
X-St:true
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
var bundle = [CPBundle mainBundle],
leftCapImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"signin-button-left-cap-up.png"] size:CGSizeMake(5, 42)],
rightCapImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"signin-button-right-cap-up.png"] size:CGSizeMake(5, 42)],
centerImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"signin-button-center-up.png"] size:CGSizeMake(93, 42)],
bezelImage = [[CPThreePartImage alloc] initWithImageSlices:[leftCapImage, centerImage, rightCapImage] isVertical:NO],
downleftCapImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:"signin-button-left-cap-down.png"] size:CGSizeMake(5, 42)],
+(void)updateAccount:(CPDictionary)accountParams delegate:(id)delegate
{
var urlString = [CPString stringWithFormat:@"http://api.webservice.com/account/update.json"];
var request = [self requestWithURLString:urlString];
var name = [accountParams valueForKey:@"name"];
var username = [accountParams valueForKey:@"username"];
var email = [accountParams valueForKey:@"email"];
var postBody = [CPString stringWithFormat:@"name=%@&username=%@&email=%@", name, username, email];
[request setValue:[postBody length] forHTTPHeaderField:@"Content-Length"];
[request setHTTPMethod:@"POST"];
require 'net/http'
require 'uri'
#1: Simple POST
res = Net::HTTP.post_form(URI.parse('http://www.example.com/search.cgi'),
{'q'=>'ruby', 'max'=>'50'})
puts res.body
#2: POST with basic authentication
res = Net::HTTP.post_form(URI.parse('http://jack:pass@www.example.com/todo.cgi'),
var addButton = [CPButtonBar plusButton];
[addButton setAction:@selector(add:)];
[addButton setTarget:self];
[addButton setEnabled:YES];
var minusButton = [CPButtonBar minusButton];
[minusButton setAction:@selector(remove:)];
[minusButton setTarget:self];
[minusButton setEnabled:YES];
[buttonBar setButtons:[addButton, minusButton]];
@dbrajkovic
dbrajkovic / STAttachedWindow.j
Created March 9, 2011 14:58
A subclass of TNAttachedWindow that prevents a window from going too far to the left off screen.
/*
* STAttachedWindow.j
* stocktwits-desktop-2
*
* Created by Daniel Brajkovic on 12/13/10.
* Copyright Witton Technology Group 2010. All rights reserved.
*/
@import "TNAttachedWindow.j"
/*
* More info at: http://phpjs.org
* http://phpjs.org/functions/index
*
* php.js is copyright 2009 Kevin van Zonneveld.
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* Conversion to Objective-J copyright 2009 Philippe Laval
* Licenced under the same MIT, GPL dual licences.
@dbrajkovic
dbrajkovic / setupButtonBar.j
Created March 16, 2011 18:35
This assumes you created a CPButtonBar
var buttonBar = [[CPButtonBar alloc] initWithFrame:CGRectMake(0,0,100,32)]; //you need to use your own frame obviously
[someSuperView addSubview:buttonBar];
var addButton = [CPButtonBar plusButton];
[addButton setAction:@selector(add:)];
[addButton setTarget:self];
[addButton setEnabled:YES];
var minusButton = [CPButtonBar minusButton];