Skip to content

Instantly share code, notes, and snippets.

View jcayzac's full-sized avatar

Julien Cayzac jcayzac

View GitHub Profile
@jcayzac
jcayzac / git-clone-tags.sh
Last active August 29, 2015 14:17
git: import remote tags into a local bare repository
#!/usr/bin/env bash
set -e -u -o pipefail
# Similar to git clone --shallow, except it creates a local shallow
# tag for every remote tag and doesn't clone any branch
#
# @param $1 [Required] Git remote
r="$1"
p="${r##*/}"
p="${p%.git*}.git"
NSData *msg = [@"This is a message" dataUsingEncoding:NSUTF8StringEncoding];
NSData *key = [@"the password" dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"Unencrypted message: [%@]", msg);
uint8_t iv[kCCBlockSizeAES128];
if (SecRandomCopyBytes(kSecRandomDefault, sizeof(iv), iv))
{
// ERROR
@jcayzac
jcayzac / dependencies.m
Created February 18, 2015 00:45
Have a block operation depend on a network operation (AFNetworking)
// The problem: AFNetworking calls the operation's completion block asynchronously, so it breaks `-[NSOperation addDependency:]` order as the dependent is started *before* the dependency's completion block.
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
__block NSOperation* blockOperation = nil;
void (^networkOperationHandler)(NSOperation *, id) = ^(NSOperation *operation, id __unused unused) {
if (operation.cancelled)
{
NSLog(@"networkOperation: networkOperation cancelled!");
[blockOperation cancel];
}
@jcayzac
jcayzac / isBeingDebugged.m
Last active August 29, 2015 14:11
Detect if iOS app is being debugged/instrumented
// attempt 1
static BOOL isBeingDebugged()
{
static BOOL cachedValue = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
char buffer[2*MAXCOMLEN + 1];
int len = proc_name(getppid(), buffer, 2*MAXCOMLEN);
buffer[len] = 0;
cachedValue = !strncmp(buffer, "debugserver", len);
@jcayzac
jcayzac / cibuild.sh
Last active August 29, 2015 14:08
CI build script for Xcode6.1/iOS8
#!/usr/bin/env bash -e -u -o pipefail
export LANG="en_US.UTF-8"
usage() {
cat <<EOT
NAME
${0##*/} -- Build iOS stuff.
SYNOPSIS
@jcayzac
jcayzac / MakeIPA
Created October 23, 2014 04:29
PackageApplication for Xcode6+
#!/usr/bin/env bash
set -e -u -o pipefail
export LANG="en_US.UTF-8"
cat <<EOT
Creating IPA with the following parameters:
Application path: "${1:-}"
Code signing identity: "${2:-}"
Provisioning profile path: "${3:-}"
@jcayzac
jcayzac / reset-sim.sh
Last active June 23, 2016 03:04
How to reset the iOS simulator properly
# source this in your Bash scripts
reset-sim() {
printf 'Close the frontend app if needed…'
killall iOS\ Simulator 2>&- && sleep 5 || true
printf ' Done.\n'
declare SIM_OS SIM SIM_ID
while read SIM
do
// Only called on iOS<8
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation __unused)toInterfaceOrientation duration:(NSTimeInterval __unused)duration {
[self _beforeOrientationChange];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation __unused)fromInterfaceOrientation {
[self _afterOrientationChange];
}
// Only called on iOS>8
@jcayzac
jcayzac / XXXLocation.m
Created October 16, 2014 05:41
iOS location updates listener example
@import Foundation;
@import CoreLocation;
////////////////////////////////////////////////////////////////////////////
@interface XXXLocation : NSObject<CLLocationManagerDelegate>
@property (nonatomic) BOOL trackingEnabled;
@property (nonatomic) BOOL updating;
@property (nonatomic, strong) CLLocationManager *locationManager;
@end
# assuming SAR is 1:1,
SRC=Foo.mp4
SRC_WIDTH=1916
SRC_HEIGHT=852
DST_WIDTH=720
DST_HEIGHT=480
DST_ASPECT=16/9
DST_FPS=24000/1001
DST_RATE=4100k