Skip to content

Instantly share code, notes, and snippets.

View marty-suzuki's full-sized avatar
Back to the future

Taiki Suzuki marty-suzuki

Back to the future
View GitHub Profile
<?php
for($i=1; $i<=100; $i++){
if($i%3==0 && $i%5!=0){
print '(」・ω・)」うー!';
}
else if($i%5==0 && $i%3!=0){
print '(/・ω・)/にゃー!';
}
else if($i%5!=0 || $i%3!=0){
print "$i";
@marty-suzuki
marty-suzuki / WPTextAttachment.h
Created February 19, 2016 11:20 — forked from stuartjmoore/WPTextAttachment.h
Creates an NSTextAttachment the takes up the entire width of the line fragment (while maintaining its aspect ratio). Instead of a simple image, any UIView (that has a (CGFloat)heightThatFits method) will work.
//
// WPTextAttachment.h
// ReadArticle
//
// Created by Moore, Stuart on 12/27/13.
// Copyright (c) 2013 The Washington Post. All rights reserved.
//
#import <UIKit/UIKit.h>
// based on this article. http://qiita.com/magickworx/items/9a8e6108db8134a8363a#comment-f7c2edf79151a38f4d9d
extension Double {
func toRadians() -> Double {
return self * Double(M_PI) / 180
}
}
extension UIView {
private struct Const {
class SectionLayoutManager {
//MARK: - Inner Enums
enum LayoutType {
case Profile
case ProfileFollowing
case ProfileFollower
case ProfileFollowingFollower
init(followingCount: Int, followerCount: Int) {
if followingCount > 0 && followerCount > 0 {
@interface TriangleView()
@property (nonatomic, strong, readonly) CAShapeLayer *shapeLayer;
@end
@implementation TriangleView
static NSString *const kAniamtionKey = @"path";
static CGFloat const ANIMATION_DURATION = 0.25f;
- (id)initWithFrame:(CGRect)frame {
extension Array {
func unique(predicate: (Element, Element) -> Bool) -> [Element] {
var result: [Element] = []
forEach { e -> Void in
guard !result.contains({ r -> Bool in
return predicate(r, e)
}) else { return }
result.append(e)
}
return result
@implementation NSObject (Error)
- (void)removeObserver:(NSObject * _Nonnull)observer forKeyPath:(NSString * _Nonnull)keyPath error:(NSError * _Nullable __autoreleasing * _Nullable)error {
@try {
[self removeObserver:observer forKeyPath:keyPath];
} @catch (NSException *exception) {
NSMutableDictionary *userInfo = nil;
if (exception.userInfo == nil) {
userInfo = [NSMutableDictionary dictionaryWithCapacity:0];
} else {
extension NSObject {
func remove(observer: NSObject, for keyPath: String) throws {
var error: NSError? = nil
removeObserver(observer, forKeyPath: keyPath, error: &error)
guard let e = error else { return }
throw e
}
}
//: Playground - noun: a place where people can play
import Foundation
// MARK: - Pub / Sub
protocol Subscription {
var id: SubscriptionID { get }
}
// A swift implementation of [this presentetion](https://www.slideshare.net/AkinoriAbe1/aja-2016623).
protocol Trait {}
enum Z: Trait {}
enum S<N: Trait>: Trait {}
struct Nat<N: Trait>: CustomStringConvertible {
let n: Int
fileprivate init(n: Int) {