Skip to content

Instantly share code, notes, and snippets.

@yycking
yycking / Hant-Hans.swift
Last active October 12, 2017 02:45
繁轉簡,簡轉繁,中文轉拼音,拼音轉注音
extension StringTransform {
public static let 简 = StringTransform("Hant-Hans")
public static let 繁 = StringTransform("Hans-Hant")
public static let 拼 = StringTransform("Han-Latin")
public static let 注 = StringTransform("Han-Latin;Latin-Bopomofo")
}
let 繁转简 = "繁轉簡".applyingTransform(.简, reverse: false)
let 簡轉繁 = "简转繁".applyingTransform(.繁, reverse: false)
let pīnyīn = "拼音".applyingTransform(.拼, reverse: false)
@yycking
yycking / bindActionCreators.js
Last active December 15, 2017 02:45
bindActionCreators的實際作用
const { createStore, bindActionCreators } = Redux
const reducer = (state = {紅:0, 綠:0, 藍:0}, action) => {
switch (action.type){
case '紅': return {...state, 紅:action.值}
case '綠': return {...state, 綠:action.值}
case '藍': return {...state, 藍:action.值}
default: return state
}
}
@yycking
yycking / ble.md
Last active December 26, 2017 10:28
ble筆記
  • 角色
    • 發佈
      • 週邊(peripheral)
        • 廣播(broadcast)
      • 中心(central)
        • 掃瞄(scan)
    • 連線
      • server
      • client
  • 搭配
@yycking
yycking / text2bitmap.swift
Created December 25, 2017 11:26
String to [[Bool]]
import Foundation
import Cocoa
func text2bitmap(text: String, font: NSFont) -> [[Bool]]? {
let attributes = [NSAttributedStringKey.font:font]
let size = text.size(withAttributes: attributes)
let width = Int(size.width)
let height = Int(size.height)
let bytesPerRow = width
@yycking
yycking / Redux特調.js
Created March 19, 2018 03:27
Redux特調
// store: 一個app state的集合體,以object表示
// 換句話說,store是由許多state組成
// 先規劃 store,初始值如下
// {
// 原料: ["咖啡"],
// 顏色: {
// 紅: 111,
// 綠: 78,
// 藍: 55,
// }
@yycking
yycking / carousel.js
Last active April 25, 2018 10:29
Carousel in React Native
@yycking
yycking / UIActivityViewController∓Facebook.swift
Last active April 10, 2018 06:29
FB no longer allows pre-fill.
extension NSString:UIActivityItemSource {
public func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
return ""
}
public func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivityType) -> Any? {
let installedFB = UIApplication.shared.canOpenURL(URL(string: "fb://")!)
let isFB = activityType == UIActivityType.postToFacebook
if installedFB && isFB {
return nil
@yycking
yycking / ShellCommand.sublime-commands
Last active June 19, 2018 10:42
[Option+Shift+K] for react native on Sublime Text
[
{
"caption": " 📱",
"command": "shell_command",
"args": {
"command": "open -a '/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app'",
}
},
{
"caption": " 🏭📱",
@yycking
yycking / 自然語言處理.swift
Created May 15, 2018 07:35
自然語言處理 NSLinguisticTagger
語言辨識:zh-Hant
斷詞:["戚戚", "堆積", "到", "淒慘", "得", "急", "憔悴", "冷冷清清", "傷心", "這", "也", "點點滴滴", "將息", "杯", "淡", "時候", "摘", "慘", "黃", "酒", "獨自", "最", "他", "有", "淒", "怎", "正", "梧桐", "難", "更", "字", "窗兒", "守", "風", "是", "如今", "兩", "乍暖還寒", "盞", "次第", "個", "尋尋覓覓", "堪", "舊時", "過", "愁", "怎生", "了得", "敵", "來", "相識", "花", "誰", "雁", "著", "黑", "卻", "晚", "黃昏", "細雨", "三", "滿地", "兼", "一", "損"]
詞性標記
詞形還原
具名實體辨識
語言辨識:en
斷詞:["no", "I", "my", "\'ll", "wilt", "Capulet", "thou", "not", "if", "be", "and", "but", "Romeo", "love", "name", "thy", "wherefore", "longer", "O", "art", "a", "And", "father", "Deny", "Or", "sworn", "refuse"]
詞性標記
no:Adverb
I:Pronoun
@yycking
yycking / swipl.pl
Created July 21, 2018 03:51
SWIProlog on TextMate
#!/usr/bin/env ruby18
require ENV["TM_SUPPORT_PATH"] + "/lib/tm/executor"
require ENV["TM_SUPPORT_PATH"] + "/lib/tm/save_current_document"
TextMate.save_current_document
TextMate::Executor.make_project_master_current_document
command = ["swipl", "-f", "#{ENV["TM_FILEPATH"]}", "-t", "main", "-g", "true", "--quit"]
TextMate::Executor.run(command)