Configure Tomcat servers for Maven:
Open ~/.m2/settings.xml (if it doesn't exist, create it), add the following lines:
Live, Learn, Work And Share
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<!-- Omit the irrelevant information here -->
<server>
<id>Tomcat7</id>
<username>tomcat</username>
<!-- Change this password -->
<password>mypassword</password>
</server>
<!-- Omit the irrelevant information here -->
</servers>
</settings>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<server>Tomcat7</server>
<!-- Change the name of your server -->
<url>http://example.com:8080/manager/text</url>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<packagingExcludes>WEB-INF/web.xml</packagingExcludes>
</configuration>
</plugin>
<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="tomcat" password="mypassword" roles="manager-gui,manager-script"/>
</tomcat-users>
NSPrintOperation*fPrintOperation = [NSPrintOperation printOperationWithView:viewToPrint];
[fPrintOperation.printInfo setOrientation:NSLandscapeOrientation];
[fPrintOperation.printPanel setOptions:NSPrintPanelShowsPreview|NSPrintPanelShowsPaperSize|NSPrintPanelShowsPageRange|NSPrintPanelShowsCopies|NSPrintPanelShowsOrientation];
[NSPrintOperation setCurrentOperation:fPrintOperation];
if(fPrintOperation.printPanel.runModal == NSOKButton){
NSPrintInfo*printInfo = [fPrintOperation printInfo];
if( [printInfo orientation] == NSPortraitOrientation){
//Do something
}else{
//Do something
}
[[NSPrintOperation currentOperation] cleanUpOperation];
NSPrintOperation *rPrintOperation = [NSPrintOperation printOperationWithView:viewToPrint printInfo:printInfo];
[rPrintOperation setShowsPrintPanel:NO];
[rPrintOperation runOperation];
}else{
[[NSPrintOperation currentOperation] cleanUpOperation];
}
@interface NSColor(Ext) +(NSColor*) newColorFromRGBString:(NSString*) rgb; @end
@implementation NSColor(Ext) +(NSColor*) newColorFromRGBString:(NSString*) rgb{ NSColor*result= nil; unsigned colorValue=0; unsigned char r,g, b; if (nil != rgb) { NSScanner* scanner = [NSScanner scannerWithString:rgb]; // ignore error (void) [scanner scanHexInt:&colorValue]; } r = (unsigned char)(colorValue >> 16); g = (unsigned char)(colorValue >> 8); // masks off high bits b = (unsigned char)(colorValue); result = [NSColor colorWithCalibratedRed:(CGFloat)r / 0xff green:(CGFloat)g / 0xff blue:(CGFloat)b / 0xff alpha:1.0f]; return result; } @end
@interface AppDelegate:NSObject @property (strong) NSColorSpace*colorSpace; @end
#import <ApplicationServices/ApplicationServices.h> @interface AppDelegate() +(CGColorSpaceRef)CreateDisplayColorSpace; -(void)updateColorSpace; -(void)registerNotifications; @end @implementation AppDelegate //Disable deprecated warning #pragma GCC diagnostic ignored "-Wdeprecated-declarations" +(CGColorSpaceRef)CreateDisplayColorSpace{ CMProfileRef sysprof = NULL; CGColorSpaceRef dispColorSpace = NULL; // Get the Systems Profile for the main display if (CMGetSystemProfile(&sysprof) == noErr) { // Create a colorspace with the systems profile dispColorSpace = CGColorSpaceCreateWithPlatformColorSpace(sysprof); // Close the profile CMCloseProfile(sysprof); } return dispColorSpace; } //Enable deprecated warning #pragma GCC diagnostic warning "-Wdeprecated-declarations" -(void)registerNotifications { NSDistributedNotificationCenter *center; center = [NSDistributedNotificationCenter defaultCenter]; [center addObserver:self selector:@selector(updateColorSpace) name:kCMDeviceUnregisteredNotification object:nil]; [center addObserver:self selector:@selector(updateColorSpace) name:kCMDefaultDeviceNotification object:nil]; [center addObserver:self selector:@selector(updateColorSpace) name:kCMDeviceProfilesNotification object:nil]; [center addObserver:self selector:@selector(updateColorSpace) name:kCMDefaultDeviceProfileNotification object:nil]; } -(void)updateColorSpace{ CGColorSpaceRef csr = [AppDelegate CreateDisplayColorSpace]; self.colorSpace = [[NSColorSpace alloc] initWithCGColorSpace:csr]; CGColorSpaceRelease(csr); }
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification{
[self registerNotifications];[self updateColorSpace];} @end
@implementation NSColor(Ext) +(NSColor*) newColorFromRGBString:(NSString*) rgb{ NSColor* result = nil; unsigned colorValue = 0; unsigned char r, g, b; if (nil != rgb) { NSScanner* scanner = [NSScanner scannerWithString:rgb]; // ignore error (void) [scanner scanHexInt:&colorValue]; } r = (unsigned char)(colorValue >> 16); g = (unsigned char)(colorValue >> 8); // masks off high bits b = (unsigned char)(colorValue); CGFloat components[4] = {(CGFloat)r / 0xff,(CGFloat)g / 0xff,(CGFloat)b / 0xff,1.0f}; return [NSColor colorWithColorSpace:(AppDelegate*)([NSApplication shareApplication].delegate).colorSpace components:components count:4]; } @end
~/Library/Developer/Xcode/UserData/FontAndColorThemes
public boolean isPowerOfTwo(int n){
if( 0 == n|| 1 == n ) return true;
int x = n / 2;
int y = n%2;
if (1 == y) return false;
return isPowerOfTwo(x);
}
Hoặc chúng ta không cần viết đệ qui như sau:
public boolean isPowerOfTwo(int n){
boolean ret;
if( 0 == n|| 1 == n ){
ret = false;
}else{
int x = n / 2;
int y = n%2;
while ( x > 0){
if (1 == y) {
ret = false;
break;
};
x = x / 2;
y = x%2;
}
ret = true;
}
return ret;
}
Sau đây là cách nhanh hơn sử dụng hàm logarit:
public boolean isPowerOfTwo(int n){
double logn2 = Math.log(n)/Math.log(2);
int logn2i = (int) (Math.floor(logn2));
if(logn2-logn2i==0)
return true;
else
return false;
}
Tuy nhiên nếu chúng ta để ý một chút chúng ta sẽ có cách kiểm tra nhanh nhất. Các số là luỹ thừa của 2 đều có 1 chữ số 1 trong biểu diễn nhị phân của chúng. Ví dụ số
public boolean isPowerOfTwo(int n){
return ((n!=0) && (n&(n-1))==0);
}
Thật ngắn gọn, đơn giản phải không các bạn!
<div style="width: 100%;height:500px;">Sau đây là một ví dụ:
<object data="http://www.example.com/visorFreemind.swf" height="100%" type="application/x-shockwave-flash" width="100%">
<param name="movie" value="http://www.example.com/visorFreemind.swf" />
<param name="quality" value="high" />
<param name="flashvars" value="initLoadFile=http://www.example.com/example.mm&openUrl=_self&startCollapsedToLevel=3&maxNodeWidth=200&mainNodeShape=elipse&justMap=false&defaultToolTipWordWrap=200&offsetX=middle&offsetY=middle&buttonsPos=top&min_alpha_buttons=20&max_alpha_buttons=100&scaleTooltips=false&bgcolor=0xF8FBFC" />
</object>
</div>
// character literals.
NSNumber *theLetterZ = @'Z'; // equivalent to [NSNumber numberWithChar:'Z']
// integral literals.
NSNumber *fortyTwo = @42; // equivalent to [NSNumber numberWithInt:42]
NSNumber *fortyTwoUnsigned = @42U; // equivalent to [NSNumber numberWithUnsignedInt:42U]
NSNumber *fortyTwoLong = @42L; // equivalent to [NSNumber numberWithLong:42L]
NSNumber *fortyTwoLongLong = @42LL; // equivalent to [NSNumber numberWithLongLong:42LL]
// floating point literals.
NSNumber *piFloat = @3.141592654F; // equivalent to [NSNumber numberWithFloat:3.141592654F]
NSNumber *piDouble = @3.1415926535; // equivalent to [NSNumber numberWithDouble:3.1415926535]
// BOOL literals.
NSNumber *yesNumber = @YES; // equivalent to [NSNumber numberWithBool:YES]
NSNumber *noNumber = @NO; // equivalent to [NSNumber numberWithBool:NO]
#ifdef __cplusplus
NSNumber *trueNumber = @true; // equivalent to [NSNumber numberWithBool:(BOOL)true]
NSNumber *falseNumber = @false; // equivalent to [NSNumber numberWithBool:(BOOL)false]
#endif
Lưu ý:
NSMutableArray *array = ...;
NSUInteger idx = ...;
id newObject = ...;
id oldObject = array[idx];
array[idx] = newObject; // replace oldObject with newObject
NSMutableDictionary *dictionary = ...;
NSString *key = ...;
oldObject = dictionary[key];
dictionary[key] = newObject; // replace oldObject with newObject
- (void) viewWillAppear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
}
- (void) viewWillDisappear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillDisappear:animated];
}