Skip to content

Instantly share code, notes, and snippets.

View tiger8888's full-sized avatar
🎯
Focusing

tiger8888

🎯
Focusing
View GitHub Profile
@tiger8888
tiger8888 / UIView+CustomTimingFunction.h
Created February 19, 2016 03:12 — forked from nuthinking/UIView+CustomTimingFunction.h
UIView Custom Timing Functions
//
// UIView+CustomTimingFunction.h
// Instants
//
// Created by Christian Giordano on 16/10/2013.
// Copyright (c) 2013 Christian Giordano. All rights reserved.
//
#import <UIKit/UIKit.h>
@tiger8888
tiger8888 / CGAffineTransformFromRectToRect.m
Created February 20, 2016 03:54 — forked from hatfinch/CGAffineTransformFromRectToRect.m
CGAffineTransformFromRectToRect (not working)
CGAffineTransform CGAffineTransformFromRectToRect(CGRect fromRect, CGRect toRect)
{
CGSize scale = CGSizeMake(toRect.size.width / fromRect.size.width, toRect.size.height / fromRect.size.height);
CGRect scaledFromRect = CGRectMake(fromRect.origin.x * scale.width, fromRect.origin.y * scale.height,
fromRect.size.width * scale.width, fromRect.size.height * scale.height);
CGSize translation = CGSizeMake(fromRect.origin.x - scaledFromRect.origin.x, fromRect.origin.y - scaledFromRect.origin.y);
return CGAffineTransformMake(scale.width, 0.0, 0.0, scale.height, translation.width, translation.height);
}
@tiger8888
tiger8888 / mixins.js
Created June 3, 2016 00:57
ES5 mixins example and TypeScript Interface example from multiple inheritance lecture
function extend(destination, source) {
for (var k in source) {
// console.log(k)
if (source.hasOwnProperty(k)) {
destination[k] = source[k];
}
}
return destination;
}
@tiger8888
tiger8888 / mixin.js
Created June 3, 2016 00:59 — forked from guilipan/mixin.js
ES5下实现mixin或extend的方法
function (receiver, supplier) {
Object.keys(supplier).forEach(function (property) {
Object.defineProperty(receiver, property, Object.getOwnPropertyDescriptor(supplier, property));
});
}
import Foundation
typealias CancelableTask = (cancel: Bool) -> Void
func delay(time: NSTimeInterval, work: dispatch_block_t) -> CancelableTask? {
var finalTask: CancelableTask?
var cancelableTask: CancelableTask = { cancel in
if cancel {
var origin: CGPoint?
var radius: CGFloat?
var locations: [CGFloat]?
var colors: [UIColor]?
override func drawInContext(ctx: CGContext!) {
super.drawInContext(ctx)
if let colors = self.colors {
if let locations = self.locations {
if let origin = self.origin {
@tiger8888
tiger8888 / ColorFunctions.m
Created June 16, 2016 09:07 — forked from kreeger/ColorFunctions.m
Tint an image with a particular color, using `kCGBlendModeNormal`.
UIImage *TintImageWithTintColor(UIImage *image, UIColor *tintColor) {
// Huge props to http://stackoverflow.com/questions/3514066/how-to-tint-a-transparent-png-image-in-iphone
UIGraphicsBeginImageContext(image.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0, image.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGRect rect = (CGRect){ CGPointZero, image.size };
//
// main.swift
// Test
//
// Created by Chris Eidhof on 29/08/15.
// Copyright © 2015 Chris Eidhof. All rights reserved.
//
import Foundation
import Quartz
@tiger8888
tiger8888 / npm-cheat-sheet.md
Created July 1, 2016 09:10 — forked from AvnerCohen/npm-cheat-sheet.md
Node.js - npm Cheat Sheet

Node.js - npm Cheat Sheet

(Full description and list of commands at - https://npmjs.org/doc/index.html)

##List of less common (however useful) NPM commands

######Prepand ./bin to your $PATH Make sure to export your local $PATH and prepand relative ./node_modules/.bin/:

@tiger8888
tiger8888 / AttributedRoundtrip.m
Created July 10, 2016 11:37 — forked from danielnorton/AttributedRoundtrip.m
Unexpected roundtrip of HTML through NSAttributedString. This demonstrates a simple HTML file going into an NSAttributedString and then writing that string back out to a new HTML file. The output file is structured very differently than the input file. This was discovered while experimenting with using a UITextView as a rich text editor.
- (NSAttributedString *)loadContent {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"input" ofType:@"html"];
NSData *htmlData = [NSData dataWithContentsOfFile:filePath];
NSDictionary *options = @{
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)
};