Skip to content

Instantly share code, notes, and snippets.

View cgreening's full-sized avatar

Chris cgreening

View GitHub Profile
@cgreening
cgreening / gist:5876948
Created June 27, 2013 14:38
Create a multipart for request for posting
Use like this:
NSData* fileData = UIImageJPEGRepresentation(profileImage, 0.8f);
NSMutableURLRequest *request = [self.httpClient requestWithMethod:@"POST" path:@"api/users/updateSettings" parameters:params];
[self setupMultipartRequest:request withParams:params data:fileData dataName:@"profileImage"];
-(void) setupMultipartRequest:(NSMutableURLRequest *) request withParams:(NSDictionary *) params data:(NSData *) data dataName:(NSString *) dataName {
//Add the header info
NSString *stringBoundary = @"0xKhTmLbOuNdArY";
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
require 'net/https'
require 'uri'
if ARGV.length != 2
puts "Usage: makeBranch.rb SPRINT_NUMBER PT_ID"
else
urlString = 'https://www.pivotaltracker.com/services/v5/stories/'+ARGV[1]
fetchRequest.entity = [RNPFeedListEntry entityInManagedObjectContext:self.managedObjectContext];
// this is the main predicate to get the feed entries that belong to the us
NSPredicate *ownerPredicate = [NSPredicate predicateWithFormat:@"%K == %@ AND %K.%K == %@",
RNPFeedListEntryRelationships.owner, self, RNPFeedListEntryRelationships.feed,
RNPFeedAttributes.action, @(FeedAction_LIKE), self];
// this is the predicate to check that we have the required item
NSPredicate *itemPopulatedPredicate = [NSPredicate predicateWithFormat:@"(%K.%K != nil AND %K.%K != nil) OR (%K.%K == nil)",
RNPFeedListEntryRelationships.feed, RNPFeedAttributes.itemId,
RNPFeedListEntryRelationships.feed, RNPFeedRelationships.item,
RNPFeedListEntryRelationships.feed, RNPFeedAttributes.itemId];
self.backgroundManagedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[self.backgroundManagedObjectContext setPersistentStoreCoordinator:persistentStoreCoordinator];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backgroundContextDidSave:) name:NSManagedObjectContextDidSaveNotification object:self.backgroundManagedObjectContext];
- (void)backgroundContextDidSave:(NSNotification *)didSaveNotification {
[self.managedObjectContext performBlock:^{
NSDate *start = [NSDate date];
[self.managedObjectContext mergeChangesFromContextDidSaveNotification:didSaveNotification];
DLog(@"Merging background changes took %f", [[NSDate date] timeIntervalSinceDate:start]);
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
[self.tableView beginUpdates];
}
- (void)controller:(NSFetchedResultsController*)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath*)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath*)newIndexPath
{
UITableView* tableView = self.tableView;
switch (type)
{
case NSFetchedResultsChangeInsert:
@cgreening
cgreening / nodule_scanning.js
Last active August 29, 2015 14:22
Scanning for devices
// start nodule scanning for devices advertising these services
nodule.startScanning([['uuid1', 'uuid2'], ['uuid3', 'uuid4']]);
nodule.on('scan', function(devices) {
// devices is an array of devices that are advertising the requested services
/*
devices = [
{
deviceName: 'TI Sensor Tag',
advertisedServices: ['uuid1', 'uuid2'],
@cgreening
cgreening / setup.html
Last active August 29, 2015 14:22
Setup nodule
<script src='https://code.jquery.com/jquery-2.1.3.min.js'></script>
<script src='https://www.nodule.io/js/nodule.151851370efa27253700.js'></script>
@cgreening
cgreening / connect.js
Last active August 29, 2015 14:22
connect to nodule
nodule.connect('wss://app.nodule.io', '<API ACCESS TOKEN>').then(function(nodule) {
}, function(error) {
console.error('Connection failed', error);
}
@cgreening
cgreening / scan.js
Last active August 29, 2015 14:22
Scan for peripherals
nodule.scanForPeripherals(<NAME REGEX>, [<SERVICE UUIDS>]);
// e.g. Scan for all peripherals with names ending in Temperature
nodule.scanForPeripherals(/.*Temperature/);
// e.g. Scan for all peripherals that advertise battery level and heart rate services
nodule.scanForPeripherals(/.*/, ['180F', '180D']);
@cgreening
cgreening / write.js
Last active August 29, 2015 14:22
write
profile.services[SERVICE_UUID].characteristics[CHARACTERISTIC_UUID].writeUint8(1);
// you can use any of the following methods
writeUint8(number);
writeUint16(number);
writeUint32(number);
writeInt8(number);
writeInt16(number);
writeInt32(number);
writeText(string);