Skip to content

Instantly share code, notes, and snippets.

View FlaviuSim's full-sized avatar

Flaviu Simihaian FlaviuSim

View GitHub Profile
#!/usr/bin/env bash
sudo apt-get -y update
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
cd /tmp
sudo wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
sudo tar -xvzf ruby-1.9.3-p125.tar.gz
sudo cd ruby-1.9.3-p125/
./configure --prefix=/usr/local
sudo make
sudo make install
@FlaviuSim
FlaviuSim / gist:2499038
Created April 26, 2012 11:41
Chef Solo Bootstrap - edited again
#!/usr/bin/env bash
sudo su -
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar -xvzf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125/
./configure --prefix=/usr/local
make
@FlaviuSim
FlaviuSim / gist:2499028
Created April 26, 2012 11:39
Chef Solo Bootstrap - edited
#!/usr/bin/env bash
sudo apt-get -y update
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
cd /tmp
sudo wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
sudo tar -xvzf ruby-1.9.3-p125.tar.gz
sudo cd ruby-1.9.3-p125/
sudo ./configure --prefix=/usr/local
sudo make
sudo make install
@FlaviuSim
FlaviuSim / gist:2499022
Created April 26, 2012 11:38
Chef Solo Bootstrap - edited
#!/usr/bin/env bash
sudo apt-get -y update
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
cd /tmp
sudo wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
sudo tar -xvzf ruby-1.9.3-p125.tar.gz
sudo cd ruby-1.9.3-p125/
sudo ./configure --prefix=/usr/local
sudo make
sudo make install
@FlaviuSim
FlaviuSim / gist:2498896
Created April 26, 2012 11:17
Chef Solo Bootstrap
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar -xvzf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125/
./configure --prefix=/usr/local
make
make install
// make the post using the objectManager if you want to map the response to a model
RKObjectManager* objectManager = [RKObjectManager sharedManager];
[objectManager loadObjectsAtResourcePath:@"/api/" delegate:self block:^(RKObjectLoader* loader) {
loader.serializationMIMEType = RKMIMETypeJSON; // We want to send this request as JSON
loader.objectMapping = [objectManager.mappingProvider objectMappingForClass:[Plan class]];
loader.resourcePath = @"/api/";
loader.method = RKRequestMethodPOST;
loader.params = [RKRequestSerialization serializationWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] MIMEType:RKMIMETypeJSON];
}];
// create a JSON string from your NSDictionary
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:finalDict
options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
error:&error];
NSString *jsonString = [[NSString alloc] init];
if (!jsonData) {
NSLog(@"Got an error: %@", error);
} else {
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
// make the inner dictionaries (probably would use a for loop for this)
NSDictionary *dict1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"value1", @"key", nil];
NSDictionary *dict2 = [[NSDictionary alloc] initWithObjectsAndKeys:@"value2", @"key", nil];
// put them in an array
NSArray *types = [[NSArray alloc] initWithObjects:dict1, dict2, nil];
// now put the array in a dictionary
NSDictionary *finalDict = [[NSDictionary alloc] initWithObjectsAndKeys:types, @"types", nil];
// make the inner dictionaries (probably would use a for loop for this)
NSDictionary *dict1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"value1", @"1", nil];
NSDictionary *dict7 = [[NSDictionary alloc] initWithObjectsAndKeys:@"value2", @"7", nil];
// put them in an array
NSArray *types = [[NSArray alloc] initWithObjects:dict1, dict7, nil];
// now put the array in a dictionary
NSDictionary *finalDict = [[NSDictionary alloc] initWithObjectsAndKeys:types, @"types", nil];
{
"types":[ {
"key" : "value1"
},
{
"key" : "value2"
} ]
}