在 Linux/Windows/Mac 上刷新 DNS 缓存的方法

当浏览器无法访问正常域名时,我们需要刷新系统的 DNS 缓存,使浏览器的访问恢复正常。不同系统中刷新 DNS 缓存的命令如下:

Windows 系统:

在旧版本中打开 dos 窗口执行:ipconfig /flushdns
在新版本中需要以管理员的身份打开 dos 窗口执行:ipconfig /flushdns

Linux 系统:

在旧版本中打开终端执行:/etc/rc.d/init.d/nscd restart
在新版本中打开终端执行:/etc/init.d/nscd restart

Max OS X 系统:

在旧版本中打开终端执行:lookupd -fluashcache
在新版本中打开终端执行:dscacheutil -flushcache

vim 中 ^M 解决方法

有两种情况,会在打开的文件中出现 ^M 符号:

1. vim 被配置为 fileformat=unix,而打开的文件是 dos 格式。

unix 格式的换行符 ascii 码为 OA (<LF>),dos 格式的换行符 ascii 码为 OD OA (<CR><LF>),而 OD 在 vim 里就显示为 ^M。

dos, mac 和 unix 格式的简介

回想计算机的史前史,那时的打字机使用两个字符来开始新的一行。首先是回车字符 OD 使打印头移回开始位置,然后用进纸字符 OA 使打印机向前进纸一行。

在计算机诞生之初,存储设备十分昂贵。于是有人就提出没有必要用两个字符来表示一行的结束。unix 一族决定只用进纸一个字符 <LineFeed> 来表示行尾。来自苹果阵营的人则把回车 OD 作为换行的标准。而微软公司(ms-dos,windows)仍然决定沿用古老的回车换行 OD OA 传统。

这就意味着文件在不同系统间转移时,会遇到与换行相关的问题。vim 编辑器则可以识别这些不同格式的文件。你可以在 fileformats 选项里指定你希望 vim 能自动识别的格式集合。

下面这条命令就能让 vim 自动识别 unix 格式和 ms-dos 格式:
:set fileformats=unix,dos
把这条命令写在 vimrc 中,通常情况下都能自动识别。

2. 你的文本中既有 unix 的换行符,又有 dos 的换行符,那么 vim 会认为你打开的是 unix的,所以那些 dos 的换行符就会出现恼人的 ^M。不过这种情况不常见,方法如下:

1)若你的 vim 版本大于 7.1 并想用 dos 显示和保存,执行命令:
:e ++ff=dos

2)若你的 vim 版本小于等于 7.1 又想把文章按照 dos 格式显示和保存,执行命令:
:set ff=dos
:%s/\r\+$//e

3)若你的 vim 版本小于等于 7.1 又想把文章按照 unix 格式显示和保存,执行命令:
:set ff=unix
:%s/\r\+$//e

High cpu usage from Finder/QTKitServer when you open a folder with mkv files

Hi all

As some of you may have noticed, if you have installed Perian and have a folder full of mkv files, Finder and QTKitServer will go a bit crazy when you open this folder. This is because they are trying to create thumbnail images for the movies automatically and most of the time fail on mkv files or broken avi files, thus causing the high cpu/disk thrashing (often even after you’ve closed the folder).

There is a fix for this, but I must warn you not to do any of this if you arent comfortable modifying system files. I have tested it on my own system with good results however.

OSX has a sandbox layer in which almost all processes run, including system processes. This sandbox has rules and by modifying those rules, we can change how things work. In this case we are changing the rules so that QTKitServer will not be able to touch mkv files. Note that this may also have the side effect of you not being able to open mkv files in QuickTime anymore, in which case just use VLC or some other movie player instead.

If you are ready to proceed, do the following:

Open Terminal, type:

sudo nano /System/Library/Sandbox/Profiles/com.apple.qtkitserver.sb

This will open the nano editor with the rules file. Scroll right to the bottom of this file and enter:

