Sunday, April 2, 2017

[Google Cloud] Upload Cron using Eclipse

1. Create cron.xml and put it on src/main/webapp/WEB-INF:

<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
  <cron>
    <url>/tasks/summary</url>
    <target>beta</target>
    <description>daily summary job</description>
    <schedule>every 24 hours</schedule>
  </cron>
</cronentries>
2. And change pom.xml to:

<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.maven.plugin.version}</version>
<configuration>
           <deployables>
             <param>target/appengine-staging/WEB-INF/appengine-generated/cron.yaml</param>
           </deployables>
                 </configuration>
</plugin>

  Note that cron.yaml is the output staging of cron.xml when deploying.

3. And run command below on Terminal for checking if the deployed works correctly:
mvn appengine:deploy -X

Why not using Eclipse to upload cron?

It seems it is Google Tools issues.

Wednesday, July 27, 2016

[iOS] NSString to hex value

+ (UIColor*)colorFromHex:(NSString*)hexString
{
    // https://github.com/timd/UIColor-HexValues
    
    hexString = [hexString stringByReplacingOccurrencesOfString:@"#" withString:@""];
    
    if ([hexString length] == 3) {
        hexString = [NSString stringWithFormat:@"%@%@%@%@%@%@", 
                     [hexString substringWithRange:NSMakeRange(0, 1)],[hexString substringWithRange:NSMakeRange(0, 1)],
                     [hexString substringWithRange:NSMakeRange(1, 1)],[hexString substringWithRange:NSMakeRange(1, 1)],
                     [hexString substringWithRange:NSMakeRange(2, 1)],[hexString substringWithRange:NSMakeRange(2, 1)]];
    }
    
    if ([hexString length] != 6) {
        return nil;
    }
    
    // Brutal and not-very elegant test for non hex-numeric characters
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[^a-fA-F|0-9]" options:0 error:NULL];
    NSUInteger match = [regex numberOfMatchesInString:hexString options:NSMatchingReportCompletion range:NSMakeRange(0, [hexString length])];
    
    if (match != 0) {
        return nil;
    }
    
    NSRange rRange = NSMakeRange(0, 2);
    NSString *rComponent = [hexString substringWithRange:rRange];
    NSUInteger rVal = 0;
    NSScanner *rScanner = [NSScanner scannerWithString:rComponent];
    [rScanner scanHexInt:(unsigned int *)&rVal];
    float rRetVal = (float)rVal / 254;
    
    
    NSRange gRange = NSMakeRange(2, 2);
    NSString *gComponent = [hexString substringWithRange:gRange];
    NSUInteger gVal = 0;
    NSScanner *gScanner = [NSScanner scannerWithString:gComponent];
    [gScanner scanHexInt:(unsigned int *)&gVal];
    float gRetVal = (float)gVal / 254;
    
    NSRange bRange = NSMakeRange(4, 2);
    NSString *bComponent = [hexString substringWithRange:bRange];
    NSUInteger bVal = 0;
    NSScanner *bScanner = [NSScanner scannerWithString:bComponent];
    [bScanner scanHexInt:(unsigned int *)&bVal];
    float bRetVal = (float)bVal / 254;
    
    return [UIColor colorWithRed:rRetVal green:gRetVal blue:bRetVal alpha:1.0f];
}

Monday, June 8, 2015

[iOS] Making fancy view with border, corner and shadow


self.imageView.layer.borderColor        = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1].CGColor;
self.imageView.layer.borderWidth        = 1;
self.imageView.layer.cornerRadius       = 3.0;
self.imageView.layer.masksToBounds      = YES;
self.imageView.layer.shouldRasterize    = YES;
self.imageView.layer.rasterizationScale = [UIScreen mainScreen].scale;

self.imageViewBG.layer.shadowOffset       = CGSizeMake(1, 1);
self.imageViewBG.layer.shadowRadius       = 1;
self.imageViewBG.layer.shadowOpacity      = 0.1;
self.imageViewBG.layer.cornerRadius       = 3.0;
self.imageViewBG.layer.masksToBounds      = NO;
self.imageViewBG.layer.shouldRasterize    = YES;
self.imageViewBG.layer.rasterizationScale = [UIScreen mainScreen].scale;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.imageViewBG.bounds cornerRadius:3.0];
self.imageViewBG.layer.shadowPath = path.CGPath;