Skip to content

Instantly share code, notes, and snippets.

View saiday's full-sized avatar
:shipit:
su su su

Saiday saiday

:shipit:
su su su
View GitHub Profile
#import "ImnotyoursonURLProtocol.h"
#import "User.h"
#import "Article.h"
#import "GenericItem.h"
@implementation ImnotyoursonURLProtocol
+ (BOOL)canInitWithRequest:(NSURLRequest *)request
{
#import <Foundation/Foundation.h>
@interface ImnotyoursonURLProtocol : NSURLProtocol
@end
@saiday
saiday / FFT.java
Created October 19, 2016 09:33
FFT
public class FFT {
int n, m;
// Lookup tables. recompute when size of FFT changes.
double[] cos;
double[] sin;
double[] window;
public FFT(int n) {
@saiday
saiday / UIImage+CornerRadius.m
Created August 9, 2016 06:52
Effective corner radius
- (UIImage *)cutCircleImage {
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);
CGContextRef ctr = UIGraphicsGetCurrentContext();
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
CGContextAddEllipseInRect(ctr, rect);
CGContextClip(ctr);
[self drawInRect:rect];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
@saiday
saiday / FFTManager.m
Created July 13, 2016 13:45
FFT computation
NSError *computationError;
[audioFile readIntoBuffer:buffer frameCount:yourSampleRate / 2 error:&computationError];
if (computationError) {
failure(computationError);
return;
}
@saiday
saiday / FFTManager.m
Last active July 13, 2016 13:37
FFT computation
NSError *computationError;
AVAudioFile *audioFile = [[AVAudioFile alloc] initForReading:[NSURL fileURLWithPath:self.filePath] error:&computationError];
if (computationError) {
failure(computationError);
return;
}
AVAudioFormat *audioFormat = audioFile.processingFormat;
UInt32 audioFrameCount = (UInt32) audioFile.length;
AVAudioPCMBuffer *buffer = [[AVAudioPCMBuffer alloc] initWithPCMFormat:audioFormat frameCapacity:audioFrameCount];
@saiday
saiday / codecov log 68s
Last active February 16, 2016 16:00
codecov log
68.52s$ bash <(curl -s https://codecov.io/bash)
_____ _
/ ____| | |
| | ___ __| | ___ ___ _____ __
| | / _ \ / _` |/ _ \/ __/ _ \ \ / /
| |___| (_) | (_| | __/ (_| (_) \ V /
\_____\___/ \__,_|\___|\___\___/ \_/
5ca7b8c
(url) https://codecov.io
(root) .
@saiday
saiday / codecov log 36s
Last active February 16, 2016 15:56
codecov log
36.79s$ bash <(curl -s https://codecov.io/bash)
_____ _
/ ____| | |
| | ___ __| | ___ ___ _____ __
| | / _ \ / _` |/ _ \/ __/ _ \ \ / /
| |___| (_) | (_| | __/ (_| (_) \ V /
\_____\___/ \__,_|\___|\___\___/ \_/
5ca7b8c
(url) https://codecov.io
(root) .
@saiday
saiday / RxSwiftExample.swift
Last active October 8, 2025 20:20
RxSwift callback chaining
func fetchUserId() -> Observable<String> {
return create{ (observer) -> Disposable in
Client.fetchUserId() { [unowned self]
(userId: String?, err: ErrorType?) -> Void in
if let _ = err{
observer.on(Event.Error(err!))
} else {
observer.on(Event.Next(userId))
observer.on(Event.Completed)
}
@saiday
saiday / promiseKitExample.m
Created December 10, 2015 11:07
PromiseKit callback chaining
// Method signatures
// Promise resolves to User instance
- (PMKPromise *)loginToRemoteServer:(NSString *)userId;
// Promise resolves to NSDictionary of user data
- (PMKPromise *)retrieveUserData:(User *)user;
// Promise resolves to UIImage
- (PMKPromise *)retrieveProfileImage:(NSURL *)imageURL;