(deny file-read* (regex #”^.*\.mkv$”))

After this do Ctrl-O and then Ctrl-X to save and exit the application.

The effect will be immediate and you should have no more issue with thumbnail generation going crazy in a folder with mkv’s. It will not affect any other video or audio files.

Again if you arent comfortable in terminal or with modifying system files, I would suggest not doing this yourself. For everybody else, I hope this helps

Reference: http://forums.macrumors.com/showthread.php?t=1463364

Windows 下 vim 配置详解

Windows 下 vim 的配置文件在安装目录下,名为 _vimrc,常见配置如下:

01. vim 配色
color evening

02. vim 字体
set guifont=Courier_New:h14:cANSI

03. 不要使用 vi 的键盘模式,而是 vim 自己的
set nocompatible

04. 语法高亮
set syntax=on

05. 去掉输入错误的提示声音
set noeb

06. 在处理未保存或只读文件的时候,弹出确认
set confirm

07. 自动缩进
set autoindent
set cindent

08. 设置 Tab 的宽度
set tabstop=4

09. 缩进设置
set softtabstop=4
set shiftwidth=4

10. 不要用空格代替制表符
set noexpandtab

11. 在行和段开始处使用制表符
set smarttab

12. 显示行号
set number

13. 历史记录数
set history=1000

14. 禁止生成临时文件
set nobackup

15. 禁止生成交换文件
set noswapfile

16. 搜索忽略大小写
set ignorecase

17. 高亮搜索内容
set hlsearch
set incsearch

18. 行内替换
set gdefault

19. 高亮显示匹配的括号
set showmatch

20. 匹配括号高亮的时间(单位是十分之一秒)
set matchtime=5

21. 为 C 程序提供自动缩进
set smartindent

22. 设置打开文件的默认编码
set encoding=utf-8
set fileencodings=utf-8,chinese,utf-16le,latin-1
if has(‘win32′)
set fileencoding=chinese
else
set fileencoding=utf-8
endif

23. 设置系统菜单的显示语言
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim

24. 设置终端输出语言
language messages zh_CN.utf-8

25. 设置屏幕显示的编码
set termencoding=字符编码

常见问题解决:
1. 解决 Windows 下 vim 的中文乱码,添加 22,23,24 配置
2. 禁止 vim 自动生成以 ~ 为后缀的文件备份,添加 14 配置

Magento 笔记

# 域名变更
update core_config_data set value=’新域名’ where  value=’旧域名’;

# 重置管理员密码
update admin_user set password=concat(md5(‘识别码admin’),’:识别码’) where user_id=管理员ID;

# 修改底部 Copyright
1. 页脚链接在 后台=>CMS=>Static Blocks=>Footer Links 里修改
2. 模板文件在 app/design/frontend/default/模板名/template/page/html/footer.phtml 里
3. 版权信息在 System=>Configuration=>General=>Design=>Footer=>Copyright 里

Access 笔记

# 数据类型

类型 描述 常量名 常量值
SMALLINT 整型 adSmallInt 2
INT 长整型 adInteger 3
REAL 单精度 adSingle 4
FLOAT 双精度 adDouble 5
MONEY 货币 adCurrency 6
DATETIME 日期时间 adDate 7
BIT 比特 adBoolean 11
TIMESTAMP 毫秒 adDBTimeStamp 135
TINYINT 小整型 adTinyInt 16
UNIQUEIDENTIFIER 同步复制ID adGUID 72
BINARY 二进制 adBinary 128
CHAR 字符 adChar 129
NCHAR UNICODE字符 adWChar 130
DECIMAL 小数 adDecimal 14
SMALLDATETIME 短日期时间 - -
VARCHAR 可变字符 adVarChar 200
TEXT 文本 - -
IMAGE 媒体 - -
MEMO 备注 - -

# 创建表
CREATE TABLE [表名](
[自增] AUTOINCREMENT(1,1) PRIMARY KEY,
[名称] VARCHAR(20) NOT NULL DEFAULT ”,
[库存] INT NOT NULL DEFAULT 0,
)

# 添加字段
ALTER TABLE [表名] ADD COLUMN [字段名] VARCHAR(20)

# 修改字段
ALTER TABLE [表名] ALTER COLUMN [字段名] VARCHAR(20)

# 删除字段
ALTER TABLE [表名] DROP COLUMN [字段名]

# 添加约束
ALTER TABLE ADD CONSTRAINT [约束名] CHECK ([约束字段]<=’2013-01-01′)

# 删除约束
ALTER TABLE DROP CONSTRAINT [约束名]

# 添加默认值
ALTER TABLE ADD CONSTRAINT [默认值名称] DEFAULT ‘默认值’ FOR [字段名]

# ADO 连接方式
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=数据库路径;User Id=用户名;Password=密码;
User Id 与 Password 为可选项,该方式允许在创建表时,设置字段的默认值