composite colors: CALayer and blend mode on iPhone

I managed to get the affect of compositing multiple CALayers by drawing them directly into a UIView’s graphics context. -(void)drawRect:(CGRect)rect { CGContextRef c = UIGraphicsGetCurrentContext(); CGContextSetBlendMode(c, kCGBlendModeDifference); [myLayer drawInContext:c]; } BTW, I did not add the layers as sublayers of the view’s layer (that is I never called [myView.layer addSublayer:myLayer])

Find the most frequent value by row

Something like : apply(df,1,function(x) names(which.max(table(x)))) [1] “red” “yellow” “green” In case there is a tie, which.max takes the first max value. From the which.max help page : Determines the location, i.e., index of the (first) minimum or maximum of a numeric vector. Ex : var4 <- c(“yellow”,”green”,”yellow”) df <- data.frame(cbind(id, var1, var2, var3, var4)) > … Read more

Toggle airplane mode in Android

This answer contains code necessary to do this. Also make sure you have the WRITE_SETTINGS permission. Adapted from Controlling Airplane Mode: // read the airplane mode setting boolean isEnabled = Settings.System.getInt( getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 1; // toggle airplane mode Settings.System.putInt( getContentResolver(), Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1); // Post an intent to reload Intent … Read more