Check if NSDate is today

by alex 8. February 2010 09:57

 

NSDate *today = [NSDate date];

NSCalendar *gregorian = [[NSCalendar alloc]

initWithCalendarIdentifier:NSGregorianCalendar];

 

NSDateComponents *weekdayComponents = [gregorian components:(NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit) fromDate:today];

NSInteger todayDay = [weekdayComponents day];

NSInteger todayMonth = [weekdayComponents month];

NSInteger todayYear = [weekdayComponents year];

 

BOOL res = NO;

 

//check if datedump is today

weekdayComponents = [gregorian components:(NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit) fromDate:dateDump];

NSInteger cday = [weekdayComponents day];

NSInteger month = [weekdayComponents month];

NSInteger year = [weekdayComponents year];

 

if (cday == todayDay &&

month == todayMonth &&

year == todayYear){

res = YES;

}

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

ImageMagick on iPhone

by alex 29. January 2010 11:35

# This is updated version from http://www.cloudgoessocial.net/2009/06/09/imagemagick-on-iphone-with-jpeg-png/ 

# Script to make static libraries (jpeg + png) and ImageMagick

# the libraries will be conbined into i386+arm.a static libraries

# to be used inside an XCODE project for iPhone development

 

# The directory structure has to be:

# ~/Desktop/cross_compile/i_m/ <- ImageMagick top directory

#   |-IMDelegataes/ <- Some delegates, in particular jpeg + png

# |-jpeg-6b/ <- Patched jpeg6b

# |-libpng-1.2.37 <- png lib - no need to patch it

# |-tiff-3.8.2 <- tiff lib - no need to patch it

#   |-... <- we don't care what's here! :)

 

# If you don't have this Directory structure you can either create it or try change around the script

 

#!/bin/bash

 

# Set this to the top directory of ImageMagick source:

IM_DIR=/Users/$USER/Desktop/cross_compile/i_m

JPEG_DIR=$IM_DIR/IMDelegates/jpeg-6b

PNG_DIR=$IM_DIR/IMDelegates/libpng-1.2.37

TIFF_DIR=$IM_DIR/IMDelegates/tiff-3.8.2

 

# Set this to where you want the libraries to be placed (if dir is not present it will be created):

TARGET_LIB_DIR=/Users/$USER/Desktop/tmp_target

LIB_DIR=$TARGET_LIB_DIR/im_libs

JPEG_LIB_DIR=$TARGET_LIB_DIR/libjpeg

PNG_LIB_DIR=$TARGET_LIB_DIR/libpng

TIFF_LIB_DIR=$TARGET_LIB_DIR/libtiff

IM_LIB_DIR=$TARGET_LIB_DIR/imagemagick

 

# Set the build directories

mkdir -p $TARGET_LIB_DIR

mkdir -p $LIB_DIR/include/jpeg

mkdir -p $LIB_DIR/include/magick

mkdir -p $LIB_DIR/include/png

mkdir -p $LIB_DIR/include/tiff

mkdir -p $LIB_DIR/include/wand

mkdir -p $LIB_DIR/jpeg_arm_dylib

mkdir -p $LIB_DIR/png_arm_dylib

mkdir -p $LIB_DIR/tiff_arm_dylib

mkdir -p $JPEG_LIB_DIR/lib #we don't need bin/ and share/

mkdir -p $JPEG_LIB_DIR/include

mkdir -p $PNG_LIB_DIR #libpng manages to create subdirectories by itself with make install

mkdir -p $TIFF_LIB_DIR #libtiff manages to create subdirectories by itself with make install

 

# General folders where you have the iPhone compiler + tools

export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer

# Change this to match for which version of the SDK you want to compile - you can change the number for the version

export SDKROOT=$DEVROOT/SDKs/iPhoneOS3.0.sdk

 

############ HACK #################################

# ImageMagick requires this header, that doesn't exist for the iPhone

# Just copying it make things compile/work (more testing needed)

sudo cp /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr/include/crt_externs.h \

$SDKROOT/usr/include/crt_externs.h

############ END - HACK #############################

 

#######################################################

############ PNG ###########################

#######################################################

 

cd $PNG_DIR

 

LIBPATH_png=libpng12.a

 

#######################################################

############ ARM ###########################

#######################################################

 

U_CC=$CC

U_CFLAGS=$CFLAGS

U_LD=$LD

U_LDFLAGS=$LDFLAGS

U_CPP=$CPP

U_CPPFLAGS=$CPPFLAGS

 

