Skip to content

Instantly share code, notes, and snippets.

@AquaGeek
AquaGeek / pragma.m
Created March 26, 2012 18:36
Interesting pragma options
// From zoul - http://stackoverflow.com/questions/7853915/how-do-i-avoid-capturing-self-in-blocks-when-implementing-an-api
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-retain-cycles"
self.progressBlock = ^(CGFloat percentComplete) {
[self.delegate processingWithProgress:percentComplete];
}
#pragma clang diagnostic pop
@AquaGeek
AquaGeek / Before.m
Created March 26, 2012 18:26
Blocks and retain cycles
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Adjust the table view's content inset when the keyboard appears/disappears
_keyboardWillShowNotification = [[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillShowNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note)
{
@AquaGeek
AquaGeek / LeapYear.m
Created February 29, 2012 15:50
NSDate notes
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
@autoreleasepool {
NSString *dateString = @"8:56pm 29 Feb";
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
[formatter setDateFormat:@"h:mma d MMM"];
@AquaGeek
AquaGeek / TweetTest.m
Created January 18, 2012 15:42
Bug in iOS 5.0's TWTweetComposeViewController
- (void)showTweetSheet
{
TWTweetComposeViewController *composeVC = [[TWTweetComposeViewController alloc] init];
NSString *tweet = @"Hello, this is a message that is 117 characters long. Let's add a bunch more characters to see how long we can make i";
//!!! BUG: If you switch the order of these two calls, the URL will not get added.
BOOL urlAdded = [composeVC addURL:[NSURL URLWithString:@"http://developer.apple.com/library/ios"]];
BOOL textAdded = [composeVC setInitialText:tweet];
#pragma unused(urlAdded)
@AquaGeek
AquaGeek / NSCachedURLResponse+EncodingFix.m
Created October 7, 2011 18:49
NSCachedURLResponse and NSKeyedArchiver issue
@implementation NSCachedURLResponse(HackityHack)
- (id)initWithCoder:(NSCoder *)aDecoder
{
return [self initWithResponse:[aDecoder decodeObjectForKey:@"response"]
data:[aDecoder decodeObjectForKey:@"data"]
userInfo:[aDecoder decodeObjectForKey:@"userInfo"]
storagePolicy:(NSURLCacheStoragePolicy)[aDecoder decodeIntForKey:@"storagePolicy"]];
}
@AquaGeek
AquaGeek / rsa.rb
Created June 2, 2011 03:09
OpenSSL RSA Keygen and Encryption/Decryption
# From: http://snippets.dzone.com/posts/show/3029
# .generate creates an object containing both keys
new_key = OpenSSL::PKey::RSA.generate( 1024 )
puts "Does the generated key object have the public key? #{new_key.public?}\n"
puts "Does the generated key object have the private key? #{new_key.private?}\n\n"
# write the new keys as PEM's
new_public = new_key.public_key
puts "New public key pem:\n#{new_public}\n"
puts "The new public key in human readable form:\n"
@AquaGeek
AquaGeek / before_destroy_with_nested_attr.diff
Created May 14, 2011 02:36
Rails Lighthouse ticket #6769
41c41
<
---
>
655,668d654
< def test_should_set_an_error_into_the_parent_on_before_destroy
< @child_1.class.before_destroy do |object|
< object.errors.add(:name, :undeletable)
< false
< end
@AquaGeek
AquaGeek / i18n_label_value.diff
Created May 14, 2011 02:36
Rails Lighthouse ticket #6753
From 3b8aa2b5cbfd5c72f2143f12236e6fad734b61e5 Mon Sep 17 00:00:00 2001
From: Jason Garber <jg@jasongarber.com>
Date: Wed, 27 Apr 2011 15:06:19 -0600
Subject: [PATCH] Allow a label with the value option to have value-specific translations.
---
actionpack/lib/action_view/helpers/form_helper.rb | 3 ++-
actionpack/test/template/form_helper_test.rb | 12 +++++++++++-
2 files changed, 13 insertions(+), 2 deletions(-)
@AquaGeek
AquaGeek / 0001-calculate-time-spent-in-ar.patch
Created May 14, 2011 02:36
Rails Lighthouse ticket #6749
From 630a55c8ece0fe1616e7785539e97f1a6da0816c Mon Sep 17 00:00:00 2001
From: Frederick Cheung <frederick.cheung@gmail.com>
Date: Tue, 26 Apr 2011 10:12:07 +0100
Subject: [PATCH 1/2] Calculate time spent in AR even if a redirect occurs or if it is after the render
---
.../test/activerecord/controller_runtime_test.rb | 29 +++++++++++++++++++-
.../active_record/railties/controller_runtime.rb | 14 +++++----
2 files changed, 36 insertions(+), 7 deletions(-)
@AquaGeek
AquaGeek / schemeless_uri.diff
Created May 14, 2011 02:36
Rails Lighthouse ticket #6748
From 61eae0f2b1bfcb54f0355b710808bdcd5fe64b84 Mon Sep 17 00:00:00 2001
From: Chad Krsek <chad.krsek@gmail.com>
Date: Mon, 25 Apr 2011 21:57:28 -0700
Subject: [PATCH] asset helpers should understand scheme-relative URLs
---
actionpack/lib/action_view/helpers/asset_paths.rb | 11 +++++++++--
actionpack/test/template/asset_tag_helper_test.rb | 15 +++++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)