Journey.


  • Home

  • menu.projects

  • About

  • Tags

  • Archives
Journey.

Days | Never Forget

|

一款简单的菜单栏倒数日App. 支持中英德文显示以及自定义间隔符.


下载:https://github.com/KeliCheng/Days

Journey.

使用OAuthSwift完成微博OAuth2.0授权

|

昨天关于新浪的授权鼓捣了一天才弄好,所以写一个这个过程。主要用到的是OAuthSwift(一个适用于iOS/macOS等的OAuth库,支持1.0和2.0)
另外关于整个授权的过程,Practical Guide for using Sina Weibo’s API 也很有帮助。

  1. 新浪开发者,申请App,填写认证和App资料(略)
  2. 在project中导入OAuthSwift库(略)
  3. 授权 doOAuthWeibo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import OAuthSwift
import AppKit
class ViewController: OAuthViewController {
var oauthswift: OAuthSwift?
}
extension ViewController {
override func viewDidLoad() {
super.viewDidLoad()
doOAuthWeibo()
}
// MARK: Weibo
func doOAuthWeibo(){
// 注意这里使用的是OAuth2Swift,因为微博使用的也是OAuth2.0
let oauthswift = OAuth2Swift(
consumerKey: "XXXXXXX",
consumerSecret: "XXXXXXXXXXXXXXXXXXXXXXXX",
authorizeUrl: "https://api.weibo.com/oauth2/authorize",
accessTokenUrl: "https://api.weibo.com/oauth2/access_token",
responseType: "code"
)
let state = generateState(withLength: 20)
self.oauthswift = oauthswift
oauthswift.allowMissingStateCheck = true
oauthswift.authorizeURLHandler = OAuthSwiftOpenURLExternally.sharedInstance
// 这里的callback URL一定要与在微博APP页面填写的一致
let _ = oauthswift.authorize(withCallbackURL: URL(string: "http://your/callback/url")!,
scope: "full",
state: state,
success: { (credential, response, parameters) in
print("OAuth successful")
self.weibo(oauthswift, token: credential.oauthToken) // 发布一条微博
}) { (error) in
print(error.description)
}
}
// post a weibo for testing
func weibo(_ oauthswift: OAuth2Swift, token: String) {
let param = [
"format": "html",
"status": "Hello, world! \(arc4random())",
"access_token": token
]
let _ = oauthswift.client.post("https://api.weibo.com/2/statuses/update.json", parameters: param, success: { (OAuthSwiftResponse) in
print("posted")
}, failure: { (OAuthSwiftError) in
print("post failed")
print(OAuthSwiftError)
})
}
// generate random state
public func generateState(withLength len : Int) -> String {
let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
let length = UInt32(letters.characters.count)
var randomString = ""
for _ in 0..<len {
let rand = arc4random_uniform(length)
let idx = letters.index(letters.startIndex, offsetBy: Int(rand))
let letter = letters.characters[idx]
randomString += String(letter)
}
return randomString
}
}
  1. 关于callback URL
    因为微博只接受http格式的URL,所以我在自己博客新建了一个页面作为callback URL(http://kelicheng.github.io/simple-sender/)
    在这个页面放一段代码重新定向到App中。
    1
    2
    3
    4
    <script type="text/javascript">
    var query = window.location.href.replace("http://your/callback/url", "YourAppName://oauth-callback/");
    window.location.assign(query)
    </script>

此外还要在project中设置URL Schemes:
Targets -> (YourAPP) -> Info -> URL Types -> Add -> URL Schemes = YourAppName

OAuthSwift的作者还给出了Ruby和PHP的代码示例,以及另一种使用内置浏览器授权的解决方案。详见:https://github.com/OAuthSwift/OAuthSwift/wiki/API-with-only-HTTP-scheme-into-callback-URL

Journey.

Simpo | the simple way of posting

|

Time: 2017-01-16 ~

Download

Github: https://github.com/KeliCheng/Simpo
一款快速发布文字和图片到社交网站的macOS菜单栏App,目前支持饭否/Twitter/微博多账户登录。

Version

2017-01-26 v.1.0.0:
-支持饭否多账户登录
-可以发送图片和文字
-自定义字体及背景颜色,管理草稿。

2017-02-01 v.1.0.1:
-支持Twitter账户登录

2017-02-03 v.1.0.2:
-支持微博账户登录

2017-02-19 v.1.1.0:

  • 全新UI设计
  • 更多自定义选项
  • 新增字体以及歌词显示

tips

  • 打开App如果出现提示为未认证作者:
    打开System Preference系统设置 –> Security & Privacy 安全和隐私 –> General –> 点击左下角小锁 –>
    看是否出现 Open Simpo Anyway, 如果没有,尝试关闭之前出现的提示; 如果有,点击Open Anyway,再重启App

  • Twitter/微博登录没有反应:打开默认浏览器重试

  • 打开设置(添加账户)/退出:右键点击菜单栏图标

  • 切换账户:点击左上角头像

  • Twitter/微博授权后有两个程序被打开:将两个程序都关闭后重启Simpo,或尝试使用Chrome等作为默认浏览器

Journey.

Breakout Game

|

https://github.com/KeliCheng/Breakout
A classic breakout game with customized settings. CS193p Assignment 6.
2017.01.08 - 2017.01.16

TODO:

  • support gravitational pull
  • support adjust of ball bounciness
  • fix alert when game ends
Journey.

修改hexo/NexT主题

|

参考:
http://zhouhuix.cn/2016/11/24/修改Hexo的Next主题/

鉴于NexT已经更新,之前很多修改颜色字体的方法也失效。
以下方案适用于NexT Version 5.1.0
修改博客背景颜色
/themes/next/source/css/_schemes/Pisces/_layout.styl

1
2
3
.main{
background: #222222; // 或替代为image
}

修改内容背景色

1
2
3
.content-wrap {
background: #222222;
}

修改字体
/themes/next/source/css/_variables/base.styl
$font-family-chinese = "Songti TC", "Adobe Song Std"

引用自定义js文件和css样式
参考:
hexo引用自定义js文件和css样式
添加css/js文件到source文件夹之后修改:
/themes/next/layout/index.swig

Journey.

Graphing Calculator

|
Journey.

iOS-learning-process

|
  1. StanfordU CS193P Spring 2016
    finished projects:
    Graphing Calculator
    Smashtag
    Breakout
    ……

Menu Bar App:
https://www.raywenderlich.com/98178/os-x-tutorial-menus-popovers-menu-bar-apps
https://samoylov.tech/2016/09/14/handling-left-and-right-click-at-nsstatusbar-with-swift-3/

Journey.

Pointing Hover Domain | Hexo-GithubPages-GoDaddy

|

Domain: example.com
Blog: build with Hexo, hosted on GithubPages (example.github.io)

  1. create CNAME file uder the “source” directory (not the root dir)
    within the CNAME file, write “http://example.com”
    save it, generate (hexo g) and deploy (hexo d) to Github Pages

  2. go to GoDaddy DNS Manager of domain “example.com”
    add new records:
    • Hostname: @, Record Type: A, Value: 192.30.252.153
    • Hostname: @, Record Type: A, Value: 192.30.252.154
    • Hostname: www, Record Type: CNAME, Value: example.github.io

Journey.

SlackBot source code

|

A simple slackbot script includes: greeting, randomly replying with lyrics

Read more »
Journey.

AWS | Error Establishing a Database Connection

|

“Error Establishing a Database Connection” – a common error with Wordpress blog deployed in AWS
Solution: log into the server and restart database

1
2
sudo service mysqld stop
sudo service mysqld start

DONE!

12
Keli Cheng

Keli Cheng

12 posts
1 categories
24 tags
GitHub Weibo
© 2017 Keli Cheng