Skip to content

Instantly share code, notes, and snippets.

// in @interface block
@property (nonatomic, retain) NSDate *dateToView;
// in @implementation block
@synthesize dateToView = _dateToView;
- (void)setDateToView:(NSDate *)newDate {
if (_dateToView == nil || ![_dateToView isEqualToDate:newDate]) {
[_dateToView release];
_dateToView = nil;
==========================================================================================
ORIGINAL CODE
$ ruby test/test_randumb.rb
Loaded suite test/test_randumb
Started
........ user system total real
2.920000 0.070000 2.990000 ( 3.092471)
2.990000 0.070000 3.060000 ( 3.069336)
2.970000 0.070000 3.040000 ( 3.070131)
context 'Benchmarking' do
setup do
100000.times { |i| Artist.make! }
end
should 'do lots of work' do
require 'benchmark'
Benchmark.bm do |x|
x.report { Artist.random }
x.report { Artist.random(5) }
@veader
veader / gist:1214620
Created September 13, 2011 18:33
Rails 2.3.12 + RubyGems 1.8.10
[14:32:48]~/Code/cardiomems/clarity/champion[master*]$ ./script/console
Loading development environment (Rails 2.3.12)
config.load_paths is deprecated and removed in Rails 3, please use autoload_paths instead
config.load_paths= is deprecated and removed in Rails 3, please use autoload_paths= instead
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /Users/veader/.rvm/gems/ruby-1.8.7-p352@championhf/gems/rails-2.3.12/lib/rails/gem_dependency.rb:21.
NOTE: Gem::SourceIndex#initialize is deprecated with no replacement. It will be removed on or after 2011-11-01.
Gem::SourceIndex#initialize called from /Users/veader/.rvm/gems/ruby-1.8.7-p352@championhf/gems/rails-2.3.12/lib/rails/vendor_gem_source_index.rb:100.
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
Gem::SourceIndex#add_spec called from /Users/veader/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems
// Using an animation grouping because we may be changing the duration
[NSAnimationContext beginGrouping];
// With the shift key down, do slow-mo animation
if ([[NSApp currentEvent] modifierFlags] & NSShiftKeyMask) {
[[NSAnimationContext currentContext] setDuration:1.0];
} else {
[[NSAnimationContext currentContext] setDuration:0.6];
}
@veader
veader / gist:914818
Created April 12, 2011 02:39
Fading Animation
NSDictionary *fadeOutDict = [NSDictionary dictionaryWithObjectsAndKeys:_mainFeedViewController.view, NSViewAnimationTargetKey, NSViewAnimationFadeOutEffect, NSViewAnimationEffectKey, nil];
NSAnimation *animation = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:fadeOutDict, nil]];
[animation setDelegate:self];
[animation setFrameRate:60.0];
[animation setDuration:0.5f];
[animation setAnimationBlockingMode:NSAnimationBlocking];
[animation setAnimationCurve:NSAnimationEaseIn];
[animation startAnimation];
[animation release];
class ExternalDbModel < ActiveRecord::Base
self.abstract_class = true
establish_connection "external_#{RAILS_ENV}"
# only need this if you want the other db to be readonly
#private
# def after_initialize
# readonly!
# end
require 'zlib'
class String
def gzip
io = StringIO.new
gz = Zlib::GzipWriter.new(io)
gz.write(self)
gz.close
io.string
end
+ (void)clearCaches {
// clear any URL caches
[[NSURLCache sharedURLCache] removeAllCachedResponses];
// clear any cookie caches
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://%@/", kAPIHost]];
for (NSHTTPCookie *cookie in [cookieStorage cookiesForURL:url]) {
[cookieStorage deleteCookie:cookie];
}
NSSortDescriptor *sortByDate = [[NSSortDescriptor alloc] initWithKey:@"self" ascending:NO];
NSArray *sortingDescriptors = [NSArray arrayWithObject:sortByDate];
[sortByDate release];
// sort array and save for later
alertDates = [[tempDates sortedArrayUsingDescriptors:sortingDescriptors] retain];