Fedora安装后要做的10件事

Fedora在Linux社区中很流行。 我已经在使用Fedora。 我更喜欢Fedora,因为它具有更新的软件包和虚拟化支持。 如果您不使用它,请尝试。 安装后,Fedora中有一些事情要做,以使用户体验更加流畅。 这些步骤也可以在CentOS,RedHat中实现。

禁用SELinux (Disable SELinux)

SELinux is a security mechanism to prevent intrusions into operating systems. It’s very powerful for security reasons but if you are using Fedora as desktop or if you do not have enough source and knowledge for SElinux try disabling it.  Keep in mind that disabling SELinux does not make us vulnerable to the attacks or make us a target for attackers. It is just an extra security layer for Linux.

SELinux是一种安全机制,可防止入侵操作系统。 出于安全原因,它非常强大,但是如果您将Fedora用作桌面,或者您没有足够的源和知识来了解SElinux,请尝试将其禁用。 请记住,禁用SELinux不会使我们容易受到攻击,也不会使我们成为攻击者的目标。 它只是Linux的额外安全层。

$ sudo nano /etc/selinux/config

Open the file and change SELINUX=enforcing to the SELINUX=disabled

打开文件并将SELINUX=enforcing SELINUX=disabled更改为SELINUX=disabled

  1. # This file controls the state of SELinux on the system.
  2. # SELINUX= can take one of these three values:
  3. #     enforcing – SELinux security policy is enforced.
  4. #     permissive – SELinux prints warnings instead of enforcing.
  5. #     disabled – No SELinux policy is loaded.
  6. SELINUX=disabled
  7. # SELINUXTYPE= can take one of these three values:
  8. #     targeted – Targeted processes are protected,
  9. #     minimum – Modification of targeted policy. Only selected processes are protected.
  10. #     mls – Multi Level Security protection.
  11. SELINUXTYPE=targeted

设置主机名(Set Hostname)

The hostname is the name of the host and it is used by a lot of different application and services in Fedora. To prevent unexpected errors and problems set a reliable hostname to the system.

主机名主机的名称,Fedora中的许多不同应用程序和服务都使用该主机名。 为防止意外的错误和问题,请为系统设置可靠的主机名。

$ sudo nano /etc/hostname

Open hostname file and add the hostname to the file

打开主机名文件,然后将主机名添加到该文件中

poftut1

To apply hostname change reboot the system.

要应用主机名更改,请重新引导系统。

LEARN MORE  What Is OSI (Open Systems Interconnection) Model?
了解更多什么是OSI(开放系统互连)模型?

设定DNS (Setup DNS)

DNS is a core protocol for network communication. It translates domain and host names into IP addresses. To access network/internet fast DNS speed is important so add fast DNS to the system by using the GUI or command line interface.

DNS是网络通信的核心协议。 它将域名和主机名转换为IP地址。 要访问网络/互联网,快速DNS速度很重要,因此请使用GUI或命令行界面将快速DNS添加到系统中。

更新系统 (Update System)

System updates are an important issue for today. It gives new features, security, and stability to the existing systems.

系统更新是当今的重要问题。 它为现有系统提供了新功能,安全性和稳定性。

$ sudo dnf update -y

安装Chrome (Install Chrome)

Chrome is a modern fast browser used millions of people. Chrome does not provide by default in Fedora repositories. We need to add chrome repository and then install it.

Chrome浏览器是一种现代的快速浏览器,已有数百万人使用。 默认情况下, Chrome在Fedora存储库中不提供。 我们需要添加chrome存储库,然后进行安装。

  1. $ sudo cat << EOF > /etc/yum.repos.d/google-chrome.repo
  2. [google-chrome]
  3. name=google-chrome – \$basearch
  4. baseurl=http://dl.google.com/linux/chrome/rpm/stable/\$basearch
  5. enabled=1
  6. gpgcheck=1
  7. gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
  8. EOF
$ sudo dnf install google-chrome-stable

安装Firefox (Install Firefox)

Firefox is old and open source browser whose predecessor is Netscape. Firefox can be found in Fedora repositories.

Firefox是旧的开放源代码浏览器,其前身是Netscape。 Firefox可以在Fedora存储库中找到。

[[email protected] ~]# dnf install firefox -y

禁用IPv6 (Disable IPv6)

IPv6 is a new replacement for IPv4 protocol but for a long time, it does not become primary for now too. If you have no idea about IPv6 application you can disable IPv6.

IPv6是IPv4协议的新替代品,但是很长一段时间以来,它现在也不是主要的。 如果您不了解IPv6应用程序,则可以禁用IPv6。

$ sudo nano /etc/sysctl.conf

And add following lines to the sysctl.conf

并将以下行添加到sysctl.conf

  1. #Disable IPv6
  2. net.ipv6.conf.all.disable_ipv6 = 1
  3. net.ipv6.conf.default.disable_ipv6 = 1
  4. net.ipv6.conf.lo.disable_ipv6 = 1

安装Terminal Yakuake (Install Terminal Yakuake)

Terminals are the heart of the Linux there are a lot of different types. Yakuake brings new concepts to the terminal or command line console usage. Yakuake have the ability to work all workspaces and can be hidden with F12 key.

终端是Linux的心脏,有很多不同的类型。 Yakuake为终端或命令行控制台的使用带来了新的概念。 Yakuake可以处理所有工作区,并且可以使用F12键隐藏。

$ sudo dnf install yakuake -y

启用RPM融合 (Enable RPM Fusion)

RpmFusion is a repo that provides a lot of useful and closed source applications. Using RpmFusion will make your Fedora life easier.

RpmFusion是一个回购协议,提供了许多有用的封闭源代码应用程序。 使用RpmFusion将使您的Fedora生活更加轻松。

  1. $ sudo dnf install -y https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https:/
  2. /download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

安装VLC (Install VLC)

VLC is my favorite multimedia player for years. I can not use my desktop without it. To install VLC use following command.

多年来,VLC是我*喜欢的多媒体播放器。 没有它,我将无法使用桌面。 要安装VLC,请使用以下命令。

$ sudo dnf install -y vlc

