Skip to content

Instantly share code, notes, and snippets.

View benvium's full-sized avatar

Ben Clayton benvium

  • www.calvium.com
  • Bristol, UK
View GitHub Profile
@benvium
benvium / process.sh
Created April 19, 2012 18:42
Mac OSX Bash Script to convert tree of images to tree of retina and normal images. for Apple iOS iPhone/iPad
#!/bin/sh
echo "This script will take an input folder full of images and assuming they're all retina sized, output the second folder to have retina and standard sized images."
if [ ! $# == 2 ]; then
echo "Usage: $0 in out"
exit
fi
if [ ! -d $1 ]
@benvium
benvium / Live template
Created April 21, 2012 08:13
AppCode Live Template to generate a UIViewController delegate
Variables set as:
name expression default value
---------------------------------
class CLASS
class2 decapitalize(class)
---------------------------------
@class $class$;
@benvium
benvium / PlayerDetailsViewController.h
Created April 21, 2012 13:15
Get the destination ViewController from an iOS5 StoryBoard segue
// From http://stackoverflow.com/questions/8041237/how-to-set-the-delegate-with-a-storyboard
#import <Foundation/Foundation.h>
@interface UIStoryboardSegue (topLevelDestinationViewController)
@property (readonly) id topLevelDestinationViewController;
@end
@benvium
benvium / installMobileProvisionFile.sh
Created May 1, 2012 15:14
This script installs a .mobileprovision file via bash (no GUI session needed)
#!/bin/sh
# 2012 - Ben Clayton (benvium). Calvium Ltd
# Found at https://gist.github.com/2568707
#
# This script installs a .mobileprovision file without using Xcode. Unlike Xcode, it'll
# work over SSH.
#
# Requires Mac OS X (I'm using 10.7 and Xcode 4.3.2)
#
@benvium
benvium / sendFileFromDocumentFolderViaEmail.m
Created May 11, 2012 08:53
Sending a file as an attachment via email from an iOS app. Add to a ViewController subclass
// NOTE YOU MUST ADD THE FRAMEWORK 'MessageUI' to your project.
// MyViewController.h
//-------------------
#import <MessageUI/MessageUI.h>
@interface MyViewController : UIViewController <MFMailComposeViewControllerDelegate>
// MyViewController.m
@benvium
benvium / kaleidoscope.html
Created August 17, 2012 09:57
A Pure CSS3 Kaleidoscope. Demonstrates using a mask image defined using SVG, and CSS3 transforms.
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<style>
.slice {
background-image: url(http://upload.wikimedia.org/wikipedia/commons/8/89/Swiss_cheese_cubes.jpg);
position: absolute;
left: 0;
@benvium
benvium / errors.m
Created August 17, 2012 10:09
The correct way to use NSError objects in your Objective-C Code
// A function that returns an object or nil if there's an error.
- (NSObject*) doSomethingComplexAndReturnObject:(NSString*) input error:(NSError**) error {
// do some work..
BOOL itWorked = YES;
if (itWorked) {
return [[NSObject alloc] init]; // Do better memory management than this please.
} else {
*error = [NSError errorWithDomain:@"com.mycompany.myapp" code:14 userInfo:[NSDictionary dictionaryWithObject:@"My error message" forKey:NSLocalizedDescriptionKey]];
@benvium
benvium / smartReadFile.php
Created September 19, 2012 12:08
PHP File to allow seeking in HTML5 <audio> tag. NOTE: I did not write this, check links in code for credits.
<?php
/**
* Reads the requested portion of a file and sends its contents to the client with the appropriate headers.
*
* This HTTP_RANGE compatible read file function is necessary for allowing streaming media to be skipped around in.
*
* @param string $location
* @param string $filename
* @param string $mimeType
* @return void
@benvium
benvium / example.js
Created September 19, 2012 12:15
Example HTML5 Audio usage. Notes of what doesn't work if you *DON'T* have a streaming server.
var url = "path/to/my/audio.mp3";
var ap = new window.Audio();
var isLoaded = false;
ap.addEventListener('canplay', function () {
isLoaded = true;
console.log(url.split("/").pop() + " loaded");
this.play();
}, false);
@benvium
benvium / forcePortrait.m
Created September 24, 2012 14:04
Force iOS 6 app portrait only (add to a UIViewController subclass).
/* in iOS 5
// Force app to be portrait-only
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
// iOS 6 interface orientation support. Only rotate on iPad.
- (BOOL)shouldAutorotate {