GET http://download.finance.yahoo.com/d/quotes.csv?f=<FIELDS>&s=<SYMBOL1,SYMBOL2,…>
$ curl 'http://download.finance.yahoo.com/d/quotes.csv?f=snl1d1t1ab&s=USDEUR=X,USDJPY=X'
"USDEUR=X","USD/EUR",0.8845,"6/11/2015","6:15am",0.8845,0.8845
| // 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); |
| // 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]; | |
| } |
| 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 |
| module.exports = function(a, b) { | |
| const vA = /^(\d+)\.(\d+)(?:\.(\d+))?(.*)$/.exec(a), | |
| vB = /^(\d+)\.(\d+)(?:\.(\d+))?(.*)$/.exec(b) | |
| // Invalid version number go at the end | |
| if (vA == null) return -1 | |
| if (vB == null) return 1 | |
| // Numeric version components | |
| const nA = (vA[1] >>> 0) * 10000 + (vA[2] >>> 0) * 100 + (vA[3] >>> 0), |
| /** | |
| * Parse a string that contains minimal <b>...</b> HTML-like markup, and | |
| * returns an attributed string with those parts styled. | |
| * | |
| * This allows to localize attributed strings without having to serialize | |
| * RTF documents with set-in-stone styling. | |
| * | |
| * @param markup Source string. | |
| * @param genericAttributes Generic attributes used for the whole string. | |
| * @param namedAttributes A `NSictionary` whose keys are tag names (e.g. "b", "i", etc), |
| NSData *provisioningProfile = nil; | |
| NSData *raw = [NSData dataWithContentsOfURL:[NSBundle.mainBundle URLForResource:@"embedded" withExtension:@"mobileprovision"]]; | |
| char *start = memmem(raw.bytes, | |
| raw.length, | |
| "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0", | |
| 47); | |
| if (start) { | |
| char *end = memmem(start, | |
| (uintptr_t)start - raw.length, | |
| "</plist>", |
| // ES6 strftime(3) function that supports FDxcAaBbCdemuwYynt% for en_US only | |
| // (only for dates, not datetimes) | |
| Date.prototype.format = function(f) { | |
| const t=this,p=(v,f)=>v.toString().length==1?f+v:v,Y=t.getFullYear(),mo=t.getMonth()+1,dm=t.getDate(),u=t.getDay(),A=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'][u%7],B=['January','February','March','April','May','June','July','August','September','October','November','December'][mo-1] | |
| return ['%Y-%m-%d','%m/%d/%y','%m/%d/%Y','%a %b %e %Y',A,A.slice(0,3),B,B.slice(0,3),Y/100|0,p(dm,'0'),p(dm,' '),p(mo,'0'),u,u%7,Y,Y%100,'\n','\t','%'].reduce((_, s, i)=>_.replace(new RegExp('%'+'FDxcAaBbCdemuwYynt%'[i],'g'),s),f) | |
| } | |
| // Unit tests | |
| !() => { | |
| var date = new Date('2016-04-02'), assert = require('assert') |
| #import "AppDelegate.h" | |
| /* | |
| * Note our application delegate doesn't implement -applicationDidEnterBackground:, but it doesn't matter. | |
| */ | |
| @implementation AppDelegate | |
| - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
| NSLog(@"Original -application:didFinishLaunchingWithOptions: (self.class is %@)", self.class); | |
| return YES; | |
| } |