Fedora安装信息图后要做的10件事 (10 Things To Do After Fedora Installation Infographic)

10 Things To Do After Fedora Installation Infographic

python变量字符串_Python字符串变量类型

python变量字符串

The string is a type used to hold text data in Python programming language. We can hold name, surname, address, text or similar data in strings. There are different functions that can be used with these string data. In this tutorial, we will look at them in detail.

字符串是一种用于以Python编程语言保存文本数据的类型。 我们可以将名称,姓氏,地址,文本或类似数据保存在字符串中。 这些字符串数据可以使用不同的功能。 在本教程中,我们将详细介绍它们。

定义字符串变量 (Define String Variable)

Defining string is easy as just setting string value into a variable by using quotes. In this example, we create a string variable named s and set string value This is a string by using a single quote.

定义字符串很容易,因为只需使用引号将字符串值设置为变量即可。 在此示例中,我们创建一个名为s的字符串变量,并设置字符串值。 This is a string通过使用单引号引起This is a string 。

s='This is a  string'

访问字符 (Access Characters)

String variables consist of characters. If we need we can access these characters like a character array. We will specify start and end index numbers like a list and we will get related characters. In this example, we will get the first 3 characters by giving 0:3 like below.

字符串变量由字符组成。 如果需要,我们可以像字符数组一样访问这些字符。 我们将像列表一样指定开始和结束索引号,并获得相关的字符。 在此示例中,我们将通过给出0:3来获得前3个字符,如下所示。

  1. s[0:3]
  2. s[3:4]
  3. s[3:]
Access Characters
Access Characters
访问字符

更新字符串(Update String)

We can update a string variable by reassigning new values. In this example, we will set the string variable s value as This is a new string by using a double quote.

我们可以通过重新分配新值来更新字符串变量。 在此示例中,我们将使用双引号将字符串变量s值设置为This is a new string 。

s="This is a new string"

单引号 (Single Quote)

We can use a single quote to define string variables while providing string value. Using a single quote for small symbol-like strings is the best way.

我们可以在提供字符串值的同时使用单引号定义字符串变量。 *佳方法是对像符号一样的小字符串使用单引号。

s='TR'

双引号 (Double Quote)

The double quote can be used in strings where interpolations and natural language messages are required. We can also use a single quote as a string part inside the double quote.

双引号可用于需要插值和自然语言消息的字符串中。 我们还可以将单引号用作双引号内的字符串部分。

s="I'll call you when I'm available"

三重报价 (Triple Quote)

The triple quote is most useful for docstrings and raw string literals definition. The triple quote may wrap multiple lines like below.

三重引号对于文档字符串和原始字符串文字定义*有用。 三重引号可能会包裹多行,如下所示。

  1. sss=”’This
  2. is
  3. a
  4. string”’

转换为大写 (Convert to Uppercase)

To make whole string uppercase use the upper function of the string variable.

要使整个字符串大写,请使用string变量的upper函数。

  1. ss=“This is poftut”
  2. ss.upper()
Convert Uppercase
Convert Uppercase
转换大写

转换为小写(Convert to Lowercase)

To make uppercase chars use lower() function.

要使用大写字符,请使用lower()函数。

  1. sl=“THIS IS POFTUT”
  2. sl.lower()
Convert Lowercase
Convert Lowercase
转换小写

检测字符串类型方法(Detect String Type Methods)

Python provides methods to detect string type. What I mean with string type is for example if the string has numeric characters or uppercase characters etc.

Python提供了检测字符串类型的方法。 我所说的字符串类型是例如,如果字符串具有数字字符或大写字符等。

LEARN MORE  Shell Scripting Languages Examples, Bash, Sh, Python, Powershell, MSDOS, PHP, Tcl, Perl
了解更多Shell脚本语言示例,Bash,Sh,Python,Powershell,MSDOS,PHP,Tcl,Perl

检查数值 (Check Numeric)

We will check the variable type with  isnumeric() function.

我们将使用isnumeric()函数检查变量类型。

  1. >>> num=“8”
  2. >>> print(num.isnumeric())
  3. True
  4. >>> num=“c”
  5. >>> print(num.isnumeric())
  6. False

检查Alpha (Check Alpha)

We will check the variable type with  isalpha() function.

我们将使用isalpha()函数检查变量类型。

  1. >>> a=“poftut1”
  2. >>> print(a.isalpha())
  3. False
  4. >>> a=“poftut”         
  5. >>> print(a.isalpha())
  6. True

检查字母数字 (Check Alphanumeric)

We will check the variable type with  isalnum() function.

我们将使用isalnum()函数检查变量类型。

  1. >>> a=“poftut1”
  2. >>> print(a.isalnum())    
  3. True
  4. >>> a=“!”              
  5. >>> print(a.isalnum())
  6. False

小写 (Lower Case)

We will check variable type with  islower() function.

我们将使用islower()函数检查变量类型。

  1. >>> a=“poftut”
  2. >>> print(a.islower())
  3. True
  4. >>> a=“Poftut”         
  5. >>> print(a.islower())
  6. False

大写 (Upper Case)

We will check the variable type with  isupper() function.

我们将使用isupper()函数检查变量类型。

  1. >>> a=“Poftut”         
  2. >>> print(a.isupper())
  3. False
  4. >>> a=“POFTUT”         
  5. >>> print(a.isupper())
  6. True

检查空字符串 (Check Empty String)

We will check variable type with  isspace() function.

我们将使用isspace()函数检查变量类型。

  1. >>> a=“POFTUT IS”      
  2. >>> print(a.isspace())
  3. False
  4. >>> a=”  “             
  5. >>> print(a.isspace())
  6. True

连接字符串 (Joining String)

Two strings can be joined together. The first string will be joined for each char in the second string as we will see next example.

两个字符串可以连接在一起。 我们将在下一个示例中看到,*个字符串将为第二个字符串中的每个字符连接。

  1. >>> a=“I love poftut”
  2. >>> ” “.join(a)
  3. ‘I   l o v e   p o f t u t’

倒弦 (Reversing String)

Reversing string can be done with reversed() function. But there is a tip here. Use reversed with join because reversed returns iterator which is not a string. By using it with join with null string value we will get reversed string.

