wangwangwar / daily-notes Goto Github PK
View Code? Open in Web Editor NEWDaily Notes
Daily Notes
记录(和思考)一些RAC Tips
Coding-iOS is the official iOS client for Coding.net.
Recently I'm learning ReactiveCocoa and reading some related projects(AshFurrow/C-41, jspahrsummers/GroceryList). I'm totally impressed by FRP's grace and MVVM's modularity. I decide to do some projects to verify my shallow understanding. Y not Coding-iOS?
I/O密集型通过少量线程和回调机制来调优
无意间看到了这句话。然后就思考了一下为什么少量的线程和回调机制可以用来对I/O密集型调优。
自己是这样理解的:
少量的线程就用单线程吧,回调机制那么就是事件驱动,当然你知道我说的是什么,对,就是Node.JS。
众所周知,单线程就考虑成一个人在使用I/O资源,那么他可以按照指令,随意的使用它的资源。多线程就考虑成很多人需要使用I/O资源那么,他们之间谁使用资源就需要竞争,需要管理,这就是消耗了。
再看事件驱动,这就很简单的,我不可能让I/O资源不使用,然后等你说你准备好了再使用吧,只能是你给我说你准备好了,我就把你的任务排在队列的最后然后让I/O资源一刻不停的按照任务的序列工作下去。
当然,这只是我的理解,而且都是白话,不具有专业的参考价值。
Access levels in Swift follow an overall guiding principle: No entity can be defined in terms of another entity that has a lower (more restrictive) access level.
All entities in your code (with a few specific exceptions, as described later in this chapter) have a default access level of internal if you do not specify an explicit access level yourself. As a result, in many cases you do not need to specify an explicit access level in your code.
When you write a simple single-target app, the code in your app is typically self-contained within the app and does not need to be made available outside of the app’s module. The default access level of internal already matches this requirement. Therefore, you do not need to specify a custom access level. You may, however, want to mark some parts of your code as private in order to hide their implementation details from other code within the app’s module.
When you develop a framework, mark the public-facing interface to that framework as public so that it can be viewed and accessed by other modules, such as an app that imports the framework. This public-facing interface is the application programming interface (or API) for the framework.
摘录来自: Apple Inc. “The Swift Programming Language”
我们好吃懒做,傲慢,蔑视,沉默,拖延,是因为我们相信事情会莫名其妙就变好了,是因为我们相信问题会自然而然地腐败入地的,是因为我们相信有上帝会饶恕我们的愚蠢和可怜。
夜行者 http://movie.douban.com/subject/25750969/
Sex is sex, but money is money https://medium.com/matter/sex-is-sex-but-money-is-money-e7c10091713f
严肃对待自己的职业。想要赚更多的钱和走得更远的话。做好职业规划,投入时间精力和金钱,更专业。
许多的障碍方块规律运动,你碰到就会死。必须操作绕过他们。
两种方式 1
Table
来声明 tablefrom sqlalchemy import create_engine, MetaData, Integer
engine = create_engine('sqlite:///:memory:')
metadata = MetaData(bind=engine)
user = Table('user', metadata,
Column('user_id', Integer, primary_key = True),
)
user_prefs = Table('user_prefs', metadata,
Column('pref_id', Integer, primary_key=True),
)
# 创建 / 丢掉全部的表
metadata.create_all()
metadata.drop_all()
# 创建 / 丢掉单独的表
user.create()
user.drop()
declarative_base
继承的方式:from sqlalchemy import create_engine, MetaData, Integer
from sqlalchemy.ext.declarative import declarative_base
engine = create_engine('sqlite:///:memory:')
metadata = MetaData(bind=engine)
Base = declarative_base(metadata=metadata)user
class User(Base):
__tablename__ = 'user'
user_id = Column('user_id', Integer, primary_key = True)
class UserPrefs(Base):
__tablename__ = 'user_prefs'
pref_id = Column('pref_id', Integer, primary_key=True)
# 创建 / 丢掉全部的表
User.metadata.create_all()
User.metadata.drop_all()
# 创建 / 丢掉单独的表
User.metadata.table['user'].create()
User.metadata.table['user'].drop()
继承机制的设计** ref 1
令h(0)=1,h(1)=1,catalan数满足递推式[1] :
h(n)= h(0)*h(n-1)+h(1)*h(n-2) + ... + h(n-1)h(0) (n>=2)
例如:h(2)=h(0)*h(1)+h(1)*h(0)=1*1+1*1=2
h(3)=h(0)*h(2)+h(1)*h(1)+h(2)*h(0)=1*2+1*1+2*1=5
另类递推式[2] :
h(n)=h(n-1)*(4*n-2)/(n+1);
递推关系的解为:
h(n)=C(2n,n)/(n+1) (n=0,1,2,...)
递推关系的另类解为:
h(n)=c(2n,n)-c(2n,n+1)(n=0,1,2,...)
主要是这个可以解出n个东西不同的进栈出栈顺序一共有多少种。包括这样的一类变种题目
"一个合法的表达式由()包围,()可以嵌套和连接,如(())()也是合法 表达式;现在有 6 对(),它们可以组成的合法表达式的个数为____".
答案是c(2n,n)-c(2n,n+1)=132;
test2
If you try to hide the complexity of the system, you'll end up with a more complex system.
From Aaron Griffin and lovely Arch Linux
I couldn't agree more. OSX try to hide the complexity by hiding the "complex" system folders for the users. WTF
今天在学习reactive cocoa的时候,看到了这样一句话“这里有两个属性:图像视图和订阅者。图像视图是弱引用,因为它归属于上一级视图管理(这是在写UICollectionViewCell子类时的标准做法)。”,看到这里的时候,突然引起了我的一个联想。对的,就是标题。
看到这句话后,我就去思考了一下: UIView 都会有一个强引用的集合属性 subviews ,也就是说, subview 都是被它的 superview 持有的,这个时候,如果你想要方便的找到其中某个特定的 subview 时,也许就会用到属性来引用它。那么,这个时候应该用 weak 还是 strong 呢?个人认为 weak 比 strong 好。既然 UIView 已经规定好了他们互相的关系,我们就需要优雅的不去打扰。
1637年荷兰发生郁金香泡沫事件,三个阶段:第一阶段是供需不平衡而变得高价,第二阶段是投机者开始进入市场,第三阶段则是卷入了缺乏资本的平民。到了第三阶段之后开始泡沫化,价格暴跌导致市场上一片混乱。
http://zh.wikipedia.org/wiki/%E9%AC%B1%E9%87%91%E9%A6%99%E7%8B%82%E7%86%B1
是的是的
glance image-download
命令来下载快照qemu-img convert -c
来压缩,压缩后通过glance image-create
来上传压缩好的镜像。UUID ref 1,ref 3, 如果UUID不带参数, 直接注意如果直接插入uuid格式的数据, 会出错.
必须UUID(as_uuid=True), 会自动转换.
from sqlalchemy.dialects.postgresql import UUID
import uuid
class User(Base):
__tablename__ = 'users'
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid1)
name = Column(String(10), nullable=False)
def __repr__(self):
return "<User '%s'>" % self.name
与GUID ref 2, GUID做了兼容.
test1
是的是的
AshFurrow/C-41 is a demo project showing how to use RAC and MVVM (and more).
Ash Furrow is famous for ReactiveCocoa.
View and its controller: ASHMasterViewController
View Model: ASHMasterViewModel
-[ASHAppDelegate application:didFinishLaunchingWithOptions:]
, we initial ASHMasterViewController
, ASHMasterViewModel
and set controller.viewModel = viewModel
.ASHMasterViewModel.h
we declare updatedContentSignal
as a RACSignal
, but in -[ASHMasterViewModel initWithModel:]
we initialize it in this way: self.updatedContentSignal = [[RACSubject subject] setNameWithFormat:@"ASHMasterViewModel updatedContentSignal"];
. We can do this because class RACSubject
inherit RACSignal
. And in -[ASHMasterViewModel controllerDidChangeContent:]
we have this line: [(RACSubject *)self.updatedContentSignal sendNext:nil]
. This line is a little tricky: we cast the updatedContentSignal
, a RACSignal
according to interface, to class RACSubject
and send msg -[RACSubject sendNext:]
. In this complicated way we want to achieve two goals: First, class RACSubject
can be manually controlled and brigde non-RAC code into the world of signals. But secondly we must avoid using subjects when possible. So inside ASHMasterViewModel
, updatedContentSignal
is RACSubject
and we manually (and carefully) handle events. Outside, it's simply immutable RACSignal
.ASHMasterViewModel.didBecomeActiveSignal
. Note ASHMasterViewModel
inherit RVMViewModel
class, didBecomeActiveSignal
actually is from RVMViewModel
. -[RVMViewModel didBecomeActiveSignal]
actually create a signal to observe the property RVMViewModel.active
. So in -[ASHMasterViewController viewWillAppear:]
we set self.viewModel.active = YES
and trigger the didBecomeActiveSignal
.bowerInstall
会找到根目录 bower.json
, 从中得到所有的依赖, 去bower components
中找到文件夹下的 .bower.json
, 插入所有 main
指定的文件.
<Functional Reactive Programming on iOS> 作者是Ash Furrow,ReactiveCocoa 成员之一。书是收费的,有支付能力的可以支持一下作者,暂时没钱的或者需要看中文的,有翻译: 连载1, 连载2, 连载3, 连载4, 连载5,这里向作者和翻译者知泉表示感谢::>_<::
在OC代码和Xcode
界面编辑器中的关于尺寸的单位都是point
,而不是pixel
. 在Retina屏上,1个point
的高是pixel
的2倍,宽也是,即1个point
对应4个pixel
。在非Retina屏上,一个point
对应一个pixel
。比如Iphone4s是Retina屏,宽度是 640 pixels,高度是960 pixels, 那么在界面编辑器中显示的分别是 320 points, 480 points。
这是一个相对概念,如果你的操作大部分时间都是在等待I/O,CPU长时间处于挂起状态,那么可以说你现在的操作是I/O密集型操作,CPU密集型则是相反。当然这既然是一个相对概念,那么就要视现在的情况而定。如果你的CPU性能不好,大多数时间都很忙,那么就是CPU密集型;这时候你换了一个强大的CPU,大大加强了CPU的计算能力,这个时候CPU大多数时间就是很闲的,也就完成了CPU密集型向I/O密集型的转化。
当然,从现在的情况来看,我们的大部分操作可以算作是I/O密集型操作,有限制的数据传输速度和强大的计算能力。App可以看作是内存与CPU,服务端可以看作宽带带宽与CPU。
表格视图控制器(Table View Controller)需要conform两个协议,UITableViewDelegate
和UITableViewDataSource
。
UITableViewController
,已经定义了遵守这两个协议,只需要实现就行。UIViewController
,那么需要自己遵守这两个协议,并实现。简介这两个协议:
UITableViewDataSource
主要关注UITableView
的数据模型(Data Model),而UITableViewDelegate
则关注UITableView
的表现。
UITableViewDataSource
必须实现两个方法:
tableView:cellForRowAtIndexPath:
是往cell填充数据的方法。注意链接中的Discussion中的最佳实践,为了提高性能,可以向tableView
发送dequeueReusableCellWithIdentifier:
消息来获取之前创建的cell对象。tableView:numberOfRowsInSection:
是指定section的行数。iOS Core Animation: Advanced Techniques
相关链接:
https://itunes.apple.com/us/book/ios-core-animation/id687319118?mt=11
http://www.amazon.com/iOS-Core-Animation-Advanced-Techniques-ebook/dp/B00EHJCORC
https://book.douban.com/subject/25716177/
翻译 https://github.com/AttackOnDobby/iOS-Core-Animation-Advanced-Techniques
翻译 https://www.gitbook.com/book/zsisme/ios-/details
Jenkins, Git, XCTool
pre-commit
hook会调用脚本检查代码缩进/风格等是否符合要求,不符合打回(TODO:或协助format?)。需要一个在Client端安装一个小脚本,以后clone代码时用此脚本,会自动在.git/hooks/pre-commit
文件加上代码检查的hook。
master
分支master
分支。开发者只能Push到feature
或者其他分支上,若分支测试通过,Jenkins会自动将分支(TODO:或用户手动?)合并进master
分支,这保证了master
分支是稳定的(如果通过所有测试可以被称为稳定的话:)。参考Jenkins-Git-Plugin 若分支测试不通过,则拒绝合并。master
分支后,Jenkins将自动Build和Distribute所有重要信息(Push,Build,Test,Merge,Distribute)都可以通过邮件和IM分发出去。
代码测试通过率,覆盖率,Build版本,风格检查结果等都有直观的报表。
单元测试相关:BDD,Mock。
UI测试相关: Snapshot, Automating UI Test
Merge Request Plugin: https://github.com/timols/jenkins-gitlab-merge-request-builder-plugin
Mirantis 5.0 需要 Virtualbox 4.2 以上的版本, Debian wheezy 只有 4.1 的.
按照 https://wiki.debian.org/VirtualBox/ 来做, 安装 wheezy-backports 版的
这里是一道面试题:
已知一个二叉树的前序遍历结果是(ACDEFHGB) ,中序遍历结果是(DECAHFBG),请问后续遍历结果是_____
求解方式,首先看前序(根左右),那么A是树的根,再看中序(左根右),A的左边就是树的左边DEC,同理,右边就是HFBG。回到前序看AC那么DEC在树的左边,那么C就是A的左孩子;然后看前序CD,中序C的左边有DE,那么D是C的左孩子,右边在DEC中没有了,就证明没有右孩子。然后看前序DE,中序E在D的右边,所以E是D的右孩子,同理..........
所以最后就是
A
/\
C F
/ /\
D H G
\ /
E B
所以后序遍历也就出来了吧:EDCHBGFA
是的是的
Ref: #46
1是更好的选择 ->
* Jenkins Github Plugins
* Gitlab Plugins
* Jenkins URL + Git Hooks
test2
经典冒泡排序:
void BubbleSort_1(int a[], int size)
{
for (int i = 0; i < size -1; i++)
{
for (int j = size - 1; j > i ; j--)
{
if (a[j-1] > a[j])
{
int temp = a[j-1];
a[j-1] = a[j];
a[j] = temp;
}
}
}
}
优化1、在第二层循环时,如果交换操作没有发生,那么证明现在这个序列就是有序的,就可以跳出这个循环。
void BubbleSort_2(int a[], int size)
{
bool bSwaped = true;
for (int i = 0; i < size -1; i++)
{
// 每次先重置为false
bSwaped = false;
for (int j = size - 1; j > i ; j--)
{
if (a[j-1] > a[j])
{
int temp = a[j-1];
a[j-1] = a[j];
a[j] = temp;
bSwaped = true;
}
}
// 如果上一次扫描没有发生交换,则说明数组已经全部有序,退出循环
if (!bSwaped)
break;
}
}
优化2、如果现在有序的区间是[1,i],第二层循环扫描的就是[i,n],这样交换操作就一定是发生在[i,n]这个区间中,记上次交换的位置为l,i《=l 《= n,那么可以确定[1,l]都是有序的,这样就可以缩小下次扫描区间为[l,n]。
void BubbleSort_3(int a[], int size)
{
int l = 0,lt = 0;
for (int i = 0; i < size - 1; i++)
{
l = lt;
for (int j = size - 1; j > l; j--)
{
if (a[j - 1] > a[j])
{
int temp = a[j - 1];
a[j - 1] = a[j];
a[j] = temp;
lt = j;
}
}
//如果没有发生交换,证明已经有序
if (l == lt)
break;
}
}
https://github.com/showcases/text-editors
Here I found Vim (my favorite text editor)'s modern clone - neovim, AWESOME! YouCompleteMe runs fast!
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
engine = create_engine('sqlite://')
Base.metadata.create_all(engine)
from sqlalchemy import create_engine, MetaData
from sqlalchemy.ext.declarative import declarative_base
engine = create_engine('sqlite://')
metadata = MetaData(bind=engine)
Base = declarative_base(metadata=metadata)
Base.metadata.create_all()
query like:
session.query(User).filter(User.name.like(q))
query order:
session.query(User).sort_by(User.id)
# desc
session.query(User).sort_by(User.id.desc())
Brand | Size |
---|---|
Arc'teryx | XS |
Marmot | S |
这是cell在重用之前执行的,啥也不说,记住它。
https://haifengl.wordpress.com/2015/02/17/learn-asynchronous-programming-with-starbucks/
Interesting post about async programming.
Agile Software Development by Robert. Martin. 3rd Edition 中文版 P92.
软件实体(类,模块,函数等等)应该是可以扩展的,但是是不可修改的。
什么是开放?
“对于扩展是开放的” (Open for extension)
什么是封闭?
“对于更改是封闭的” (Close for modification)
很多时候即使你想要更改模块,人家也不允许,比如商业上闭源的库,如IOS开发提供的SDK,是无法修改模块的,只提供头文件和编译好的库。 Object-C本身是一种基于消息的语言,方法可以在运行时具体调用时来查找,所以可以使用Category和Extension来扩展。
如果像C++
,Java
此类静态语言,该如何实现对于扩展是开放的
呢?那就需要用到C++
和Java
的抽象类。关键一点就是抽象。
像Ruby
, Python
此类动态语言,实现扩展开放更简单了,其语言支持Duck typing。还有支持接口(Interface)的语言,比如Java
, Object-C
,也是可以的。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.