export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/4.0.1/include/ -I$SDKROOT/usr/include/"

export CFLAGS="$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT -I$SDKROOT/usr/include -L$SDKROOT/usr/lib/"

export CPP="/usr/bin/cpp $CPPFLAGS"

export LDFLAGS="-L$SDKROOT/usr/lib/"

 

./configure prefix=$PNG_LIB_DIR --enable-shared --enable-static \

CC=$DEVROOT/usr/bin/arm-apple-darwin9-gcc-4.0.1 LD=$DEVROOT/usr/bin/ld --host=arm-apple-darwin

 

make

make install

 

# cp the static + shared library

cp $PNG_LIB_DIR/lib/$LIBPATH_png $LIB_DIR/libpng.a.arm

cp $PNG_LIB_DIR/lib/libpng12.0.dylib $LIB_DIR/png_arm_dylib/libpng.dylib

 

make distclean

 

#######################################################

############ INTEL ###########################

#######################################################

 

# Use default environment

export CC=$U_CC

export CFLAGS=$U_CFLAGS

export LD=$U_LD

export LDFLAGS=$U_LDFLAGS

export CPP=$U_CPP

export CPPFLAGS=$U_CPPFLAGS

 

LIBPATH_png=libpng12.a

 

./configure prefix=$PNG_LIB_DIR --enable-shared --enable-static

 

make

make install

 

# cp the static library

cp $PNG_LIB_DIR/lib/$LIBPATH_png $LIB_DIR/libpng.a.i386

# cp the include/* files