反转字符串可以使用reversed()函数完成。 但是这里有一个提示。 与join一起使用reversed,因为reversed返回的迭代器不是字符串。 通过将其与具有空字符串值的连接一起使用,我们将获得反向字符串。

  1. >>> a=“I love poftut”
  2. >>> print(“”.join(reversed(a)))
  3. tutfop evol I

分割字符串 (Splitting String)

The splitting string is easy. By default, space is used as a delimiter. But delimiter can be provided.

分割字符串很容易。 默认情况下,空格用作定界符。 但是可以提供定界符。

  1. >>> a.split()
  2. [‘I’, ‘love’, ‘poftut’]
  3. >>> a.split(‘o’)
  4. [‘I l’, ‘ve p’, ‘ftut’]

替换字符串 (Replacing String)

Replace function gets two parameters first is which chars will be changed, second is what will be new chars.

Replace函数有两个参数,*个是要更改的字符,第二个是新的字符。

  1. >>> a=“I love poftut”
  2. >>> a.replace(“poftut”,“POFTUT”)
  3. I love POFTUT

大写 (Capitalize)

We can capitalize on the start character or first letter of the string by using capitalize function.

通过使用capitalize功能,我们可以利用字符串的起始字符或首字母。

  1. s=“this is a string”
  2. s.capitalize()
Capitalize
Capitalize
大写

计数发生(Count Occurrence)

String variable provides count function to get the count of given characters occurrence. In this example, we will count i .

字符串变量提供count功能来获取给定字符出现的计数。 在此示例中,我们将计算i 。

  1. s=“this is a string”
  2. s.count(‘i’)
Count Occurrence
Count Occurrence
计数发生

带状空间(Strip Spaces)

While working with strings there will be some unwanted spaces at the begging or end of the strings. We can remove the spaces easily with split function.

在使用琴弦时,在琴弦的开头或结尾会有一些多余的空格。 我们可以使用split函数轻松删除空格。

LEARN MORE  How To Check If String Contains A Specific Word in PHP?
了解更多如何在PHP中检查字符串是否包含特定单词?

s=”  this is a string  ” s.strip()

s =”这是一个字符串” s.strip()

Strip Spaces
Strip Spaces
带状空间

将字符串拆分为单词列表(Split String Into Word List)

Another useful function provided by a string is splitting the string into a word list. While slitting space will be used as a delimiter.

字符串提供的另一个有用功能是将字符串拆分为单词列表。 同时分割空间将用作定界符。

  1. s=“this is a string”
  2. word_list = s.split()
Split String Into Word List
Split String Into Word List
将字符串拆分为单词列表

Python字符串变量类型信息图(Python String Variable Type Infographic)

Python String Variable Type Infographic

如何在PHP中随机播放/随机化数组

There are different ways to randomly select elements of an array in PHP. But recurring elements are biggest problem most of them. Here the clean and PHP library supported solution for this. We will use shuffle() function which will change the positions of the given array.

有多种方法可以在PHP中随机选择数组的元素。 但是重复性元素是其中大多数的*大问题。 这里干净PHP库为此提供了支持的解决方案。 我们将使用shuffle()函数来更改给定数组的位置。

随机播放示例 (Shuffle Example)

shuffle() function accept only single parameter which is the array we want to shuffle. shuffle() function will return shuffled array. In this example we will create an array which is consist of numbers from 1 to 20 in a sequential way. Then we will shuffle() this array and print to the screen.

shuffle()函数仅接受单个参数,这是我们要随机播放的数组。 shuffle()函数将返回改组后的数组。 在此示例中,我们将创建一个数组,该数组由120的数字顺序组成。 然后我们将shuffle()这个数组并打印到屏幕上。

  1. <?php
  2. $numbers = range(120);
  3. shuffle($numbers);
  4. foreach ($numbers as $number) {
  5.     echo “$number “;
  6. }
  7. ?>

Here shuffle function accepts an array and changes the keys of the array in place.

这里shuffle功能接受一个数组,并且改变的键阵列就位。

Shuffle Example
Shuffle Example
随机播放示例

As we can see that ordered array will be shuffeled and printed in a random way  like 15,1,10,12,8,…

如我们所见,有序数组将以随机方式(例如15,1、10、12、8,…)改组并打印

LEARN MORE  What is UUID (Universally Unique Identifier)?

Mac上9款常用软件推荐,个个都是良心之作!

对于一台全新的 Mac ,我们除了欣赏它奇妙的工业设计之外,还有一件非常重要的事情,就是装上 我们常用的一些Mac软件。一般,这些软件会一直伴随着我们日常生活、办公、娱乐,所以能在*开始就装上这些优秀的应用,*对是提升幸福感的不错途径。

那么Mac装机必备软件有哪些?有没有Mac上常用的软件推荐?不用急!macdown小编为大家带来一些Mac超常用软件推荐,个个都是良心之作,总有一款是你需要的!

1、Alfred

每次软件推荐,Alfred都位列其中,可见其实用性有多强!

Alfred 能帮你快速打开网页、快速进行自定义搜索、查看剪贴板历史、快速查询单词等等。Alfred 提供的功能虽然很多,但目的只有一个 —— 那就是减少我们工作中的一些重复动作,提升我们的工作效率。你甚至无需鼠标就可以实现各种操作,包括出发各种文件、网络操作,其UI界面使用方便,而且不是通过命令来实现。

使用了你就会离不开它,不信你可以试试哦!

2、CleanMyMac

一款专业的Mac清理工具,只需要一键智能清理,便能让Mac恢复原始*佳性能,其功能非常丰富全面,堪称 macOS 系统清理和优化的超级利器,是MAC系统必不可少的工具。

使用CleanMyMac旨在帮助用户更加方便的清理您系统中的所有垃圾,从而加快电脑运行速度,保持*佳性能,更加稳定、流畅、快速!

3、Camtasia

我们在使用mac过程中免不了遇到需要录制屏幕的工作。

