This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fontMetrics (family, size) { | |
this._family = family || (family = "Monaco, 'Courier New', Courier, monospace") | |
this._size = parseInt(size, 10) || (size = 12) | |
// Preparing container | |
var line = document.createElement('div') | |
var body = document.body | |
line.style.position = 'absolute' | |
line.style.whiteSpace = 'nowrap' | |
line.style.font = size + 'px ' + family |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hdpiCanvasPolyfill (canvas) { | |
var dpr = Math.max(1, window.devicePixelRatio || 1) | |
var logicalWidth = canvas.width | |
var logicalHeight = canvas.height | |
canvas.width = dpr * logicalWidth | |
canvas.height = dpr * logicalHeight | |
canvas.style.width = `${logicalWidth}px` | |
canvas.style.height = `${logicalHeight}px` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
// The Promise States constants | |
const PENDING = 0 | |
const FULFILLED = 1 | |
const REJECTED = 2 | |
export default class Promise { | |
// The constructor function | |
constructor (executor) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: http://stuffandnonsense.co.uk/blog/about/hardboiled_css3_media_queries/ | |
*/ | |
/* Smartphones (portrait and landscape) ----------- */ | |
@media only screen | |
and (min-device-width : 320px) | |
and (max-device-width : 480px) { | |
/* Styles */ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>object-observe</title> | |
<style> | |
</style> | |
</head> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(UIImage *)fixOrientation:(UIImage *)aImage | |
{ | |
if (aImage == nil) | |
{ | |
return nil; | |
} | |
CGImageRef imgRef = aImage.CGImage; | |
CGFloat width = CGImageGetWidth(imgRef); | |
CGFloat height = CGImageGetHeight(imgRef); | |
CGAffineTransform transform = CGAffineTransformIdentity; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <mach/mach.h> | |
// 获取 CPU 使用率 | |
float cpu_usage() | |
{ | |
kern_return_t kr; | |
task_info_data_t tinfo; | |
mach_msg_type_number_t task_info_count; | |
task_info_count = TASK_INFO_MAX; | |
kr = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)tinfo, &task_info_count); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (UIViewController *)topViewController{ | |
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController]; | |
} | |
- (UIViewController *)topViewController:(UIViewController *)rootViewController | |
{ | |
if (rootViewController.presentedViewController == nil) { | |
return rootViewController; | |
} | |