|
|
线程安全,保证在应用的 lifetime 中只生成一次。其他一些语言实现需要加同步锁如 Java
|
|
|
|
|
|
|
|
栈的实现
|
|
计算机网络由一组通过通信信道连接的机器组成,有 host
和 router
,host
是运行了应用程序的计算机。router
能够将信息从一个通信信道转发或传递到另一个通信信道。通信信道是将字节序列从一个 host 传输到另外一个 host 的手段。不同 host 的差异性通过和 router 连接连进行消除
传递的字节序列被称为分组报文,一组报文包括了基本的控制信息和用户数据,要传递这些报文需要定义 protocol,它规定了报文交换的方式和结构以及如何解析,TCP/IP 就是来解决这个问题的。他是一个协议簇主要包含 网络层的 IP 协议,传输层的 TCP 和 UDP 等。网络层负责将分组报文传输到目的地址,IP 协议提供将每组分组报文独立处理分发的能力,每个 IP 报文包含目的主机地址字段。但是 IP 协议不能保证报文完整的百分之百的正确的传递到目标主机,偶尔会丢失报文,报文乱序等。在 IP 协议之上为传输层,TCP 和 UDP 协议是进一步的寻址,他们采用端口号作为地址来区分同一主机上的不同应用,因为 IP 只能发到主机 不能区分应用。所以他们称为端到端的传输协议。
TCP 提供可信赖的字节流信道,他能检测和恢复 IP 层提供的主机到主机信道中可能发生的报文丢失,重复和其他错误。TCP在使用时候要先建立连接所以它是面向连接的协议。建立连接就需要常常提到的三次握手,断开连接采用四次握手。相反 UDP 不能对IP层产生的错误进行修复,他扩展了 IP 层的数据报服务功能使其能够在应用程序间工作。所以它叫做 用户数据报协议,他是不可靠的。
PS: IP 地址和域名不表
Socket 是在传输层和应用层之间的一中抽象层,应用程序可以使用 socket 来发送和接收数据就像在磁盘上读取和写入数据一样。TCP/IP 协议簇中的 socket 为 Stream Socket 和 datagram socket,它们分别应用 TCP 和 UDP 协议。一个 Steam Socket 代表了 TCP 连接的一端,TCP/IP 套接字有一个 地址和端口唯一确定。
本文翻译自:
https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/index.html#//apple_ref/doc/uid/TP40007457
由于对内容理解程度不够深入,翻译内容难免有不当之处还望指正。
View Controllers 是你的应用内部结构的基础,每个应用至少有一个 VC 大部分应用有多个 VC的。每个 VC 管理你的应用的用户界面的一部分以及底层数据和用户界面之间的交互。VC 也有助于在你的应用的用户界面之间进行切换。
因为 VC 在你的 app 中扮演如此重要的角色,VC 几乎是你所做一切工作的核心. UIViewController
类定义了管理 view 的方法和属性,处理事件,从一个 VC 切换到另一个 VC,他也协调你 app 的其他部分。你定义 UIViewController
的子类(或者其子类之一)并且你需要添加实现你的 app 的 行为的自定义代码。
这里有两种类型的 VC:
prsent
的这样便利的方式呈现不同地视图控制器的内容。大多数 VC 是这两种类型的混合。
视图控制器最重要的角色是管理视图的层次结构。每个视图控制器有一个 根视图(root view)它包含了视图控制器的所有内容,你在根视图中添加用于展示内容的视图。图 1-1
展示了视图控制器和视图之间的内在关系。视图控制器总是有对其根视图的引用并且每个视图对齐子视图都是强引用。
图1-1 视图控制器和其视图之间的关系
注意
在你的视图控制器层级中使用outlets
去访问其他视图是常用的方法,因为一个视图控制器管理所有视图的内容,outlets
可以让你存储你需要的视图的引用。当视图从storyboard
加载的时候,outlets
本身自动的链接到实际的视图对象。
一个内容视图控制器自己管理其说有的视图,一个容器视图控制器(container view controller)管理其自己的视图以及来自其一个或多个子视图控制器的根视图。容器视图控制器不管理他子视图的内容。它只管理根视图,根据容器的设计进行尺寸调整和位置的摆放。图1-2 显示了一个视图分割的视图控制器和他子视图之间的关系。这个分割的视图控制器管理管理其子视图的整体的大小和位置,但是子视图控制器真正管理这些视图的内容。
图1-2 视图控制器可以管理其他视图控制器的内容。
关于管理视图控制器的视图的信息可以查看 Managing View Layout
一个视图控制器充当在它管理的视图和你应用的数据之间的媒介。UIViewController
类的属性和方法可以让你管理你的应用的视觉呈现。当你继承UIViewController
后,你可以在你的子类中添加任何你需要用来管理数据的变量。添加自定义变量会创建一个如图1-3 所示的关系,其中视图控制器具有对你数据的应用以及用于呈现数据的视图。在这两者直接来回移动数据是你的工作。
图1-3 视图控制器在数据对象和视图之间调解
你应该始终在视图控制器和数据对象中保持清晰的职责分工。大多数的确保数据结构完整性的逻辑属于数据对象的本身。视图控制器可以校验来自视图的输入然后以数据对象需要的格式打包输入,但是你应该最小化视图控制器在管理实际数据中的角色。
UIDocument
对象是一个独立于视图控制器来管理你的数据的方式。一个文档(doucument)对象是一个控制器对象,它知道如何读取和写入数据到持久化存储当中。当你继承 UIDocument
时候,你可以添加所需的任何逻辑和方法来提取数据,并将其传递给视图控制器或应用程序的其他部分。视图控制器可以存储他接受的任何数据的副本,以便更新视图,但文档仍然拥有真实的数据。
视图控制器是响应者(responder) 对象 ,能够处理响应者链中传递下来的事件。尽管他们都能够处理事件,视图控制器很少直接处理触摸事件。相反,视图经常处理他们自己的触摸事件然后将结果报告给关联的委托(delegate)或目标对象(通常是视图控制器)的方法。所以视图控制器的大多数事件都是使用委托方法或操作方法处理的。
关于在视图控制器中实现操作方法的更多信息,请查看Handling User interractions.有关处理其他类型的事件,请查看 Event handling Guide for iOS
视图控制器对其视图和它创建的任何对象承担全部责任。 UIViewController
类自动处理视图管理的大多数方面。举个例子,UIKit 自动释放不在需要的任何视图相关的资源。在你的 UIViewController
子类中,你负责管理你明确创建的任何对象。
当可用空闲内存不足时,UIKit 要求应用程序释放不在需要的资源。一种方式是通过调用视图控制器的 didReceiveMemoryWarning
方法。用这个方法移除不再需要的对象的引用或者稍后可以轻松重新创建。例如,你可能用这个方法删除了缓存数据,当低内存条件发生的时候,他是一个你能够释放更多内存的重要方法。应用消耗太多内存的话可能被系统恢复内存彻底终止。
视图控制器负责呈现其视图,并使该呈现适应底层环境。每个 iOS 应用应该能够在 iPadshang运行,并且可以在几种不同大小的 iPhone 上运行。而不是为每个设备提供不同的视图控制器和视图层次结构。使用单一视图控制器管理视图使其适应不断变化的空间要求更为简单。
在 iOS 中,视图控制器需要处理粗粒度编号和细粒度变化。粗粒度变化发生在视图控制器特征的变化。特征是描述整个环境的属性,像显示的比例。两个重要的特征是视图控制器的水平和垂直尺寸类别,它表示视图控制器在给定维度有多少空间。你可以使用尺寸类别的变化来更改你布局视图的类别,像 图1-4 显示的那样。当尺寸种类是 regular
时候,视图控制器利用额外的空间去管理它的内容,当是 compact
时候,视图控制器垂直排列其内容。
图1-4 调整视图大小类的变化
在给定的尺寸级别类中,任何时候都可能发生更细粒度的尺寸变化。当用户将 iPhone 从纵向旋转到横向时,尺寸类别可能不会改变,但是屏幕尺寸通常会改变。当你使用自动布局时候,UIKit
自动调整视图的大小和位置去匹配新的屏幕大小,视图控制器可以需求进行其他调整。
有关更多的适应性的信息,请查看The Adaptive Model
]]>create two file : AlterViewController.h and AlterViewController.m. .h file is the head file like C style. we can create class and declare property. .m file is is the implementation file it implement method and create instance object.
We should import UIKith to head file and then inherit from UIViewController
create implementation of AlterViewController. We should import AlterViewController.h and then implementation AlterViewController and override viewDidLoad method and so on .
UIView is flexible and easy to customize We can use iOS API to set its propety.We can set frame(position,size)、background color、gesture… etc. let’s look at the details.
UIView *alterView = [[UIView alloc]init];
in objective-c we can get an instance object use grammar likeObject *property = [[ Object alloc]init]
alloc return a new instance and initialized to a data structrue that describes the class memory for all other instance variables is set to 0;
In the first pleace we should have a concept of view coordinator system in UIKit .The default coordinate system has its origin in the top-left corner and has axes that extend down and to the right from the origin point .Firgure 1 show this concept
Figure 1
We can set UIView postion and size with frame rectangle. It create a rectangle return from CGRectMake Function that can define the position of rectangle
CGRectMake have four arguments: x,y rectangle width and heightCGRect CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height);
you should get x,y-coordinate depends the origin point (0,0) at the top-left corner
For the example, I want to set UIView height with 160
and width with screenwidth -30
Why subtract 30 ? because the X is 15 I want the UIView have a same safe area to the phone border The Firure 2 show the description .
Figure 2
The height same as the above. set height is 160 so I should subtract the View height and margin that’s why Y = screenHeight - 175 (175 = 160 +15)
For this section we set the UIView position and size completed.
We already create View and set the view position. we should add the view to the SuperView now
background: When we create view and want to display it add a view to the end of the receiver’s list of subviews is necessary. we can use ddSubview
method
From the Apple API description:the method establishes a strong reference to view and set its next responder to the receiver,which is its new superview. Views can have only one superview.If view already has a superview and that view is not receiver,this method removes the privious superview before making the receiver its new superview.
Add sub view method:
self.view rpresents the current view not the view we just created. alterView
will be presented soon.
If you want to listener the tap action we should add tap recognizer to the View.For example you want to dismiss the UIView when to tap the point out of UIView.
UITapGestureRecognizer object have a action of selector you should define the selector,eg: we can dismiss our UIView.
Now we can display the UIView on the other View.
#import "AlterViewController.h"
#import "AlterViewController.h"
alter.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:alter animated:YES completion:nil];
Explain: when we present the view we the the modal style. you can found the guide from here
https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/PresentingaViewController.html
UIModalPresentationOverCurrentContext result like figure 3
Figure 3 The current context presentation style
Source file https://github.com/shuiqingliu/IOS_Dev/tree/master/Assignment1/Assignment1
@xizhou help me to understand the concepte of UITapGestureRecongnizer.
]]>Environment :Mac Sierra10.12.6,OpenSSH,Global Proxy with IPv6
ERROR like this photo below:
ssh_exchange_identification: Connection closed by remote host
I searched for a long time and try it by myself,all of not work I realized that the problem was not that simple. So I go to next way.
I found the Message give me key_load_public: no such file or directory
,this message cause me to focus on this direction .As you know it still don’t work well,when you check the connection with command ssh -T git@github.com -vvv
you can get the same message of the key_load even if you can connect properly.
I saw a message when I very upset,It is Connecting to github.com port 21473
,Holy S**t as you know the ssh default port is 22 ,I am stupid to use 21473
connect the github, I recall that I have changed the local ssh port. so I type ssh -T -p 22 git@github.com
it worked well.
There have to ways to solve this,the first way is change the ssh port to default value 22
,the second way use Using SSH over the HTTPS port
Enjoy your coding time and focus on the error message.
]]>Item | Value |
---|---|
HardWare Name | BCM94352HMB |
Vendor ID | 14E4 |
Device ID | 43B1 |
System Version | macOS Sierra(10.12.5 16F73) |
Laptop info | Hasee K610-I7-D2 |
There are a few steps for dealing with wif & bluetooth
Tools:
Reboot your computer and then quickly press the ESC
button,When you into the BIOS option select SCU
Item then move to Advanced
option ,the very important step is set the value of XHC
tosmart auto
The operation like this
KCMP Utility Pro
tools to install FakePCIID.kext
, FakePCIID_Broadcom_WiFi.kext
and FakePCIID_XHCIMux.kext
into /Library/Extensions
BrcmFirmwareRepo.kext
and BrcmPatchRAM2.kext
from RehabMan’s bitbucket https://bitbucket.org/RehabMan/os-x-brcmpatchram/downloads//Library/Extensions
ACPI/DSDT/Patches/
|
|
When you driver the BCM94352HMB you can check it use IORegistryExplorer tools,open the tools you can find the bluetooth port.connect to network and try to use AirDrop Enjoy your hackintosh!
@RehabMan
@toleda
@jqqqqqqqqqq
@wx3124558
@yuxans
PS:If you find a grammatical error please let me know, I am learning to write a blog in English this time.
]]>look this link: https://www.continuum.io/downloads
2. setting anaconda
- Add the anaconda bin PATH in your .bashrc file or maybe you are using zsh the file will be .zshrc:
1 vim .bashrc
add the following line to the file
|
|
and then load the config use source .bashrc
conda update --all
|
|
activate enviroment
|
|
install opencv
|
|
|
|
File-->Settings-->Project Interpreter
,click the right button like a gear then click add local input the path of ~/anaconda3/envs/opencv/bin/python
click ok button to save the setting题目描述:
Given any string of N (>=5) characters, you are asked to form the characters into the shape of U. For example, “helloworld” can be printed as:
h d
e l
l r
lowo
That is, the characters must be printed in the original order, starting top-down from the left vertical line with n1 characters, then left to right along the bottom line with n2 characters, and finally bottom-up along the vertical line with n3 characters. And more, we would like U to be as squared as possible – that is, it must be satisfied that n1 = n3 = max { k| k <= n2 for all 3 <= n2 <= N } with n1 + n2 + n3 - 2 = N.
输入:
There are multiple test cases.Each case contains one string with no less than 5 and no more than 80 characters in a line. The string contains no white space.
输出:
For each test case, print the input string in the shape of U as specified in the description.
样例输入:
helloworld!
ac.jobdu.com
样例输出:
h !
e d
l l
lowor
a m
c o
. c
jobdu.
|
|
最后祝大家刷题愉快!
]]>Code::Blocks is a free, open-source, cross-platform IDE. Using a plugin architecture, its capabilities and features are defined by the provided plugins.
codeblocks
的仓库 因为我用的Ubuntu所以直接去添加仓库:
https://launchpad.net/~damien-moore/+archive/ubuntu/codeblocks-stable/
|
|
Setting--->General settings ----> Terminal to launch console programs
选择 genome-terminal -t $TITLE -x
Setting--->General settings--->Open default workspace
还要设置下on project load 为 open all project files
Setting-->Editor--->Margins and caret在caret栏目选择颜色和宽度就可(光标)
Setting-->Editor--->Syntax highlight 设置颜色主题
检查配置文件的权限
|
|
如果用户和所属组均为root 则修改权限
|
|
背景:我拿到机子之前是刷过openwrt的,然后系统崩溃了,DHCP和wifi全挂了,我直接TFTP再刷一次openwrt
Let’s do it!
PS:先给Ubuntu装个tftp:sudo apt-get install tftp
192.168.1.2
子网掩码255.255.255.0
输入如下命令,然后耐心的等待重启,直至绿灯长亮说明系统启动完毕(大约5分钟)
|
|
具体输入如下图所示:
|
|
如图:
|
|
192.168.1.1
,密码为之前设置的密码,登录之后在Network
下wifi
目录下打开wifi并点击edit
-Wireless Security
设置wifi密码.system-software-avaliable package
搜索chinese
安装base-zh-cn那个包就OK了.来张web界面图:
|
|
software-properties-gtk --open-tab=4
打开addition driver
选择xorg-xserver
然后再执行如下操作解决办法:Linux下找到home/username/.AndroidStudio(版本号)/restart/restarter.sh 将改脚本执行一下即可完成升级脚本内容自己可以看一下
这还不行,还需要开启apache的rewrite模块,由于我服务器是Ubuntu系统很简单,一个命令搞定:
sudo a2enmod rewrite
sudo service apache2 restart
问题完美解决
在/etc/default/dnsmasq中添加DNSMASQ_EXCEPT=lo
|
|
1.首先我的Fragment的布局根节点为RelativeLayout,首先获得Relativelayout的View 对
2.创建带有参数的MapView对象其中如下则为设置缩放控件不显示
|
|
3.然后设置mapview在RelativeLayout中的摆放,因为其父控件为RelativeLayout所以这里使用
|
|
来给他设置wrap_content。
4.将mapview 添加到RelatvieLayout中
将通过RelativeLayout的id获取到的view转型为RelativeLayout,然后调用其addView方法将MapView添加到布局中。
|
|
这就完成了将MapView动态添加到Fragment并设置其缩放控件不显示的步骤,如果你看到了这里非常感谢您。下方高能预警,不要打我
其实,我昨晚睡了一觉今天早上发现了3.4的sdk在mapview中已经直接提供了设置方法。那就是直接在布局文件中创建MapView然后通过如下方法设置
希望你看到这里不要骂我,其实应该高兴,因为昨晚上我花了好几个小时,在想如何抛弃官方的SupportMapFragment来实现MapView的添加,用我自定义的Fragment来添加。这下想出来了,替你想好了。多省时省力。
]]>删除其他内容只保留如下:
auto lo
iface lo inet loopback
第二步 :sudo subl /etc/NetworkManager/NetworkManager.conf
将其中:
[ifupdown]
managed=true
改为:
[ifupdown]
managed=false
第三步:重启networkmanager服务
sudo service network-manager restart
]]>