Camtasia是一款专门录制屏幕动作的工具,它能在任何颜色模式下轻松地记录屏幕动作,包括影像、音效、鼠标移动轨迹、解说声音等等,另外,它还具有即时播放和编辑压缩的功能,可对视频片段进行剪接、添加转场效果。它输出的文件格式很多,包括MP4、AVI、WMV、M4V、CAMV、MOV、RM、GIF动画等多种常见格式,是制作视频演示的*佳工具。

4、ScreenFlow

Camtasia用不习惯的朋友可以选择ScreenFlow!

ScreenFlow是OS X 系统上的一款老牌录屏软件,不仅仅支持简单的屏幕录制,还包含各种简单和复杂的编辑功能,可以说是制作屏幕录制视频的强大软件。ScreenFlow可以记录屏幕的任何部分或整个显示器,同时还可以同时捕捉摄像机,iPad或iPhone,麦克风或多声道音频接口以及计算机的音频!

当然,对于一般用户来说,使用OS X 自带的 Quicktime 就可以实现简单的屏幕录制需求了。

5、IINA

一款运行在Mac平台上的开源视频播放器,人们也称之为万能视频播放器。

INA 是一款采用现代设计和流线型功能的mac版在线视频播放器,可以观看视频,管理播放列表,处理媒体内容或为电影加载字幕提等等。iina mac可以加载本地文件或提供视频URL,iina mac可以使用所有流行的媒体格式。

iina mac版界面精美,功能齐全,是苹果必备软件!

6、Audio Hijack

一款功能强大的音频录制软件,用户可以使用audio hijack mac录制互联网的音频流,导入录制好的音频声音或抓取DVD audio光盘的声音。

除此以外,audio hijack mac可以将音频导出为流行的音频文件格式,如MP3,AIFF,AAC,Apple Lossless,FLAC或WAV。

7、Downie

mac平台上*好用的视频下载工具,支持超过1,000个不同的网站(包括YouTube,优酷,Bilibili,Vimeo等),帮你轻松下载数千个不同网站的视频!

Downie 3 for Mac使用简单,仅仅靠拖放即可完成视频下载任务,提升视频下载速度!

8、iStat Menus

如果您正在寻找一种简单易用的工具来监控Mac处理可用资源的方式,那么iStat Menus是您的不错选择!

istat menus mac能够帮助您实时查看所有硬件信息,非常的直观便于查看,实时网速、CPU温度、内存以及硬盘各方面实现全面监控。iStat Menus Mac版让您对电脑运行使用情况了如指掌,真的是人人可用的电脑硬件监测神器。

9、MarginNote X

一款功能强大的阅读和学习工具软件,适用于Mac, iPad, iPhone。它将PDF/EPUB阅读器和多种学习工具集成起来,使得学习者可以在学习时从不同的维度将知识进行重组,连接,从而达到记住,领会的效果。

无论你是研究者,律师,学生,或是终生热爱学习的人,都可以用MarginNote来在阅读时做标注,记笔记,并可以利用思维导图(Mindmap)和大纲工具(Outline)对笔记进行组织,利用标签(Hashtag)创建横向的知识连接,利用学习卡(Flashcards)提高记忆效率。

如果你用上一段时间,你就会发现,MarginNote并不是将这些工具简单的集成起来,而是做了深入和巧妙的融合,让你在不同的工具模式中切换时更加便捷。

隐藏在苹果Mac中的十个强大功能

在计算机产业中苹果的Mac系列成为人们的首选,Mac计算机的强大功能更人们带来生活,办公等事物上带来便捷,在苹果Mac系列中却还有许多我们不知道的强大功能!今天就让您来了解一下苹果Mac中的十个隐藏功能!

1.让计算机替你朗读

屏幕上密密麻麻的文字让你有些发晕?OS X所具备复制能力之一就是文字朗读。你只要选定需要阅读的段落,然后点击页面顶部的编辑>语音>开始朗读。如果你不喜欢朗读的声音,还可以进入系统偏好设置>听写和语音对其进行更换。

2.老板键

在工作时间里,我们应该都看过自己不该看的东西。如果你正在浏览一份招聘启事,突然感觉老板正向你走来,那你可以点击Command + H键把它隐藏起来。点击之后,屏幕上正在显示的任何内容都会被立刻藏到Dock当中。如果你打开了一大堆工作期间不宜浏览的东西,别担心,你还可以点击Command + M将它们通通*小化。

3.挤到打印队列*前端

如果你急着打印一份文件,但却在打印队列里被排在了打印工作不相关内容的同事后头,这岂不是让人非常恼火。别着急,你可以选择办公室里所有的打印机,然后让*先可用的一台打印你的内容。进入系统偏好设置>打印机和扫描仪,选择网络中所有的打印机,然后创建一个打印机池。在你下一次要打印文件的时候,就可以直接选择这个池,而不是单独一台打印机了。

4.对文档进行数字签名

你可以在Mac上保存一份自己的签名,然后在需要对文档进行签名时将其拖拽到其中便可。首先,在一张白纸上用黑笔写上你的名字,然后运行预览程序,开启偏好设置菜单,选择签名>创建签名,并将纸上的签名对准计算机摄像头,确认无误之后点击接受便可。

5.自定义快捷键

不想一遍遍地输入相同的内容?OS X可通过自定义快捷键保存你的按键内容。无论是以“otw”代替“on the way”,还是设置复杂的邮件签名,都可通过该功能搞定。

想要设置文字替换快捷键,你需要进入系统偏好设置>语言和区域>键盘设置>文本,然后点击“+”来添加快捷键。

6.执行超快计算

想要做一些加减乘除运算,大多数人会选择从Dashboard中运行计算器程序。但实际上,你还可以使用一种更为快捷的方式来进行计算,那就是直接在Spotlight当中输入计算问题,答案会直接显示在搜索栏的下方。

7.更快地购物

如果你经常网购,那每次在买东西时输入信用卡就成了件麻烦事。不过Safari允许你保存信用卡号码,并在你每次点击结账时自动填写。想要保存信用卡号,你需要运行Safari,选择偏好设置>自动填写,然后点击信用卡旁边的编辑按钮,将信用卡号码输入便可。

8.隐身模式

