Skip to content

Instantly share code, notes, and snippets.

View stuffmc's full-sized avatar

StuFF mc stuffmc

View GitHub Profile
+ (void)asyncRequest:(NSURLRequest *)request success:(void(^)(NSData *,NSURLResponse *))successBlock_ failure:(void(^)(NSData *,NSError *))failureBlock_
{
[[failureBlock_ copy] autorelease];
[[successBlock_ copy] autorelease];
[NSThread detachNewThreadSelector:@selector(backgroundSync:) toTarget:[NSURLConnection class]
withObject:[NSDictionary dictionaryWithObjectsAndKeys:
request,@"request",
successBlock_,@"success",
failureBlock_,@"failure",
nil]];
@stuffmc
stuffmc / gist:1016621
Created June 9, 2011 12:18
imageWithCGImage:scale:orientation:
- (void)upload:(UIImage*)image {
CGFloat width = [image size].width;
CGFloat scale = 600/width;
UIImage *picture = [UIImage imageWithCGImage:[image CGImage] scale:scale orientation:UIImageOrientationRight];
NSLog(@"image: %@ - picture: %@", NSStringFromCGSize([image size]), NSStringFromCGSize([picture size]));
image: {1536, 2048} - picture: {3932.16, 5242.88}
self.imagePickerController = [[UIImagePickerController alloc] init];
[self.imagePickerController setDelegate:self];
[self presentModalViewController:self.imagePickerController animated:YES];
--
@interface MainViewController : UIViewController <UIImagePickerControllerDelegate> {
--
@stuffmc
stuffmc / jquery-ui-draggable-droppable.js
Created August 8, 2011 20:37
jQuery-ui Draggable Droppable can't drop
$(".ui-sortable tr").each(function() {
$($(this)).droppable({
accept: "tr",
drop: function(e, ui) {
console.log('dropped');
},
over: function(e, ui) {
ui.draggable.insertAfter(this);
}
});
21.08.11 13:54:45,295 [0x0-0x8008].com.apple.dt.Xcode: Traceback (most recent call last):
21.08.11 13:54:45,295 [0x0-0x8008].com.apple.dt.Xcode: File "<console>", line 1, in <module>
21.08.11 13:54:45,295 [0x0-0x8008].com.apple.dt.Xcode: IOError: [Errno 2] No such file or directory: '/dev/ttys012'
21.08.11 13:54:45,295 [0x0-0x8008].com.apple.dt.Xcode: Traceback (most recent call last):
21.08.11 13:54:45,295 [0x0-0x8008].com.apple.dt.Xcode: File "<console>", line 1, in <module>
21.08.11 13:54:45,295 [0x0-0x8008].com.apple.dt.Xcode: NameError: name 'new_stdin' is not defined
21.08.11 13:54:45,295 Xcode: unable to start read thread for lldb io
21.08.11 13:54:45,385 com.apple.debugserver-141: debugserver-141 for x86_64.
21.08.11 13:54:45,385 com.apple.debugserver-141: Listening to port 43409...
21.08.11 13:54:45,481 com.apple.debugserver-141: Got a connection, waiting for process information for launching or attaching.
@stuffmc
stuffmc / value_for_key_path.rb
Created September 17, 2011 12:29
Ruby Implementation of "valueForKeyPath"
class Hash
def key_path(dotted_path)
# see http://stackoverflow.com/questions/7139471/transform-a-ruby-hash-into-a-dotted-path-key-string
parts = dotted_path.split '.', 2
match = self[parts[0]]
if !parts[1] or match.nil?
return match
else
return match.key_path(parts[1])
end
.row
.left
display: inline-block
width: 70px
.right
display: inline-block
margin-left: 10px
width: 20px
#fake .row .left {
display: inline-block;
text-align: right;
width: 70px;
}
#fake .row .right {
display: inline-block;
width: 20px;
}
FYI: If you come from Google on this one... YAML is installed with Ruby... If it can be compiled! When installing 1.9.2 with "rvm install 1.9.2"
I stumbled upon Yaml not installing because gcc4.2 wasn't on my system. Turned out it was because Xcode 4.2 doesn't deliver GCC 4.2 anymore so
you'll have to either Install Xcode 4.1 (or at least the Unix tools) or install gcc by hand (or brew, or anything).
gem install psych
Building native extensions. This could take a while...
ERROR: Error installing psych:
ERROR: Failed to build gem native extension.
@stuffmc
stuffmc / gist:1396335
Created November 26, 2011 21:39
AVAssetExportSession
AVAsset *asset = [AVAsset assetWithURL:inputURL];
NSLocale *locale = [[asset availableChapterLocales] lastObject];
NSArray *keys = [NSArray arrayWithObjects:AVMetadataCommonKeyTitle, nil];
NSArray *chapters = [asset chapterMetadataGroupsWithTitleLocale:locale containingItemsWithCommonKeys:keys];
// Yes, we do have chapters ;-) 8... ;-)
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetAppleM4A];
exportSession.outputURL = outputURL;
exportSession.outputFileType = AVFileTypeAppleM4A;