cp $PNG_LIB_DIR/include/libpng12/* $LIB_DIR/include/png/

 

make distclean

 

# combine the static libraries for i386 and arm

$DEVROOT/usr/bin/lipo -arch arm $LIB_DIR/libpng.a.arm -arch i386 $LIB_DIR/libpng.a.i386 -create -output $LIB_DIR/libpng.a

 

#######################################################

############ JPEG ###########################

#######################################################

 

cd $JPEG_DIR

 

LIBPATH_jpeg=libjpeg.a

LIBNAME_jpeg=`basename $LIBPATH_jpeg`

 

#######################################################

############ ARM ###########################

#######################################################

 

U_CC=$CC

U_CFLAGS=$CFLAGS

U_LD=$LD

U_LDFLAGS=$LDFLAGS

U_CPP=$CPP

U_CPPFLAGS=$CPPFLAGS

 

export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/4.0.1/include/ -I$SDKROOT/usr/include/"

export CFLAGS="$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT -I$SDKROOT/usr/include -L$SDKROOT/usr/lib/"

export CPP="/usr/bin/cpp $CPPFLAGS"

export LDFLAGS="-L$SDKROOT/usr/lib/"

 

./configure prefix=$JPEG_LIB_DIR --enable-shared --enable-static \

CC=$DEVROOT/usr/bin/arm-apple-darwin9-gcc-4.0.1 LD=$DEVROOT/usr/bin/ld --host=arm-apple-darwin

 

make

make install-lib

 

# cp the static + shared library

cp $JPEG_LIB_DIR/lib/$LIBPATH_jpeg $LIB_DIR/$LIBNAME_jpeg.arm

cp $JPEG_LIB_DIR/lib/libjpeg.62.0.0.dylib $LIB_DIR/jpeg_arm_dylib/libjpeg.dylib

 

make distclean

 

#######################################################

############ INTEL ###########################

#######################################################

 

# Use default environment

export CC=$U_CC

export CFLAGS=$U_CFLAGS

export LD=$U_LD

export LDFLAGS=$U_LDFLAGS

export CPP=$U_CPP

export CPPFLAGS=$U_CPPFLAGS

 

./configure prefix=$JPEG_LIB_DIR --enable-shared --enable-static

 

make

make install-lib

 

# cp the static library

cp $JPEG_LIB_DIR/lib/$LIBPATH_jpeg $LIB_DIR/$LIBNAME_jpeg.i386

# cp the include/* files

cp $JPEG_LIB_DIR/include/*.h $LIB_DIR/include/jpeg/

 

make distclean

 

# combine the static libraries for i386 and arm

$DEVROOT/usr/bin/lipo -arch arm $LIB_DIR/$LIBNAME_jpeg.arm -arch i386 $LIB_DIR/$LIBNAME_jpeg.i386 -create -output $LIB_DIR/$LIBNAME_jpeg

 

########################################################

############# TIFF ############################

########################################################

 

cd $TIFF_DIR

 

LIBPATH_tiff=libtiff.a

LIBNAME_tiff=`basename $LIBPATH_tiff`

 

#######################################################

############ ARM ###########################

#######################################################

 

U_CC=$CC

U_CFLAGS=$CFLAGS

U_LD=$LD

U_LDFLAGS=$LDFLAGS

U_CPP=$CPP

U_CPPFLAGS=$CPPFLAGS

 

export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/4.0.1/include/ -I$SDKROOT/usr/include/"

export CFLAGS="$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT -I$SDKROOT/usr/include -L$SDKROOT/usr/lib/"

export CPP="/usr/bin/cpp $CPPFLAGS"

export LDFLAGS="-L$SDKROOT/usr/lib/"

 

./configure prefix=$TIFF_LIB_DIR CC=$DEVROOT/usr/bin/arm-apple-darwin9-gcc-4.0.1 \

LD=$DEVROOT/usr/bin/ld --host=arm-apple-darwin --disable-cxx

 

make

make install

 

# cp the static + shared library

cp $TIFF_LIB_DIR/lib/$LIBPATH_tiff $LIB_DIR/$LIBNAME_tiff.arm

cp $TIFF_LIB_DIR/lib/libtiff.3.dylib $LIB_DIR/tiff_arm_dylib/libtiff.dylib

 

make distclean

 

#######################################################

############ INTEL ###########################

#######################################################

 

# Use default environment

export CC=$U_CC

export CFLAGS=$U_CFLAGS

export LD=$U_LD

export LDFLAGS=$U_LDFLAGS

export CPP=$U_CPP

export CPPFLAGS=$U_CPPFLAGS

 

./configure prefix=$TIFF_LIB_DIR

 

make

make install

 

# cp the static library

cp $TIFF_LIB_DIR/lib/$LIBPATH_tiff $LIB_DIR/$LIBNAME_tiff.i386

# cp the include/* files

cp $TIFF_LIB_DIR/include/*.h $LIB_DIR/include/tiff/

 

make distclean

 

# combine the static libraries for i386 and arm

$DEVROOT/usr/bin/lipo -arch arm $LIB_DIR/$LIBNAME_tiff.arm -arch i386 $LIB_DIR/$LIBNAME_tiff.i386 -create -output $LIB_DIR/$LIBNAME_tiff

 

 

#######################################################

############ IMAGEMAGICK #######################

#######################################################

 

cd $IM_DIR

 

# static library that will be generated

LIBPATH_static=$IM_LIB_DIR/lib/libMagickCore.a

LIBNAME_static=`basename $LIBPATH_static`

LIBPATH_static2=$IM_LIB_DIR/lib/libMagickWand.a

LIBNAME_static2=`basename $LIBPATH_static2`

 

#######################################################

############ ARM ###########################

#######################################################

 

# Save relevant environment

U_CC=$CC

U_CFLAGS=$CFLAGS

U_LD=$LD

U_LDFLAGS=$LDFLAGS

U_CPP=$CPP

U_CPPFLAGS=$CPPFLAGS

 

export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/4.0.1/include/ -I$SDKROOT/usr/include/"

export CFLAGS="$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT -I$SDKROOT/usr/include -I$LIB_DIR/include"

export LDFLAGS="-L$LIB_DIR/jpeg_arm_dylib/ -L$LIB_DIR/png_arm_dylib/ -L$LIB_DIR/tiff_arm_dylib/ -L$SDKROOT/usr/lib/"

export CPP="/usr/bin/cpp $CPPFLAGS"

 

 

# configure to have the static libraries and make

./configure prefix=$IM_LIB_DIR CC=$DEVROOT/usr/bin/arm-apple-darwin9-gcc-4.0.1 LD=$DEVROOT/usr/bin/ld --host=arm-apple-darwin \

--disable-largefile --with-quantum-depth=8 --without-magick-plus-plus --without-perl --without-x --without-freetype \

--disable-shared --without-openexr --without-lqr  --without-jp2 --without-lcms --without-fftw

 

# compile ImageMagick

make

make install

 

# copy the CORE + WAND libraries - ARM version

cp $LIBPATH_static $LIB_DIR/$LIBNAME_static.arm

cp $LIBPATH_static2 $LIB_DIR/$LIBNAME_static2.arm

 

# clean the ImageMagick build

make distclean

 

#######################################################

############ INTEL ###########################

#######################################################

 

# Use default environment

export CC=$U_CC

export CFLAGS=$U_CFLAGS

export LD=$U_LD

export LDFLAGS=$U_LDFLAGS

export CPP=$U_CPP

export CPPFLAGS=$U_CPPFLAGS

 

# configure with standard parameters

./configure prefix=$IM_LIB_DIR --without-magick-plus-plus --without-perl --without-x --without-freetype --disable-shared \

--without-openexr --without-lqr --without-jp2 --without-lcms --without-fftw

 

# compile ImageMagick

make

make install

 

# copy the CORE + WAND libraries - INTEL version

cp $LIBPATH_static $LIB_DIR/$LIBNAME_static.i386

cp $LIBPATH_static2 $LIB_DIR/$LIBNAME_static2.i386

 

# copy the wand/ + core/ headers

cp $IM_LIB_DIR/include/ImageMagick/magick/* $LIB_DIR/include/magick/

cp $IM_LIB_DIR/include/ImageMagick/wand/* $LIB_DIR/include/wand/

 

# clean the ImageMagick build

make distclean

 

# combine the two generated libraries to be used both in the simulator and in the device

$DEVROOT/usr/bin/lipo -arch arm $LIB_DIR/$LIBNAME_static.arm -arch i386 $LIB_DIR/$LIBNAME_static.i386 -create -output $LIB_DIR/$LIBNAME_static

$DEVROOT/usr/bin/lipo -arch arm $LIB_DIR/$LIBNAME_static2.arm -arch i386 $LIB_DIR/$LIBNAME_static2.i386 -create -output $LIB_DIR/$LIBNAME_static2


Currently rated 5.0 by 3 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

General

Disable sleeping

by alex 28. December 2009 15:48

[UIApplication sharedApplication].idleTimerDisabled = YES;

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Determine the device running an application

by alex 9. December 2009 09:33

NSString *deviceType = [UIDevice currentDevice].model;

 

if([deviceType isEqualToString:@"iPhone"])

// it's an iPhone


Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Scroll UITableView to the top

by alex 4. December 2009 16:24

//Move to the top of UITableView

NSIndexPath *i = [NSIndexPath indexPathForRow:0 inSection:0];

[namesTableView scrollToRowAtIndexPath:i atScrollPosition:UITableViewScrollPositionNone animated:YES];


Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Create screenshot in runtime (inside UIView)

by alex 7. November 2009 10:35

UIGraphicsBeginImageContext(self.bounds.size);

[self.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

General

Get list of files

by alex 7. November 2009 10:20

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

 

//try to get list of files from new folder

NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager]

  enumeratorAtPath:documentsDirectory];

 

NSString *pname;

while (pname = [direnum nextObject])

{

if ([[pname pathExtension] isEqualToString:@"rtfd"])

{

/* don't enumerate this directory */