OS X的桌面通知是个非常实用的功能,但如果你正在给客户做演示,那你可能不会想要让一条条通知出现在屏幕上。

和iPhone一样,OS X也有一个勿扰模式,你可以进入系统偏好设置>通知,来对通知显示进行设置。通过自定义,你可以让系统在连接到投影仪或电视时自动进入勿扰模式,也能对显示通知的时间进行设置。

9.保护电池

你可以点击屏幕顶部的电池图标来查看系统中*耗电的应用。

10.保护孩子

儿童并不适宜随心所欲地去使用计算机,特别是考虑到互联网当中有大量少儿不宜的内容存在。如果你家小孩有自己的计算机账户,那你可以通过家长控制功能对该账户的功能进行限制。你需要使用你的(管理员)账户登入系统,进入系统偏好设置>家长控制,然后就能对其他账户的权限进行限制了,限制内容涵盖可使用Safari浏览的网页,甚至是使用计算机的时间。

 

Mac电脑录屏导出黑边如何解决

Mac电脑录制屏幕视频时两边有黑边,无论是将录制格式设置为1080p还是默认分辨率,*终生成的视频两边都有黑边,遇到这种情况如何解决呢?原因是 mac 录制出的视频分辨率比例是 16:10 ,比需要的 16:9 高一点。接下来给大家讲一讲Mac电脑录屏导出黑边如何解决。

为什么会出现这些问题呢?原因就在于现在的视频网站支持的都是16:9的显示比例,而当你对本身16:10显示比例的Mac系列电脑录制屏幕的话,在*终导出为16:9的视频文件时,如果为了显示全部内容,要么保持原始比例,这种情况下视频两边有很宽的黑边;要么让视频铺满整个16:9的显示区域,但是画面内容就会变形失真。还有一种方法就是让画面放大铺满整个16:9的显示区域,但是这种情况下有一部分内容就会被拉出画面之外。

那么如何才能在Mac系列电脑上录制屏幕,导出的画面内容不丢失,画面内容不失真变形呢?

解决方法:

使用屏幕显示调节插件,在录制屏幕之前,先用屏幕显示调节插件将Mac系列电脑屏幕显示比例调节为16:9的形式,然后再去录制屏幕,这样录制出的屏幕视频自然也是16:9的比例。当然有的同学会说,屏幕显示比例不是在Mac OS中的系统设置中就可以调节吗?实际情况是,无论怎么调节Mac系列电脑的屏幕显示比例依然是16:10。这里我比较常用的插件是SwitchResX,一般在录制屏幕之前我会把屏幕显示比例调节为2560*1440或者1920*1080。

switchresx mac是一款非常实用的Mac屏幕分辨率修改器,能够简单快速的更改Mac显示屏的分辨率,将Mac的内容显示在不同的屏幕上。

 

macOS终端常用命令大全

不管是在Windows系统还是在macOS系统中,都有一个名为“终端”的应用,对于我们普通人来说它就好像是个很深奥的东西,只有技术流,程序猿才能驾驭。其实不然,今天小编就整理了一些简单的命令,让你轻松使用终端开启macOS系统的隐藏功能。

初识终端
命令的构成:Command Name、Options、Arguments、Extras 四个部分,很多情况下后面三部分都是可省略的。

Options 部分用-作为前导符。其中许多命令的 Options 部分只包含单个字母,这时可以合并。例如:ls -lA和ls -l -A是等效的。Arguments 部分用来细化这个命令或指定这个命令具体的实施对象。Extras 部分则用来进一步实现其他功能。

例子:删除 QQ 这个程序。

rm -R /Applications/QQ.app

为什么要使用命令行/如何开启命令行?
许多功能在图形界面不提供,只有通过命令行来实现。 Finder会隐藏许多你不太会需要的文件,然而 command line 会允许你访问所有文件。 通过 command line 可以远程访问你的 Mac(利用 SSH)。 administrators 用户可以通过 sudo命令获得 root 用户权限。 通过 command-line script 可以使工作更高效。 Terminal(终端)程序可以在“实用工具”里找到。 如果你开启手动输入用户名登录模式,登陆时在用户名处输入 >console 可以直接进入命令行界面。随后你仍然需要登录到一个账户。

关于 man 命令
不管是mac还是linux都有很多命令,不可能熟练掌握所有命令,即使忘记了使用Google也能查到。mac*强大的一个命令应该算 man xxx ,Mac有上千条命令,每条命令还有许多可选参数和具体的使用方式,但是你却不需要记住这些命令。你只需要记住一个:man,查看具体的命令说明,想要推出直接键入q即可。

大多数命令都会包含一个使用指南,会告诉你任何你需要知道的关于这个命令的所有细节,在命令行中输入 man command-name即可获取。例如,你想知道ls这个命令怎么使用,输入man ls即可进入使用指南页面。使用指南往往很长,所以你可以使用▲(上箭头)或▼(下箭头)来上下移动,使用 来翻页,输入/和关键字来按照关键字搜索,按Q来退出使用指南页面。

那么——如果你连命令名称都不知道怎么办呢?输入man -k和关键字来对整个使用指南数据库进行搜索。

MacOS 常用终端命令大全:
目录操作

%title插图%num

文件操作

%title插图%num

选择操作

%title插图%num

安全操作

%title插图%num

编程操作

%title插图%num

进程操作

%title插图%num

时间操作

%title插图%num

网络与通信操作

%title插图%num

Korn Shell 命令

%title插图%num

其它命令

%title插图%num

 

mac终端命令

1.查看当前目录下文件:

ls

2.查看当前所在目录:

psw

3.显示当前目录下的隐藏文件:

ls -ah

4.返回上级目录:

cd ..

5.创建一个空目录:

mkdir fileName

6.打开配置文件:

open ~/.bash_profile

7.自动补全代码:

tab

8.查看mac ip地址

ifconfig

Mac终端使用技巧 切换到其他路径和目录

如果你想将当前 command line 会话切换到其他目录,需要用到三个命令:pwd,ls和cd。

