For now, Kaching only provides kaching-paypal to accepting payment through Paypal. More strategies are under plan.
$ npm install kaching
$ npm install kaching-paypal
https://github.com/gregwym/kaching/tree/master/example
Paypal strategy require the client_id
and client_secret
offered by Paypal to operate. You can obtain them from https://developer.paypal.com/webapps/developer/applications.
It use api.sandbox.paypal.com
as the default paypal host address. Feel free to change it in production environment.
var PaypalStrategy = require('kaching-paypal');
var kaching = require('kaching');
kaching.use(new PaypalStrategy({
host: '<paypal_rest_api_endpoint>', // optional
port: '', // optional
client_id: '<paypal_client_id>',
client_secret: '<paypal_client_secret>'
}));
Use kaching.create
, specifying paypal
strategy, to create a Paypal payment. The payment detail should be setup and saved in req.payment
prior invoking the create middleware.
After kaching created the pending payment, it replaces req.payment
with the real payment object that was returned from Paypal API. Save it securely. (i.e., together with the user's order.)
app.get('...', function(req, res, next) {
// Setup payment detail in `req.payment`.
req.payment = {
amount:{
total:'7.47',
currency:'USD'
},
redirect_urls: {
return_url: 'http://<return_url>',
cancel_url: 'http://<cancel_url>'
},
description:'Kaching paypal test transaction'
};
next();
}, kaching.create('paypal', {
// Optional options
}), function(req, res) {
// Now `req.payment` is the Paypal returned payment object
res.json(req.payment);
});
For most of the time, user should redirect to Paypal to complete the payment right away. You can find the page url in payment.links
and do whatever you want.
Or simpler, append the kaching.approve
middleware after the last request handler. It will redirect the user to the payment approval page.
app.get('...', function(req, res, next) {
...
}, kaching.create('paypal', {
...
}), function(req, res, next) {
console.log(JSON.stringify(req.payment));
next();
}, kaching.approve('paypal'));
If you want to use kaching.approve
somewhere else, make sure req.payment
contain a valid payment object.
User will be redirect to return_url
once the payment has been approved. Paypal will specify the payer_id
in req.query.PayerID
. This piece of information is required to execute and complete the payment, so save it securely.
Commonly, execute the payment right after can save many trouble. Here is an example,
app.get('<return_route>', function(req, res, next) {
// Prepare payment information and payerId
req.payment = ...; // Fetch the payment object from anywhere it was saved.
req.payment.payer_id = req.query.PayerID;
next();
}, kaching.execute('paypal'), function(req, res) {
res.json(req.payment); // Now the payment has been completed.
});
Like kaching.create
, kaching.execute
will update req.payment
to the latest. And it's up to you to deal with it.
Note: all the middleware look for the payment informations in req.payment
. Make sure it is set before passing control to a middleware.
Construct a new strategy
.
var options = {
host: '<paypal_rest_api_endpoint>', // optional
port: '', // optional
client_id: '<paypal_client_id>',
client_secret: '<paypal_client_secret>'
}
Build the payment creation middleware.
It use req.payment
as the payment_detail skeleton.
req.payment = {
intent: '[sale | authorize]', // default: sale
payment_method: '[paypal | credit_card]', // default: paypal
funding_instruments: { // required when payment_method = credit_card
... // https://developer.paypal.com/webapps/developer/docs/api/#fundinginstrument-object
},
amount: { // required
... // https://developer.paypal.com/webapps/developer/docs/api/#amount-object
},
item_list: { // optional
... // https://developer.paypal.com/webapps/developer/docs/api/#itemlist-object
},
description: 'Payment description', // optional
redirect_urls: { // required when payment_method = paypal
return_url: ...,
cancel_url: ...
}
};
You may notice that, things like intent
, payment_method
and redirect_urls
are not necessarily be different for each payment. You can set the default value for them when building the middleware.
...
}, kaching.create('paypal', {
intent: 'sale',
payment_method: 'paypal',
redirect_urls: { ... }
}),
...
Then you can omit these fields in req.payment
.
Build the payment approval middleware. Mainly redirect to the approval_url
in payment.links
.
Build the approved payment execution middleware. The middleware find the payment in req.payment
and execute it with req.payment.payer_id
.
Copyright (c) 2013 Greg Wang http://gregwym.info/
]]>In my last release of doGRT, I was proudly announcing the AUTO UPDATE feature. The feature which would let my user updates the schedule data without update the entire app from the App Store. I spent quite a bit of time to implement this feature, and put the schedule data on a place that I thought will never let me down - Github.
Seriously, it was working like a charm. At least during the time I was testing it. Unfortunately, the feature died before anyone can actually try it out.
Right before the schedule season change, Github put out a blog post saying "Goodbye, Uploads". At the main while, they replaced the Downloads Section with Tags and completely disabled the upload.
Even tho Github will keep the downloads page for 90 days, I cannot upload any new file to it. Cannot upload means I cannot tell my app "A newer version of schedule is available, go download it!!!!"
How sad is that`T_T
Github, can't you tell me this a bit earlier? or allow upload for extra 90 days? sigh
First, I wanna say sorry to doGRT users. If it is not the case, you guys would have the hot and fresh holiday schedule in your hand now. This situation should have been avoided if I have left enough flexibility in my implementation.
Of course, I'm going to fix it! Going to release a quick fix version with Winter schedule first.
The more feature I'm working on:
Feel free to @gregwym on twitter about your suggestions. Or you can email me through the feedback button in the app.
Merry Christmas,
Greg
Remember in the Mail App, it shows update status and sending mail progress in the bottom toolbar. I think it is a really neat way to show information, especially for those apps who use native iOS UI elements.
However, I couldn't find any lib out there for this task. So I decide to invent the wheel myself.
Feel free to post any issues or patch. It's my pleasure for any who like my work.
InformaticToolbar is mainly an UIViewController Category which allows you to add several UIBarButtonItems set to your toolbar.
The sets are defined as subclasses of ITBarItemSet. All ITBarItemSet can have a dismiss button if the target and action has been defined. If more than one set has been added, a switch button (an arrow) will be displayed on the left for user to switch between sets.
For now, there are three pre-defined set:
You can easily create new sets by extending ITBarItemSet yourself.
Screenshot:
cd *your-project-location*
git submodule add git://github.com/gregwym/InformaticToolbar.git
You can either add the source codes directly or
InformaticToolbar.xcodeproj
to your project.InformaticToolbar
(the library)libInformaticToolbar.a
"${PROJECT_DIR}/InformaticToolbar/"
to User Header Search Paths, include the quotation marks.YES
-ObjC
In any UIViewController
that you want to use this lib, add #import "InformaticToolbar.h"
at the front.
Or easier, you can add the import to YOUR Prefix.pch
file.
Let's say I want to add a Label to my toolbar, I can call the following method in an UIViewController
:
- (IBAction)addLabelBarItemSet:(id)sender
{
ITLabelBarItemSet *labelBarItemSet = [ITLabelBarItemSet labelBarItemSetWithDismissTarget:self andAction:@selector(dismissBarItemSet:)];
labelBarItemSet.textLabel.text = @"This is text label. ";
labelBarItemSet.detailTextLabel.text = @"This is detail text label. ";
[self pushBarItemSet:labelBarItemSet animated:YES];
}
- (void)dismissBarItemSet:(ITBarItemSet *)sender
{
[self removeBarItemSet:sender animated:YES];
}
In the project, there is a demo app you can tryout. ITViewController.m
includes the sample usage of all three pre-defined item sets.
InformaticToolbar by Greg Wang is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
]]>Just finished my 3B term @ University of Waterloo. Learnt a lot, worked a lot...
Things that I was or is recently working on:
These should be able to keep me busy for my Summer, lol. Gotta stop playing around and start working now.
Wish everyone has a nice summer.
]]>Design as search. Design spaces. Design state, goal structure, generative design operations, early quantitative evaluations, control of design process. Basic models of design (transformational, plan/architecture driven). Relationship to other life-cycle activities.
A lot of others.
Most of them involves trade off between each other
What should be represented (structure, behaviour)? Informal representations of design, examples of design notations. Formal representation of design. Domain specific architecture descriptions. Role of standards, reference architectures. Design documentation.
-
Benefits
Arch Views and Viewpoints
Different views should be consistent between each other.
Metamodel意会了, 但是不知道怎么总结…
主要用来保证view之间的consistency
...继续ing...
Review of small/medium scale plans (data structures, programming language structures, concurrency). Plans/architectures for common types of software systems (translators, embedded, real-time, user interface).
...未开始...
]]>yum安装比较简单快捷, 但默认配置的安全和性能方面不如LNMP一键安装包. 推荐生产环境用一键安装包
如果你在国内的话, 先替换CentOS-Base.repo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
# 如果是CentOS 5.*
wget http://mirrors.163.com/.help/CentOS5-Base-163.repo
# 如果是CentOS 6.*
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
yum makecache
如果之前有apache, 卸载
yum remove httpd
更新软件到最新版本
yum -y update
安装源
# 如果是CentOS 5.*
rpm -ivh http://nginx.org/packages/centos/5/noarch/RPMS/nginx-release-centos-5-0.el5.ngx.noarch.rpm
rpm -ivh http://fedora.mirror.nexicom.net/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
# 如果是CentOS 6.*
rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
rpm -ivh http://fedora.mirror.nexicom.net/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
编辑启用remi源
vi /etc/yum.repos.d/remi.repo
# 将[remi]下的enabled=0改为enabled=1
# 按esc
# :x回车
执行安装, 根据需要增减要安装的php模块
yum install nginx mysql mysql-server php-fpm php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy
启动nginx, php-fpm, mysqld
service nginx restart
service php-fpm restart
service mysqld restart
设置自动启动
chkconfig nginx on
chkconfig php-fpm on
chkconfig mysqld on
mysql密码设置
mysql_secure_installation
至于目录权限管理什么的, 就不写了.
niginx配置文件在/etc/nginx/nginx.conf
php-fpm配置文件在/etc/php-fpm.conf
php配置文件/etc/php.ini
mysql配置文件/etc/my.cnf
参考文章:
http://www.ppkj.net/2011/11/18/centos6-yum-%E6%90%AD%E5%BB%BAlinux-nginx-php-mysql-lnmp/
http://www.centos.bz/2011/03/yum-install-nginx-mysql-php-fastcgi-lnmp/
这两种实现都各有利弊, 我个人倾向于ichuan的做法.
原因无外乎, 能保持Typecho文章数据的一致性, 以前存HTML现在还是存HTML, 只是编辑的方式变了.
但ichuan的插件在用的时候不是那么顺利. 因为js放置的位置好像有些问题, 编辑器和预览99%的时候加载失败(Chrome 17). 预览界面的CSS定义也有些问题.
于是自己动手丰衣足食, 把成果po出来给和我碰到同样问题的朋友们.
Mar 19/2012 v0.2.1
strong text
emphasized text
strong & emphasized text
Blockquote
enter code here
List item
一直想换主题却没有找到好的. 最近对Bootstrap很是痴迷, 又有了点空闲, 就顺手仿着Bootstrap官网风格做了一个Typecho的主题.
自己觉得效果还不错, po出来给喜欢的朋友.
下载我放在doLast.com上了, 点Download即可
http://dolast.com/pages/trapecho
https://github.com/gregwym/Trapecho/zipball/master
/admin/options-theme.php
主题设置页中填入新浪微博的UID, 侧栏中就会显示新浪微博的插件.footer.php
最后删除和pre
有关的几行JavaScript即可.使用很简单, 展示大段的代码, 使用<pre>
将代码括住, 就会自动高亮, 语言类型自动识别.
<pre>
<!--你的代码放在中间-->
</pre>
比如,
int main(){
cout << "Welcome to Trapecho" << endl;
return 0;
}
更多使用方法请参考, google-code-prettify README
String filename = "path/file.txt";
File file = new File(filename);
FileInputStream fileinput = new FileInputStream(file.getAbsolutePath());
int x = fileinput.available();
byte b[] = new byte[x];
fileinput.read(b);
String string = new String(b);
System.out.println(string);
开始实习以后, 真的没什么自己的时间了. 学到了不少东西, 但还是老样子, 自己摸索自己成长. 长篇的理论知识整理确实重要, 但这些代码片段, 在需要的时候也是实实在在能帮上忙的东西.
闲的时间少了, 估计以后这类东西会比较多吧...
btnx非常好的解决了这个问题, 而且还带GUI设置工具. 除了设置里没有Apply这个按钮, 让人有点琢磨不透它到底什么时候保存设置以外, 其他都还不错.
调整好设置以后记得点"Restart BTNX"来重启服务.
记一下安装使用时候碰到的各种问题.
在设置好鼠标以后还有点神器的问题, 就是btnx的设置不会屏蔽(override)掉这个按键的默认功能.
举个例子, 我把鼠标上原先的"前进/后退"设置成了"Ctrl+TAB/Ctrl+Shift+TAB", 当我在浏览器里按这个按钮的时候, 我不光会切换tab, 还会让页面前进/后退...很恶心是不是?
解决方法是, 编辑~/.Xmodmap把这几个按钮屏蔽掉.
比如button 8, 9是前进后退, 那就在~/.Xmodmap里写入
! Disable buttons 8 and 9
pointer = 1 2 3 4 5 6 7 0 0
参考资料:
http://ubuntuforums.org/showthread.php?t=918714
http://unix.stackexchange.com/questions/20550/how-to-disable-the-forward-back-buttons-on-my-mouse