omiga

简单就好

多个github帐号的SSH key切换

发表评论»

github使用SSH与客户端连接。如果是单用户(first),生成密钥对后,将公钥保存至github,每次连接时SSH客户端发送本地私钥(默认~/.ssh/id_rsa)到服务端验证。单用户情况下,连接的服务器上保存的公钥和发送的私钥自然是配对的。但是如果是多用户(first,second),我们在连接到second的帐号时,second保存的是自己的公钥,但是SSH客户端依然发送默认私钥,即first的私钥,那么这个验证自然无法通过。不过,要实现多帐号下的SSH key切换在客户端做一些配置即可。

首先cd到~/.ssh 使用 ssh-keygen -t -rsa -C ‘second@mail.com’ 生成新的SSH key:id_rsa_second,生成完后将新的SSH public key添加到github。

ssh-keygen -t -rsa -C 'second@mail.com'

默认SSH只会读取id_rsa,所以为了让SSH识别新的私钥,需要将其添加到SSH agent

ssh-add ~/.ssh/id_rsa_second

该命令如果报错:Could not open a connection to your authentication agent.无法连接到ssh agent,可执行ssh-agent bash命令后再执行ssh-add命令。

完成以上步骤后在~/.ssh目录创建config文件,该文件用于配置私钥对应的服务器。内容如下:

# Default github user(first@mail.com)
Host github.com
 HostName github.com
 User git
 IdentityFile C:/Users/username/.ssh/id_rsa

# second user(second@mail.com)
Host github-second
 HostName github.com
 User git
 IdentityFile C:/Users/username/.ssh/id_rsa_second

阅读全文»

JavaScript中的property和attribute

发表评论»

首先看看这两个单词的英文释义(来自有道词典)。先是property:

property ['prɔpəti]

n. 性质,性能;财产;所有权

英英释义:

  1. any area set aside for a particular purpose “the president was concerned about the property across from the White House”
    同义词:place
  2. something owned; any tangible or intangible possession that is owned by someone “that hat is my property”; ” he is a man of property”
    同义词:belongings | holding | material possession
  3. a basic or essential attribute shared by all members of a class
  4. a construct whereby objects or individuals can be distinguished “self-confidence is not an endearing property”
    同义词:attribute | dimension
  5. any movable articles or objects used on the set of a play or movie
    同义词:prop

重点看2、3、4条。

再看attribute:

attribute [ə'tribju:t, 'ætribju:t]

n. 属性;特质
vt. 归属;把…归于

英英释义:

n.

  1. a construct whereby objects or individuals can be distinguished
    同义词:property | dimension
  2. an abstraction belonging to or characteristic of an entity

v.

  1. attribute or credit to ”We attributed this quotation to Shakespeare”
    同义词:impute | ascribe | assign
  2. decide as to where something belongs in a scheme
    同义词:assign

property,attribute都作“属性”解,但是attribute更强调区别于其他事物的特质/特性,而在这篇文章中也提交到attribute是property的子集

而在JavaScript中,property和attribute更是有明显的区别。众所周知,setAttribute是为DOM节点设置/添加属性的标准方法:

var ele = document.getElementById("my_ele");
ele.setAttribute("title","it's my element");

但很多时候我们也这样写:

ele.title = "it's my element";

如果不出什么意外,他们都运行的很好,它们似乎毫无区别?而且通常情况下我们还想获取到我们设置的“属性”,我们也很爱这样写:

alert(ele.title);

这时候,你便会遇到问题,如果你所设置的属性属于DOM元素本身所具有的标准属性,不管是通过ele.setAttribute还是ele.title的方式设置,都能正常获取。但是如果设置的属性不是标准属性,而是自定义属性呢?

阅读全文»

SSI详解

发表评论»

SSI(Server Side Include)使用在HTML中,用于在请求内容返回到客户端前执行页面中的SSI命令,生成动态内容。通常用于多个页面引用公共的内容模块,将此模块分离出来,使用SSI引入即可。

<!--#include virtual="/inc/header.html"-->

以上代码便能在服务端完成header.html的动态引入,非常简单。

服务端配置

使用SSI之前需要服务端进行简单的配置,开启SSI功能。SSI是针对HTML增加动态内容的技术,所以只对HTML类型文件(.html,.shtml),使用SSI功能的文件建议使用.shtml后缀,便于维护。如果使用.shtml后缀需在服务端作一些配置:

AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

第一行命名配置将.shtml作为html文件返回

第二行命令用于在返回请求内容前执行页面中的SSI命令,如果你在.html文件中使用SSI,那么将.shtml改为.html即可。

SSI命令

SSI的语法有点像HTML注释,所以如果SSI不能识别,那么将被视作HTML注释处理。SSI的语法功能主要包括:变量的设置/获取,文件的引用,可执行命令,条件表达式等。

SSI基本语法

<!--#command param="value"-->

SSI的语法非常简单,但使用中需注意以下几点:

  1. <!–与#之间无空格
  2. SSI大小写敏感
  3. 所有value需写在引号中

config命令

config命令主要用于修改SSI的默认设置,诸如时间格式,默认错误信息,文件大小单位。

设置默认错误信息:errmsg

<!--#config errmsg="Error,please contact webmaster@mail.com"-->

定义日期和时间格式:timefmt

<!--#config timefmt="%A, %B %d, %Y"-->

定义文件大小单位

<!--#config sizefmt="bytes"-->

config命令只对其后使用的命令生效。同时,后定义的设置具有更高的优先级,会覆盖之前的设置。

阅读全文»

博客手机版

4条评论»

心血来潮,简单弄了个手机版。用USER_AGENT判断了下客户端,不是很准确,基本能用。手机上算是比之前web版看得舒服一点,暂时就这样了~···

omiga手机版

omiga手机版

Git笔记-进阶

发表评论»

tag

在git中可以为任意其他对象添加tag,包括commit,tree,blob,甚至包括tag自身。git中都是用sha-1标识git对象,这是一个40个字符长度的字符串,不方便记忆,那么可为git对象添加一个tag便于标识不同对象。

添加tag

# git tag tag-name sha-1
$ git tag v1.0 bdc390c2

这样便为bdc390c2的对象添加了一个tag,如果不指定sha-1,会为最近的一个commit对象添加tag

查看tag

使用git tag命令便能查看所有tag

$ git tag

当然可以筛选

$ git tag -l 'v1.*'

删除tag

$ git tag -d <tag-name>

重命名tag

重命名tag有两种方式:

  1. 删除原tag,重新添加
  2. git tag -f 强制替换已存在的tag后,再删除原tag
$ git tag -f <new-tag> <old-tag>
$ git tag -d <old-tag>

tag的分类

  1. 轻量型标签 轻量型标签直接使用 $ git tag <tag-name> <git-object> 即可创建
  2. 标注型(annotated)标签 标注型标签可记录更多的信息,使用 $ git tag -a <tag-name> <git-object> -m ‘tag message’即可创意一个标注性标签