pwd的含义是“print working directory”,会显示当前目录的*对路径。
ls的含义是“list directory contents”,它会列出当前目录的内容。这个命令还有其他参数可选。
cd的含义是“change directory”,它会改变当前目录到你指定的目录。如果你不指定,则会返回你的 home folder。

pwd      当前工作目录

cd(不加参数)  进root

cd(folder)  进入文件夹

cd ..      上级目录

cd ~      返回root

cd -      返回上一个访问的目录

rm 文件名     删除

cat 文件名(|less)  在终端下查看文件

ls        列出目录下所有文件

cp 文件名 目标目录  将文件拷贝到目标目录下

~代表root  如:~/Document/CPP2/

mkdiv      新建文件夹

g++ 源文件名    编译源文件,产生a.out

./文件名      运行 例如:./a.out < 输入文件名 > 输出文件名

control+d     中断a.out运行

nano       编写脚本语言  ctrl+o存储

nano ….sh    打开

bash ….sh    运行脚本

echo “…$i…”   输出语句

tar -zxf abc.tar.gz tar文件解压

ssh root@192.168.1.222 以root账号远程连接222服务器

unrar x abc.rar rar文件解压,需要安装rar工具

open /Users/sunww 使用 open 命令,如打开/Users/sunww 文件夹

Android service ( 一 ) 三种开启服务方法

Android service ( 一 ) 三种开启服务方法

一、 Service简介

Service是android 系统中的四大组件之一(Activity、Service、BroadcastReceiver、ContentProvider),它跟 Activity的级别差不多,但不能自己运行只能后台运行,并且可以和其他组件进行交互。service可以在很多场合的应用中使用,比如播放多媒体的 时候用户启动了其他Activity这个时候程序要在后台继续播放,比如检测SD卡上文件的变化,再或者在后台记录你地理信息位置的改变等等,总之服务总 是藏在后台的。

Service的启动有两种方式:context.startService() 和 context.bindService()

 

二、 Service启动流程

context.startService() 启动流程:

context.startService()  -> onCreate()  -> onStart()  -> Service running  -> context.stopService()  -> onDestroy()  -> Service stop

 

如果Service还没有运行,则android先调用onCreate(),然后调用onStart();

如果Service已经运行,则只调用onStart(),所以一个Service的onStart方法可能会重复调用多次。

如果stopService的时候会直接onDestroy,如果是调用者自己直接退出而没有调用stopService的话,Service会一直在后台运行,该Service的调用者再启动起来后可以通过stopService关闭Service。

所以调用startService的生命周期为:onCreate –> onStart (可多次调用) –> onDestroy

 

context.bindService()启动流程:

context.bindService()  -> onCreate()  -> onBind()  -> Service running  -> onUnbind()  -> onDestroy()  -> Service stop

 

 

context.startService() 启动再context.bindService()启动:

 

context.startService()  -> onCreate()  ->onBind() -> Service running  ->  onUnbind()  ->context.stopService()  -> onDestroy()  -> Service stop

先startService()再context.bindService()的话必须context.stopService() 和 context.onUnbind()都调用才可以停止服务
 

使用再context.bindService()启动时,需要在Service中创建一个IBind接口实例然后通过onBind()方法传入通道,在Activity中要创建一个ServiceConnection()对象作为通道然后实现其中两个方法来获取Service放入通道的IBind接口对象。

onBind() 将返回给客户端一个IBind接口实例,IBind允许客户端回调服务的方法,比如得到Service的实例、运行状态或其他操作。这个时候把调用者 (Context,例如Activity)会和Service绑定在一起,Context退出了,Srevice就会调用 onUnbind->onDestroy相应退出。

所以调用bindService的生命周期为:onCreate –> onBind(只一次,不可多次绑定) –> onUnbind –> onDestory。

在Service每一次的开启关闭过程中,只有onStart可被多次调用(通过多次startService调用),其他onCreate,onBind,onUnbind,onDestory在一个生命周期中只能被调用一次。

%title插图%num

 

三、 Service生命周期 

Service的生命周期并不像Activity那么复杂,它只继承了onCreate()、onStart()、onDestroy()三个方法

当我们*次启动Service时,先后调用了onCreate()、onStart()这两个方法;当停止Service时,则执行onDestroy()方法。

这里需要注意的是,如果Service已经启动了,当我们再次启动Service时,不会在执行onCreate()方法,而是直接执行onStart()方法。

它可以通过Service.stopSelf()方法或者Service.stopSelfResult()方法来停止自己,只要调用一次stopService()方法便可以停止服务,无论调用了多少次的启动服务方法。

 

service可以在和多场合的应用中使用,比如播放多媒体的时候用户启动了其他Activity这个时候程序要在后台继续播放,比如检测SD卡上文件的变化,再或者在后台记录你地理信息位置的改变等等,总之服务嘛,总是藏在后头的。
四、 Service示例

 

下面我做了一个简单的音乐播放的应用,分别使用startService和bindService来启动本地的服务。

先从使用startService启动Service学起

首先编写一个Activity

 

复制代码
public class PlayMusic extends Activity implements OnClickListener {
    private static final String TAG = "PlayMusic";
    private Button playBtn;
    private Button stopBtn;
    private Button pauseBtn;
    private Button exitBtn;
    private Button closeBtn;
 
    //....(详见源码)
 
@Override
    public void onClick(View v) {
        int op = -1;
        Intent intent = new Intent("org.allin.android.musicService");
         
        //广播用
//      Intent intent = new Intent("org.allin.android.musicReceiver");
         
        switch (v.getId()) {
        case R.id.play:
            Log.d(TAG, "onClick: playing muic");
            op = 1;
            break;
        case R.id.stop:
            Log.d(TAG, "onClick: stoping music");
            op = 2;
            break;
        case R.id.pause:
            Log.d(TAG, "onClick: pausing music");
            op = 3;
            break;
        case R.id.close:
            Log.d(TAG, "onClick: close");
            this.finish();
            break;
        case R.id.exit:
            Log.d(TAG, "onClick: exit");
            op = 4;
            stopService(intent);
            this.finish();
            break;
        }
         
        Bundle bundle  = new Bundle();
        bundle.putInt("op", op);
        intent.putExtras(bundle);
        startService(intent);
         
//      sendBroadcast(intent);
    }
 
 
}
复制代码

 

