Sign up to create your own snipts, or login.

Public snipts » nicolascormier's snipts The latest snipts from nicolascormier.

showing 1-12 of 12 snipts
  • vrac
    - (UITableViewCell*) tableView:(UITableView*)target cellForRowAtIndexPath:(NSIndexPath*)indexPath
    {
      UITableViewCell* sourceCell = nil;
      NSInteger row = kIndexPathToRow(indexPath);
      if (!row)
      {
        static NSString* sCellID = @"EKArticlesListHeaderCell";
        sourceCell = [target dequeueReusableCellWithIdentifier:sCellID];
        if (!sourceCell) sourceCell = [[[EKArticlesListHeaderCell alloc] initWithFrame:CGRectZero reuseIdentifier:sCellID] autorelease];
      }
      else if ((row-1) < [_articles count])
      {
        static NSString* sCellID = @"EKArticlesListOptimizedCell";
        sourceCell = [target dequeueReusableCellWithIdentifier:sCellID];
        if (!sourceCell) sourceCell = [[[EKArticlesListOptimizedCell alloc] initWithFrame:CGRectZero reuseIdentifier:sCellID] autorelease];
        ((EKArticlesListOptimizedCell*)sourceCell).article = [_articles objectAtIndex:(row-1)];
      }
      else // load more row
      {
        static NSString* sCellID = @"EKArticlesMoreListCell";
        sourceCell = [target dequeueReusableCellWithIdentifier:sCellID];
        if (!sourceCell) sourceCell = [[[EKArticlesMoreListCell alloc] initWithFrame:CGRectZero reuseIdentifier:sCellID] autorelease];
        ((EKArticlesMoreListCell*)sourceCell).current = _fetchLimit;
        ((EKArticlesMoreListCell*)sourceCell).total = _totalArticleCount;
      }
      return sourceCell;
    }
    

    copy | embed

    0 comments - tagged in  posted by nicolascormier on Feb 23, 2010 at 9:46 p.m. EST
  • vrac
    - (id) initWithFrame:(CGRect)aRect reuseIdentifier:(NSString *)identifier
    {
    	if (self = [super initWithFrame:aRect reuseIdentifier:identifier])
    	{
        self.selectionStyle = UITableViewCellSelectionStyleGray;
        
        _mybackgroundView = [[[UIView alloc] initWithFrame:aRect] autorelease];
        _mybackgroundView.backgroundColor = [UIColor whiteColor];
    		[self.contentView addSubview:_mybackgroundView];    
        
    		_titleLabel = [[[UILabel alloc] initWithFrame:aRect] autorelease];
        _titleLabel.numberOfLines = 1;
    		_titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:16.];
        _titleLabel.textColor = [UIColor colorWithRed:71./255. green:68./255. blue:58./255. alpha:1.];
        _titleLabel.text = @"Load More Articles...";
    		[self.contentView addSubview:_titleLabel];
        
        _subtitleLabel = [[[UILabel alloc] initWithFrame:aRect] autorelease];
        _subtitleLabel.numberOfLines = 1;
    		_subtitleLabel.font = [UIFont fontWithName:@"Arial" size:12.];
        _subtitleLabel.textColor = [UIColor colorWithRed:119./255. green:119./255. blue:119./255. alpha:1.];
    		[self.contentView addSubview:_subtitleLabel];
        
    	}
    	return self;
    }
    
    - (CGSize) layoutSubviewsThatFits:(CGSize)size setFrames:(BOOL)setFrames
    {
    
      CGSize titleTextSize =  ((CGRect)[_titleLabel textRectForBounds:CGRectMake(0., 0., size.width, kBloodyHugeHeight) limitedToNumberOfLines:_titleLabel.numberOfLines]).size;
      CGSize subtitleTextSize =  ((CGRect)[_subtitleLabel textRectForBounds:CGRectMake(0., 0., size.width, kBloodyHugeHeight) limitedToNumberOfLines:_subtitleLabel.numberOfLines]).size;
      
      CGFloat maxHeight = titleTextSize.height + subtitleTextSize.height + kTopMargin + kBottomMargin + kElementPadding;
      
      CGRect titleFrame = CGRectMake(size.width/2. - titleTextSize.width/2.,
                                     maxHeight/2. - (titleTextSize.height+subtitleTextSize.height)/2.,
                                     titleTextSize.width, titleTextSize.height);
      CGRect subtitleFrame = CGRectMake(size.width/2. - subtitleTextSize.width/2., 
                                        titleFrame.origin.y +  titleTextSize.height + kElementPadding,
                                        subtitleTextSize.width, subtitleTextSize.height);
      
      if (setFrames)
      {
        _titleLabel.frame = CSNormalizeFrame(titleFrame);
        _subtitleLabel.frame = CSNormalizeFrame(subtitleFrame);
        _mybackgroundView.frame = CGRectMake(0., 0., size.width, size.height);
      }
      return ((CGSize){ size.width, maxHeight });
    }
    
    - (CGSize) sizeThatFits:(CGSize)size
    {
      return [self layoutSubviewsThatFits:size setFrames:NO];
    }
    
    - (void) layoutSubviews
    {	
    	[super layoutSubviews];
      (void) [self layoutSubviewsThatFits:self.bounds.size setFrames:YES];
    }
    

    copy | embed

    0 comments - tagged in  posted by nicolascormier on Feb 23, 2010 at 9:45 p.m. EST
  • vrac
      _window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
      _navigationController = [[UINavigationController alloc] initWithRootViewController:[[[HLHomepageListViewController alloc] init] autorelease]];
      [_window addSubview:_navigationController.view];    
    
    
    
    
    
    
      [self performSelectorInBackground:@selector(forceMobileVersion) withObject:nil];
    
    - (void) forceMobileVersion
    {
      NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
      [NSData dataWithContentsOfURL:[HLConstants forceMobileVersionOfWebsiteURL]];
      [pool release];
    }
    

    copy | embed

    0 comments - tagged in  posted by nicolascormier on Feb 23, 2010 at 9:42 p.m. EST
  • random md5
    md5(uniqid(rand(), true));
    

    copy | embed

    0 comments - tagged in  posted by nicolascormier on Feb 08, 2010 at 7:49 p.m. EST
  • view fade animation
      CATransition* animation = [CATransition animation];
    	[animation setType:kCATransitionFade];
    	[[aSuperview layer] addAnimation:animation forKey:@"layerAnimation"];
    

    copy | embed

    0 comments - tagged in  posted by nicolascormier on Oct 06, 2009 at 12:30 a.m. EDT
  • class initialiser
    + (void) initialize
    {
      if (self == [ClassName class])
      {
        /**
         * initialize class properties
         */
      }
    }
    

    copy | embed

    0 comments - tagged in  posted by nicolascormier on Oct 03, 2009 at 7:35 p.m. EDT
  • uiview to uiimage
    UIGraphicsBeginImageContext(myView.bounds.size);
    [myView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    copy | embed

    0 comments - tagged in  posted by nicolascormier on Sep 30, 2009 at 4:33 a.m. EDT
  • sql force id insert
    SET IDENTITY_INSERT TABLE ON;
                              
    INSERT  INTO TABLE
      (ID, ...)
    VALUES
      (ID, ...);
    
    SET IDENTITY_INSERT TABLE OFF;
    

    copy | embed

    0 comments - tagged in  posted by nicolascormier on Sep 30, 2009 at 3:25 a.m. EDT
  • shadow gradient
    - (CAGradientLayer *)shadowAsInverse:(BOOL)inverse
    {
    	CAGradientLayer *newShadow = [[[CAGradientLayer alloc] init] autorelease];
    	CGRect newShadowFrame = CGRectMake(0, 0, self.frame.size.width, inverse ? SHADOW_INVERSE_HEIGHT : SHADOW_HEIGHT);
    	newShadow.frame = newShadowFrame;
    	CGColorRef darkColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha: inverse ? (SHADOW_INVERSE_HEIGHT / SHADOW_HEIGHT) * 0.5 : 0.5].CGColor;
    	CGColorRef lightColor = [self.backgroundColor colorWithAlphaComponent:0.0].CGColor;
    	newShadow.colors = [NSArray arrayWithObjects:(id)(inverse ? lightColor : darkColor), (id)(inverse ? darkColor : lightColor), nil];
    	return newShadow;
    }
    

    copy | embed

    0 comments - tagged in  posted by nicolascormier on Sep 30, 2009 at 2:06 a.m. EDT
  • modx menu generator
    <?php
      $pages = $modx->getAllChildren($modx->documentObject['id'], $sort= 'menuindex', $dir= 'ASC', $fields= 'id, pagetitle, introtext');
    ?>
    <? foreach ($pages as $page): ?>
      <li><a href="<?=$modx->makeUrl($page['id'])?>"><?=$page['pagetitle']?></a> </li>
    <? endforeach ?>
    

    copy | embed

    0 comments - tagged in  posted by nicolascormier on Sep 27, 2009 at 9:28 p.m. EDT
  • uitableview variable height
    - (CGFloat) tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
    {
      return ((CGSize)[[self tableView:tableView cellForRowAtIndexPath:indexPath] sizeThatFits:self.view.frame.size]).height;
    }
    
    - (NSInteger) numberOfSectionsInTableView:(UITableView*)tableView
    {
      return 1;
    }
    
    - (NSInteger) tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
    {
      return 1;
    }
    
    - (UITableViewCell*) tableView:(UITableView*)target cellForRowAtIndexPath:(NSIndexPath*)indexPath
    {
      static NSString* sCellID = @"HLAskListCell";
      UITableViewCell* sourceCell = [target dequeueReusableCellWithIdentifier:sCellID];
      if (!sourceCell) sourceCell = [[[HLAskListCell alloc] initWithFrame:CGRectZero reuseIdentifier:sCellID] autorelease];
      return sourceCell;
    }
    

    copy | embed

    0 comments - tagged in  posted by nicolascormier on Sep 27, 2009 at 7:04 a.m. EDT
  • layoutSubviewsThatFits
      CGSize titleTextSize =  ((CGRect)[_titleLabel textRectForBounds:CGRectMake(contentLeftOffset, topOffset, contentWidth, kBloodyHugeHeight) limitedToNumberOfLines:_titleLabel.numberOfLines]).size;
      CGRect titleFrame = CGRectMake(contentLeftOffset, topOffset, contentWidth, titleTextSize.height);
      topOffset += titleFrame.size.height + kTitleBottomPadding;
    

    copy | embed

    0 comments - tagged in  posted by nicolascormier on Sep 24, 2009 at 3:16 a.m. EDT
Sign up to create your own snipts, or login.