Skip to content

Instantly share code, notes, and snippets.

View hartbit's full-sized avatar
👨‍💻
Swifting, one commit at a time

David Hart hartbit

👨‍💻
Swifting, one commit at a time
  • Atipik Sàrl & Witty Wings SA
  • Geneva, Switzerland
View GitHub Profile
let yetAnotherPoint = (1, -1)
switch yetAnotherPoint {
case let (x, y) where x == y:
println("(\(x), \(y)) is on the line x == y")
case let (x, y) where x == -y:
println("(\(x), \(y)) is on the line x == -y")
case let (x, y):
println("(\(x), \(y)) is just some arbitrary point")
}
// prints "(1, -1) is on the line x == -y"
id mockFileManager = mock([NSFileManager class]);
[given([mockFileManager removeItemAtURL:notNilValue() error:notNilValue()]) willReturnBool:YES];
MKTArgumentCaptor* argument = [MKTArgumentCaptor new];
[verify(mockFileManager) removeItemAtURL:notNilValue() error:[argument capture]];
#import <Foundation/Foundation.h>
#import "ATPInfo.h"
@interface ATPDecorator : NSObject <ATPInfo>
@property (nonatomic, strong, readonly) NSString* fullName;
- (id)initWithInfo:(NSObject<ATPInfo>*)info;
NSFileManager* fileManager = [NSFileManager new];
NSURL* directoryURL = [NSURL fileURLWithPath:@"~/photos"];
NSArray* contents = [fileManager contentsOfDirectoryAtURL:directoryURL includingPropertiesForKeys:@[] options:NSDirectoryEnumerationSkipsHiddenFiles error:NULL];
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"pathExtension == 'jpg' OR pathExtension == 'jpeg'"];
for (NSURL* fileURL in [contents filteredArrayUsingPredicate:predicate]) {
NSURL* rawFileURL = [[fileURL URLByDeletingPathExtension] URLByAppendingPathExtension:@"raw"];
if (![fileManager fileExistsAtPath:[rawFileURL path]]) {
[fileManager removeItemAtURL:fileURL error:NULL];
}
@interface AWRParallaxAnimationController : ECSlidingAnimationController <ECSlidingViewControllerLayout>
@property (nonatomic) CGFloat parallaxFactor;
@end
fatal: Not a git repository: /path/to/repo/.git/modules/Libraries/a-submodule
fatal: 'git status --porcelain' failed in submodule Libraries/another-submodule
@hartbit
hartbit / gist:7195151
Last active December 26, 2015 18:29
RestKit Error
E restkit.network:RKObjectRequestOperation.m:213 GET 'http://REDACTED/apps/CJJeUXEVQ25KNdu5/radios' (200 OK / 0 objects) [request=0.1465s mapping=0.0000s total=0.2118s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded." UserInfo=0xa4dcb20 {NSErrorFailingURLStringKey=http://REDACTED/apps/CJJeUXEVQ25KNdu5/radios, NSLocalizedFailureReason=A 200 response was loaded from the URL 'http://REDACTED/apps/CJJeUXEVQ25KNdu5/radios', which failed to match all (1) response descriptors:
<RKResponseDescriptor: 0xa4bc030 baseURL=http://REDACTED/apps/CJJeUXEVQ25KNdu5/ pathPattern=radios statusCodes=200-299> failed to match: response path 'radios' did not match the path pattern 'radios'., NSLocalizedDescription=No response descriptors match the response loaded., keyPath=null, NSErrorFailingURLKey=http://REDACTED/apps/CJJeUXEVQ25KNdu5/radios, NSUnderlyingError=0xa4dcb80 "No mappable object representations were found at the key paths searched."}
[Test]
public void SimpleTest()
{
var calculator = Substitute.For<ICalculator>();
int z;
calculator.Add(1, 2, out z).Returns(x => { x[2] = 2; return 3; });
calculator.Add(4, 5, out z).Returns(x => { x[2] = 20; return 9; });
Expect(calculator.Add(1, 2, out z), Is.EqualTo(3));
// SetCallback calls an instance of the class' SetCallback method
class ASE_PluginBase
{
public:
ASE_PluginBase();
~ASE_PluginBase();
void SetGameObjectName( const char * sName );
void SetMethodName( const char * sName );
// From library
typedef void (*Callback) ( int nEvent, const char* sMessage );
void SetCallback( Callback * cbk );
// My code
void MyCallback(int nEvent, const char* sMessage) {
// ....
}