通过重写onClick方法来实现对播放音乐的控制。这里把播放音乐的各种操作用数字的方式通过Intent传递给service。
构造一个Intent ,ntent intent = new Intent(“org.allin.android.musicService”);
“org.allin.android.musicService”是在AndroidManifest.xml文件中对service类的定义

 

<service android:enabled="true" android:name=".MusicService">
<intent-filter>
<action android:name="org.allin.android.musicService" />
</intent-filter>
</service>

把操作码放在Bundle中
Bundle bundle  = new Bundle();
bundle.putInt(“op”, op);
intent.putExtras(bundle);
*后使用startService(intent);启动服务。
下面看看Service是怎么实现的。

MusicService.java

 

复制代码
/**
 * @author allin.dev
 * http://allin.cnblogs.com/
 * 
 */
public class MusicService extends Service {
 
    private static final String TAG = "MyService";
    private MediaPlayer mediaPlayer;
 
    /*
     * (non-Javadoc)
     * 
     * @see android.app.Service#onBind(android.content.Intent)
     */
    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }
 
    @Override
    public void onCreate() {
        Log.v(TAG, "onCreate");
        if (mediaPlayer == null) {
            mediaPlayer = MediaPlayer.create(this, R.raw.tmp);
            mediaPlayer.setLooping(false);
        }
    }
 
    @Override
    public void onDestroy() {
        Log.v(TAG, "onDestroy");
        if (mediaPlayer != null) {
            mediaPlayer.stop();
            mediaPlayer.release();
        }
    }
 
    @Override
    public void onStart(Intent intent, int startId) {
        Log.v(TAG, "onStart");
        if (intent != null) {
            Bundle bundle = intent.getExtras();
            if (bundle != null) {
 
                int op = bundle.getInt("op");
                switch (op) {
                case 1:
                    play();
                    break;
                case 2:
                    stop();
                    break;
                case 3:
                    pause();
                    break;
                }
 
            }
        }
 
    }
 
    public void play() {
        if (!mediaPlayer.isPlaying()) {
            mediaPlayer.start();
        }
    }
 
    public void pause() {
        if (mediaPlayer != null && mediaPlayer.isPlaying()) {
            mediaPlayer.pause();
        }
    }
 
    public void stop() {
        if (mediaPlayer != null) {
            mediaPlayer.stop();
            try {
                // 在调用stop后如果需要再次通过start进行播放,需要之前调用prepare函数
                mediaPlayer.prepare();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
 
}
复制代码

服务 使用了系统自带MediaPlayer进行音乐的播放控制。 当调用了startService后服务会先调用onCreate,我们在里面对MediaPlayer进行初始化。接着会调用onStart,可以看到传递给startService()的Intent对象会传递给onStart()方法,这样我们就可以得到intent里面的操作码:
Iundle bundle = intent.getExtras();
int op = bundle.getInt(“op”);

图中的”close”和“exit”是不同的,close只是调用finish()退出当前的Activity,但是Service并没有关掉,音乐会继续播放。而exit就是调用了stopService(intent);来停止服务,Service会调用onDestroy()方法来对mediaPlayer进行停止和释放资源。
有时候如果服务只提供一些操作接口,我们也可以通过广播的g方式来启动服务。
首先要定义一个Receiver,并继承BroadcastReceiver,然后在AndroidManifest.xml中进行注册:

 

<receiver android:name=".MusicReceiver">
<intent-filter>
<action android:name="org.allin.android.musicReceiver" />
</intent-filter>
</receiver>

 

Receiver的实现:

MusicReceiver.java
复制代码
/**
 * @author allin.dev
 * http://allin.cnblogs.com/
 *
 */
public class MusicReceiver extends BroadcastReceiver {
 
    private static final String TAG = "MusicReceiver";
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "onReceive");
        Intent it = new Intent("org.allin.android.musicService");
        Bundle bundle = intent.getExtras();
        it.putExtras(bundle);
         
        if(bundle != null){
            int op = bundle.getInt("op");
            if(op == 4){
                context.stopService(it);
            }else{
                context.startService(it);
            }
        }
         
    }
 
}
复制代码

然后对PlayMusic中的onclick方法进行些改造,把Intent指向Receiver
Intent intent = new Intent(“org.allin.android.musicReceiver”);
intent中绑定的操作码都不变,再调用sendBroadcast(intent);把intentg广播出去。
当MusicReceiver接受到广播后根据操作码进行相应的操作。

接下来的例子就是使用bindService来启动Service
首先一样是写一个Activity

 

复制代码
public class PlayBindMusic extends Activity implements OnClickListener {
 
    private static final String TAG = "PlayBindMusic";
    private Button playBtn;
    private Button stopBtn;
    private Button pauseBtn;
    private Button exitBtn;
     
    private BindMusicService musicService;
 
    @Override
    public void onClick(View v) {
 
        switch (v.getId()) {
        case R.id.play:
            Log.d(TAG, "onClick: binding srvice");
            musicService.play();
            break;
        case R.id.stop:
            Log.d(TAG, "onClick: stoping srvice");
            if(musicService != null){
                musicService.stop();
            }
            break;
        case R.id.pause:
            Log.d(TAG, "onClick: pausing srvice");
            if(musicService != null){
                musicService.pause();
            }
            break;
        case R.id.exit:
            Log.d(TAG, "onClick: exit");
            this.finish();
            break;
        }
    }
 
 
private void connection(){
        Log.d(TAG, "connecting.....");
        Intent intent = new Intent("org.allin.android.bindService");
        bindService(intent, sc, Context.BIND_AUTO_CREATE);
         
    }
private ServiceConnection sc = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            musicService = null;
            Log.d(TAG, "in onServiceDisconnected");
        }
         
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            musicService = ((BindMusicService.MyBinder)(service)).getService();
            if(musicService != null){
                musicService.play();
            }
             
            Log.d(TAG, "in onServiceConnected");
        }
    };
}
复制代码

 

