Skip to content

Instantly share code, notes, and snippets.

@christophercotton
christophercotton / UIImage+Resize.m
Created July 16, 2010 17:00
Using http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/ but with additions for iPhone 4 hires scale images. Also includes fix for 24bit non alpha images.
// Returns a copy of the image that has been transformed using the given affine transform and scaled to the new size
// The new image's orientation will be UIImageOrientationUp, regardless of the current image's orientation
// If the new size is not integral, it will be rounded up
- (UIImage *)resizedImage:(CGSize)newSize
transform:(CGAffineTransform)transform
drawTransposed:(BOOL)transpose
interpolationQuality:(CGInterpolationQuality)quality {
// COTTON - adding in scaling for iPhone 4
BOOL shouldScale = NO;
# Example class by christophercotton to show how to validate JSON in
# ActiveRecord
class Stuff < ActiveRecord::Base
validates_presence_of :my_field
validate :valid_json
# make sure the JSON is valid
def valid_json
begin