Posts List

Shell常用命令

本文整理一些在linux或mac的shell命令及脚本的使用。 文件操作 递归的创建目录 mkdir -p 目录名 如:mkdir -p test1/test2/test3 命令行下打开Finder并指向当前路径 open . 列出文件 ls -a:全部文件 -d:仅列出目录本身 -l:列出长数据串,包含文件的属性 -t:按时间排序 -S:按文件大小排序 -r:将排序结果反向输出 -R:与子目录一起列出来 拷贝 ...

chrome源码之 FileStream

FileStream is a basic interface for reading and writing files synchronously or asynchronously with support for seeking to an offset. Generally speaking, we normally use asynchronous mode on a TYPE_IO Thread, because it’s more effective. Note that even when used asynchronously, only one operation is supported at a time. FileStream class declare classNET_EXPORT FileStream { public: // Creates a |FileStream| with a new |BoundNetLog| (based on |net_log|) // attached. |net_log| may be NULL if no logging is needed. // Uses |task_runner| for asynchronous operations. FileStream(net::NetLog* net_log, const scoped_refptr<base::TaskRunner>& task_runner); // |flags| is a bitfield of base::PlatformFileFlags when the file handle was // opened. FileStream(base::PlatformFile file, int flags, net::NetLog* net_log, const scoped_refptr<base::TaskRunner>& task_runner); // The underlying file is closed automatically. virtual ~FileStream(); // Call this method to open the FileStream asynchronously. The remaining // methods cannot be used unless the file is opened successfully. Returns // ERR_IO_PENDING if the operation is started. If the operation cannot be // started then an ...

Git常用命令

本文整理了一些git的常用操作和配置。 基本操作 仓库管理 clone到本地仓库 git clone git_addr ["指定目录"] 远程拉取更新本地仓库 git pull 添加文件 git add file or folder 删除文件(也可以直接删除,git commit -am会识别) git rm [-rf] file or folder 提交部分变更的文件 git commit file1 file2 ... -m "message" 提交所有本地更新的文件 git commit -am "message" 查看本地仓库状态 git status 本地仓库更新同步到远 ...

chrome源码之 SequencedWorkerPool

SequencedWorkerPool is a worker thread pool that allow you to post unordered tasks, and it also can enforce ordering between sets of tasks. What’s more, It allows you to specify what should happen to your tasks on shutdown. Ordered Tasks To enforce ordering, get a unique sequence token from the pool and post all tasks you want to order with the token. All tasks with the same token are guaranteed to execute serially, though not necessarily on the same thread. This means that: No two tasks with the same token will run at the same time. Given two tasks T1 and T2 with the same token such that T2 will run after T1, then T2 will start after T1 is destroyed. If T2 will run after T1, then all memory changes in T1 and T1’s destruction will be visible to T2. Example: SequencedWorkerPool::SequenceToken token = pool.GetSequenceToken(); pool.PostSequencedWorkerTask(token, SequencedWorkerPool::SKIP_ON_SHUTDOWN, FROM_HERE, base::Bind(...)); pool.PostSequencedWorkerTask(token, SequencedWorkerPool::SKIP_ON_SHUTDOWN, FROM_HERE, base::Bind(...)); Notes You can make named sequence ...

Java 字符串

本文介绍java的字符串及其编码转换。 String 基本用法 String是常量字符串,正因为是常量使得String对象可以安全的在变量间分享。 例如: String a = "hello"; a += " world"; // 相当于把a指向a+“ world”得到的常量字符串 String b = a; // 共享a指向的常量字符串 构造函数 String(char[] value) 分配一个新的 String,使其表示字符数组参数中当前包含的字符序列。 String(char[] value, int ...

chrome源码之 Network Stack

The network stack is a mostly single-threaded cross-platform library primarily for resource fetching. Its main interfaces are URLRequest and URLRequestContext. URLRequest, as indicated by its name, represents the request for a URL. URLRequestContext contains all the associated context necessary to fulfill the URL request, such as cookies, host resolver, proxy resolver, cache, etc. Many URLRequest objects may share the same URLRequestContext. Most net objects are not threadsafe, although the disk cache can use a dedicated thread, and several components (host resolution, certificate verification, etc.) may use unjoined worker threads. Since it primarily runs on a single network thread, no operation on the network thread is allowed to block. Therefore we use non-blocking operations with asynchronous callbacks (typically CompletionCallback). Net Code Layout base - Grab bag of net utilities, such as host resolution, cookies, network change detection, SSL. disk_cache - Cache for web resources. ftp - FTP implementation. Code is primarily based on the old HTTP implementation. http - HTTP implementation. ...

JS 类实现

在Javascript中,类的实现是基于原型继承来实现的,类的一个重要特征是“动态扩展”(dynamically extendable)的能力。这种动态扩展和自省的能力也是动态脚本语言的强大之处。 原型与工厂函数 工厂函数也是创建对象的一种方式,借助与inherit函数可以简单的实现工厂函数。 function range(from, to) { var r = inherit(range.methods); r.from = from; r.to = to; return r; ...

macOS下java开发环境配置

本文介绍下Mac下java开发环境中常用工具(jdk, idea, maven等)的配置,包括系统环境变量的配置。 JDK jdk是 Java 语言的软件开发工具包。 下载jdk 当前下载的版本是 jdk-8u45-macosx-x64.dmg,下载后安装即可,安装目录在 /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk 配置jdk 在~/.bash_profile中添加配置: export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar 添加 $JAVA_HOME/bin 到PATH 关于 ...

JS 函数

函数function在Javascript中是一等公民,是一种特殊的对象,函数可以作为参数传给其他高阶函数,支持匿名函数,还支持强大的闭包特征,总之javascript的函数是非常精彩的。 函数定义 函数使用function关键字来定义: 函数定义表达式 var square = function(x) { return x*x; } 函数声明 function distance( x1, y1, x2, y2 ) { var dx = x2 - x1; var dy = y2 - y1; return Math.sqrt( dx*dx + ...

JS 数组

数组是值的有序集合,Javascript数组是无类型的,数组元素可以是任意类型,并且同一数组中的不同元素也可以是不同类型。 创建数组 数组直接量 var ary = [1, 'hello', {x:1}, [2,3,5]]; 使用Array()的构造函数 var a = new Array(); var b = new Array(10); // 指定数组长度 var c = new Array(2,3,5,'hello'); // 指定数组元素 数组元素的读写 数组是对象的特殊形式,使用方括号[]和数字索引访问数组元素: Jav ...

JS 对象

本文介绍Javascript的Object对象类型的重点内容。 对象创建 对象直接量 var point = { x:0, y:100 }; new关键字 var o = new Object( {v:100} ); var a = new Array([1,2,3]); 原型 每个对象都是从原型继承属性,通过{}和new Object()创建的对象都是从Obejct.prototype继承。 利用原型继承,可以从现有对象继承来创建新的对象,并且保证新对象的继承属性 ...

JS 字符串

本文详细介绍javascript中的字符串处理,包括String对象的使用,以及正则表达式RegExp的相关细节。 字符串是JavaScript的一种基本的数据类型。JavaScript 的字符串是不可变的(immutable),String 类定义的方法都不能改变字符串的内容。像String.toUpperCase()这样 ...

C++11 类型重命名(Type Alias and Alias Template)

Type alias is a name that refers to a previously defined type (similar to typedef), and alias template is a name that refers to a family of types. Syntax Alias declarations are block declarations with the following syntax: using identifier = type-id; template < template-parameter-list > using identifier = type-id; identifier - the name that is introduced by this declaration template-parameter-list - template parameter list, as in template declaration type-id - abstract declarator or any other valid type-id. For alias template declaration, type_id cannot directly or indirectly refer to identifier Explanation A type alias declaration introduces a name which can be used as a synonym for the type denoted by type-id. It does not introduce a new type and it cannot change the meaning of an existing type name. There is no difference between a type alias declaration and typedef declaration. An alias template is a template which, when specialized, is equivalent to the result of substituting the template arguments ...

chrome源码之 ObserverList

ObserverList<ObserverType> is a container for a list of observers, it is an easy-to-use observer pattern for two related objects. Unlike a normal STL vector or list, this container can be modified during iteration without invalidating the iterator. So, it safely handles the case of an observer removing itself or other observers from the list while observers are being notified. If you want to deal with observer_list in multi-thread, just use ObserverListThreadSafe. ObserverList template <classObserverType, bool check_empty = false> classObserverList : public ObserverListBase<ObserverType> { //... }; #define FOR_EACH_OBSERVER(ObserverType, observer_list, func) \ do { \ if ((observer_list).might_have_observers()) { \ ObserverListBase<ObserverType>::Iterator it(observer_list); \ ObserverType* obs; \ while ((obs = it.GetNext()) != NULL) \ obs->func; \ } \ } while (0) Example #include "base/observer_list.h" classMyWidget; classMyObserver { public: MyObserver( MyWidget * widget ); virtual void OnFoo(MyWidget* w) { //... } virtual void OnBar(MyWidget* w, int x, int y){ //... } }; classMyWidget { public: void AddObserver(MyObserver* obs) { observer_list_.AddObserver(obs); } void RemoveObserver(MyObserver* obs) { ...

chrome源码之 Notification Registrar

Event register and callback are very common and useful in an app, chrome implements an simple, uncoupled and smart Notification Mechanism. NotificationRegistrar This class is designed to register for notifications and ensures that all registered notifications are unregistered when the class is destroyed. The intended use is that you make a NotificationRegistrar member in your class and use it to register your notifications instead of going through the notification service directly. It will automatically unregister them for you. // callback interface classCONTENT_EXPORT NotificationObserver { public: virtual void Observe(int type, const NotificationSource& source, const NotificationDetails& details) = 0; protected: virtual ~NotificationObserver() {} }; // notification registrar classCONTENT_EXPORT NotificationRegistrar : NON_EXPORTED_BASE(public base::NonThreadSafe) { public: // This class must not be derived from (we don't have a virtual destructor so // it won't work). Instead, use it as a member in your class. NotificationRegistrar(); ~NotificationRegistrar(); // Wrappers around NotificationService::[Add|Remove]Observer. void Add(NotificationObserver* observer, int type, const NotificationSource& source); void Remove(NotificationObserver* observer, int type, const ...