View calculation.py
This file contains 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
def yuan2fen(amount): | |
if isinstance(amount, str): | |
amount = float(amount) | |
a = amount * 100 | |
z = str(a).split(".") | |
if len(z) == 2: | |
if int(z[1][0]) > 4: | |
return int(a) + (1 if a > 0 else -1) |
View mount disk
This file contains 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
1.分区(new disk) | |
查看 | |
> fdisk -l | |
Disk /dev/vda: 60 GiB, 64424509440 bytes, 125829120 sectors | |
Units: sectors of 1 * 512 = 512 bytes | |
Sector size (logical/physical): 512 bytes / 512 bytes | |
I/O size (minimum/optimal): 512 bytes / 512 bytes | |
Disklabel type: dos | |
Disk identifier: 0xd6804155 |
View Row.delete()
This file contains 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
def remove_row(table, row): | |
tbl = table._tbl | |
tr = row._tr | |
tbl.remove(tr) | |
table = d.tables[0] | |
row = table.rows[1] | |
remove_row(table, row) |
View tornado_concurrency.py
This file contains 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
#!/bin/env python | |
import tornado.gen | |
import tornado.httpserver | |
import tornado.ioloop | |
import tornado.options | |
import tornado.web | |
# 这个并发库在python3自带;在python2需要安装sudo pip install futures | |
from tornado.options import define, options | |
define("port", default=8002, help="run on the given port", type=int) |
View UIImageViewExtension
This file contains 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
extension UIImageView { | |
func clip(roundedRect: CGRect?, cornerRadius: CGFloat = 0, force: Bool = false) { | |
if force { | |
let bezierPath = UIBezierPath(roundedRect: roundedRect ?? bounds, cornerRadius: cornerRadius) | |
let maskLayer = CAShapeLayer() | |
maskLayer.path = bezierPath.cgPath | |
layer.mask = maskLayer | |
} else if layer.mask == nil { | |
let bezierPath = UIBezierPath(roundedRect: roundedRect ?? bounds, cornerRadius: cornerRadius) |
View umeng_UDID_Swift3
This file contains 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
let cls = NSClassFromString("UMANUtil") | |
let deviceIDSelector = Selector("openUDIDString") | |
var deviceID: String? = nil | |
if(cls != nil && cls!.responds(to: deviceIDSelector)){ | |
deviceID = (cls as? NSObjectProtocol)?.perform(deviceIDSelector).takeUnretainedValue() as? String | |
} | |
guard let jsonData = try? JSONSerialization.data(withJSONObject: ["oid":deviceID], options: JSONSerialization.WritingOptions.prettyPrinted) else { | |
print("Can't get UDID") | |
return false |
View WKWebView_Image_adaption
This file contains 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
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { | |
if webView.canGoBack { | |
// html padding | |
let javascriptString = "document.body.style.padding='0px 12px 0px 12px'; " | |
webView.evaluateJavaScript(javascriptString) { (obj, error) in | |
print(obj) | |
} | |
let imgJs = "function getImages(){" | |
+ "var objs = document.getElementsByTagName(\"img\");" |
View Fit html image to NSAttributedString
This file contains 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
// NSAttributedString: Fit image to container | |
// Find answer in here: | |
// https://stackoverflow.com/questions/28920795/nsattributedstring-fit-image-to-container/29060169#29060169 | |
## Code Below | Swift 3 | |
let data = htmlString.data(using: .unicode) | |
let text = try NSMutableAttributedString(data: data!, options: [NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType], documentAttributes: nil) | |
text.enumerateAttribute(NSAttachmentAttributeName, in: NSMakeRange(0, text.length), options: .init(rawValue: 0), using: { (value, range, stop) in | |
if let attachement = value as? NSTextAttachment { |
View main.swift
This file contains 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 Foundation | |
func numberOfTasksRuningWithStart(start:Array<Int>, end:Array<Int>, query:Array<Int>) -> Array<Int> { | |
// 1.fill empty array with zero | |
var numberOfTasksRuning = Array<Int>.init(repeating: 0, count: query.count) | |
// 2.search data | |
for i in 0..<query.count { |