Skip to content

Instantly share code, notes, and snippets.

View 查看PDF
wx.downloadFile({
url: path,
success(res) {
const downloadPath = res.tempFilePath
console.log('downloadPath =>', downloadPath)
wx.openDocument({
filePath: downloadPath,
fileType: 'pdf',
success(res) {
console.log('打开文档成功 =>', res)
View HexString2Bytes
HexString2Bytes(str) {
var pos = 0;
var len = str.length;
if (len % 2 != 0) {
return null;
}
len /= 2;
var arrBytes = new Array();
for (var i = 0; i < len; i++) {
View mp
let getQuery = "" + decodeURIComponent(options.q)
console.log("getQuery =>", getQuery);
wx.showModal({
title: 'onLoad',
content: getQuery
})
View callback
// example
//a.js
// this.callback("abc")
Say(res) {
// this.callback = (result) => {
// console.log("result => ", result)
// }
this.callback = res;
// console.log("this.callback =>", this.callback)
// console.log("this.callback type =>", typeof(this.callback))
View crc16
import React, { Component } from 'react';
import { Buffer } from 'buffer'
var crc_table = [
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5,
0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b,
0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210,
0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c,
0xf3ff, 0xe3de, 0x2462, 0x3443, 0x0420, 0x1401,
View gist:5cf2fadf80096a1ab30ec8c2e4eb90b8
https://github.com/apple/swift/blob/master/stdlib/public/core/Optional.swift
public enum Optional<Wrapped> : ExpressibleByNilLiteral {
// The compiler has special knowledge of Optional<Wrapped>, including the fact
// that it is an `enum` with cases named `none` and `some`.
/// The absence of a value.
///
/// In code, the absence of a value is typically written using the `nil`
/// literal rather than the explicit `.none` enumeration case.
case none
View gist:34fa6470e5fe02a4b3992ce935705a0a
https://github.com/apple/swift/blob/master/stdlib/public/core/Optional.swift
@_inlineable
public func map<U>(_ transform: (Wrapped) throws -> U) rethrows -> U? {
switch self {
case .some(let y):
return .some(try transform(y))
case .none:
return .none
}
View gist:1870a5ae1564f6202fc87de69ee97b04
https://github.com/apple/swift/blob/master/stdlib/public/core/SequenceAlgorithms.swift.gyb
@_inlineable
public func flatMap<SegmentOfResult : Sequence>(_ transform: (${GElement}) throws -> SegmentOfResult) rethrows -> [SegmentOfResult.${GElement}] {
var result: [SegmentOfResult.${GElement}] = []
for element in self {
result.append(contentsOf: try transform(element))
}
return result
}
View gist:6c8b438e0a6d1488443f0a814b45cc76
https://github.com/apple/swift/blob/master/stdlib/public/core/Collection.swift
@_inlineable
public func map<T>(_ transform: (Iterator.Element) throws -> T) rethrows -> [T] {
// TODO: swift-3-indexing-model - review the following
let count: Int = numericCast(self.count)
if count == 0 {
return []
}