这里使用了bindService(intent, sc, Context.BIND_AUTO_CREATE);来启动服务的,
我们需要定义ServiceConnectionnn,并实现里面的方法,当服务绑定成功后会调用ServiceConnectionnn中的回调函数:
public void onServiceConnected(ComponentName name, IBinder service),
回调函数里面使用musicService = ((BindMusicService.MyBinder)(service)).getService();来获取BindMusicService服务对象,有了BindMusicService实例对象,就可以调用服务提供的各种控制音乐播放的哦功能。
下面看看BindMusicService.java的实现:

 

复制代码
/**
 * @author allin.dev
 * http://allin.cnblogs.com/
 */
public class BindMusicService extends Service {
 
    private static final String TAG = "MyService";
    private MediaPlayer mediaPlayer;
 
    private final IBinder binder = new MyBinder();
 
    public class MyBinder extends Binder {
        BindMusicService getService() {
            return BindMusicService.this;
        }
    }
 
    /*
     * (non-Javadoc)
     * 
     * @see android.app.Service#onBind(android.content.Intent)
     */
    @Override
    public IBinder onBind(Intent intent) {
        Log.d(TAG, "onBind");
        play();
        return binder;
    }
 
    @Override
    public void onCreate() {
        super.onCreate();
         
        Log.d(TAG, "onCreate");
        Toast.makeText(this, "show media player", Toast.LENGTH_SHORT).show();
         
         
    }
 
    @Override
    public void onDestroy() {
        super.onDestroy();
         
        Log.d(TAG, "onDestroy");
        Toast.makeText(this, "stop media player", Toast.LENGTH_SHORT);
        if(mediaPlayer != null){
            mediaPlayer.stop();
            mediaPlayer.release();
        }
    }
 
     
    public void play() {
        if (mediaPlayer == null) {
            mediaPlayer = MediaPlayer.create(this, R.raw.tmp);
            mediaPlayer.setLooping(false);
        }
        if (!mediaPlayer.isPlaying()) {
            mediaPlayer.start();
        }
    }
 
    public void pause() {
        if (mediaPlayer != null && mediaPlayer.isPlaying()) {
            mediaPlayer.pause();
        }
    }
 
    public void stop() {
        if (mediaPlayer != null) {
            mediaPlayer.stop();
            try {
                // 在调用stop后如果需要再次通过start进行播放,需要之前调用prepare函数
                mediaPlayer.prepare();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
 
}
复制代码

我们看到Service中有个返回IBinder对象的onBind方法,这个方法会在Service被绑定到其他程序上时被调用,而这个IBinder对象和之前看到的onServiceConnected方法中传入的那个IBinder是同一个东西。应用和Service间就依靠这个IBinder对象进行通信。

 

 

五、 拓展知识(进程和声明周期)

 

Android操作系统尝试尽可能长时间的保持应用的进程,但 当可用内存很低时*终要移走一部分进程。怎样确定那些程序可以运行,那些要被销毁,Android让每一个进程在一个重要级的基础上运行,重要级低的进程 *有可能被淘汰,一共有5级,下面这个列表就是按照重要性排列的:

1 一个前台进程显示的是用户此时需要处理和显示的。下列的条件有任何一个成立,这个进程都被认为是在前台运行的。
a 与用户正发生交互的。
b 它控制一个与用户交互的必须的基本的服务。
c 有一个正在调用生命周期的回调函数的service(如onCreate()、onStar()、onDestroy())
d 它有一个正在运行onReceive()方法的广播接收对象。
只有少数的前台进程可以在任何给定的时间内运行,销毁他们是系统万不得已的、*后的选择——当内存不够系统继续运行下去时。通常,在这一点上,设备已经达到了内存分页状态,所以杀掉一些前台进程来保证能够响应用户的需求。

2 一个可用进程没有任何前台组件,但它仍然可以影响到用户的界面。下面两种情况发生时,可以称该进程为可用进程。
它是一个非前台的activity,但对用户仍然可用(onPause()方法已经被调用)这是可能发生的,例如:前台的activity是一个允许上一 个activity可见的对话框,即当前activity半透明,能看到前一个activity的界面,它是一个服务于可用activity的服务。

3 一个服务进程是一个通过调用startService()方法启动的服务,并且不属于前两种情况。尽管服务进程没有直接被用户看到,但他们确实是用户所关心的,比如后台播放音乐或网络下载数据。所以系统保证他们的运行,直到不能保证所有的前台可见程序都正常运行时才会终止他们。

4 一个后台进程就 是一个非当前正在运行的activity(activity的onStop()方法已经被调用),他们不会对用户体验造成直接的影响,当没有足够内存来运 行前台可见程序时,他们将会被终止。通常,后台进程会有很多个在运行,所以他们维护一个LRU*近使用程序列表来保证经常运行的activity能*后一 个被终止。如果一个activity正确的实现了生命周期的方法,并且保存它当前状态,杀死这些进程将不会影响到用户体验。

5 一个空线程没有运行任何可用应用程序组,保留他们的唯一原因是为了设立一个缓存机制,来加快组件启动的时间。系统经常杀死这些内存来平衡系统的整个系统的资源,进程缓存和基本核心缓存之间的资源。
Android把进程里优先级*高的activity或服务,作为这个进程的优先级。例如,一个进程拥有一个服务和一个可见的activity,那么这个进程将会被定义为可见进程,而不是服务进程。

此 外,如果别的进程依赖某一个进程的话,那么被依赖的进程会提高优先级。一个进程服务于另一个进程,那么提供服务的进程不会低于获得服务的进程。例如,如果 进程A的一个内容提供商服务于进程B的一个客户端,或者进程A的一个service被进程B的一个组件绑定,那么进程A至少拥有和进程B一样的优先级,或 者更高。

因为一个运行服务的进程的优先级高于运行后台activity的进程,一个activity会准备一个长时间运行的操作来启动一 个服务,而不是启动一个线程–尤其是这个操作可能会拖垮这个activity。例如后台播放音乐的同时,通过照相机向服务器发送一张照片,启动一个服务会 保证这个操作至少运行在service 进程的优先级下,无论这个activity发生了什么,广播接收者应该作为一个空服务而不是简单的把耗时的操作单独放在一个线程里。