Skip to content

Instantly share code, notes, and snippets.

View YoniTsafir's full-sized avatar

Yoni Tsafir YoniTsafir

View GitHub Profile
@YoniTsafir
YoniTsafir / gist:4770019
Created February 12, 2013 13:52
A useful method to mask a view according to an alpha channel to an image. Example usage: place the masking image using IB (make it hidden), and dynamically create a view around it, that you mask using this method.
+ (void)maskView:(UIView *)targetView withImageView:(UIImageView *)maskingImageView {
CALayer *maskingLayer = [CALayer layer];
maskingLayer.frame = CGRectMake(maskingImageView.frame.origin.x - targetView.frame.origin.x,
maskingImageView.frame.origin.y - targetView.frame.origin.y,
maskingImageView.frame.size.width,
maskingImageView.frame.size.height);
maskingLayer.contents = (id)maskingImageView.image.CGImage;
targetView.layer.mask = maskingLayer;
}
@YoniTsafir
YoniTsafir / appdir_alias.sh
Last active December 28, 2015 03:09
A bash function that takes you to the directory of an app running in iOS SImulator. Add to your bash aliases file. Usage: appdir <AppName>
appdir() {
dir=$(ps ax | grep $1.app | grep -v grep | grep -v AppCode | awk '{print "\""$5" "$6" "$7"\""} ' | sed "s/$1\.app\/$1//g")
eval cd "$dir"
}
@YoniTsafir
YoniTsafir / A.h
Created May 29, 2015 09:59
Importing Swift code from Objective-C in a Test Target - It's Possible!
@interface A : NSObject
- (int)foo;
@end
@YoniTsafir
YoniTsafir / TensorflowAndroidSample.java
Created March 29, 2017 11:35
TensorFlow Android Sample Code
import org.tensorflow.contrib.android.TensorFlowInferenceInterface;
/** One time initialization: */
TensorFlowInferenceInterface tensorflow = new TensorFlowInferenceInterface();
tensorflow.initializeTensorFlow(getAssets(), "file:///android_asset/model.pb");
/** Continuous inference (floats used in example, can be any primitive): */
// loading new input
tensorflow.fillNodeFloat("input:0", INPUT_SHAPE, input); // INPUT_SHAPE is an int[] of expected shape, input is a float[] with the input data