[direnum skipDescendents];

}

else

{

/* ...process file here... */

NSLog(pname);

}

}

Currently rated 4.5 by 2 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Hide keyboard when pressing Done

by alex 26. October 2009 12:01

// You need to add this method to your controller class

- (BOOL)textFieldShouldReturn:(UITextField *)textField{

[textField resignFirstResponder];

return YES;

}


Currently rated 4.7 by 3 people

  • Currently 4.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Flip UIView

by alex 16. October 2009 02:15

-(IBAction)flipAction{

NSLog(@"flip");

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:1];

[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight

  forView:self.view cache:YES];

if ([discoView superview]){

[discoView removeFromSuperview];

[termsView addSubview:flipButton];

[self.view addSubview:termsView];

}

else

{

[termsView removeFromSuperview];

[self.view addSubview:discoView];

[discoView addSubview:flipButton];

}

[UIView commitAnimations];

}


Currently rated 2.0 by 1 people

  • Currently 2/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Get pixel information from UIImage

by alex 4. October 2009 02:46

UIImage *uiImage = [UIImage imageNamed:@"myimage.png"];

CGImageRef image = uiImage.CGImage;

NSUInteger width = CGImageGetWidth(image);

NSUInteger height = CGImageGetHeight(image);

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

UInt8 * rawData = malloc(height * width * 4);

 

int bytesPerPixel = 4;

int bytesPerRow = bytesPerPixel * width;

 

NSUInteger bitsPerComponent = 8;

CGContextRef context1 = CGBitmapContextCreate(

rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace,

kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big

);

CGColorSpaceRelease(colorSpace);

 

CGContextDrawImage(context1, CGRectMake(0, 0, width, height), image);

CGContextRelease(context1);

 

//Now to get byte for ppixel you need to call

//rawData[x * bytesPerRow  + y * bytesPerPixel]


Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen