.NET 高效开发之不可错过的实用工具(第一的当然是ReSharper插件)

Standard

工欲善其事,必先利其器,没有好的工具,怎么能高效的开发出高质量的代码呢?本文为 ASP.NET 开发者介绍一些高效实用的工具,包括 SQL 管理,VS插件,内存管理,诊断工具等,涉及开发过程的各个环节,让开发效率翻倍。当然,吾乐吧软件站认为.NET神器第一名的绝对是ReSharper,有了这个,基本上其他工具都可以忽略!

.NET 高效开发之不可错过的实用工具(第一的当然是ReSharper插件)

.NET 高效开发之不可错过的实用工具(第一的当然是ReSharper插件)

Visual Studio

  • Jetbrains ReSharper Ultimate:VS最强的插件,没有之一,支持:C#, VB.NET, ASP.NET, XML, XAML, C++, JavaScript,CSS,Razor视图引擎等等~~
  • Visual Studio Productivity Power tool: VS 专业版的效率工具。
  • Web Essentials: 提高开发效率,能够有效的帮助开发人员编写CSS, JavaScript, HTML 等代码。
  • MSVSMON: 远程Debug 监控器 (msvsmon.exe) 是一种轻量级的应用程序,能够远程控制VS来调试程序。在远程调试期间,VS 在调试主机运行,MSVSMON 在远程机器中运行。
  • WIX toolset: 可以将XML 源代码文件编译成Windows 安装包。
  • Code digger: Code Digger 是VS 2012/2013 的扩展插件,能够帮助开发人员分析代码。
  • CodeMaid: CodeMaid 是一款开源的VS2012/2013/2015 插件,提供代码分析,清理,简化代码的功能。
  • OzCode: 非常强大的VS 调试工具。
  • CodeRush: 是VS的提高代码重构和提升效率的VS插件。
  • T4 Text Template:VS中T4 文本模板是生成代码文件最常用的模板文件,这种模板文件是通过编写文本块和控制逻辑来实现的。
  • Indent Guides:  快速添加缩进行。
  • PowerShell Tools:支持开发和调试PowerShell 脚本和VS2015代码块的工具包。
  • Visual Studio Code: 免费的跨平台编辑器,可以编译和调试现代的Web和云应用。

ASP.NET

  • Fiddler: 能够捕获 http 请求/响应来模拟请求行为。
  • AutoMapper: 自动生成对象到对象的映射代码,比如,能够生成从实体对象映射到域对象,而不是手动编写映射代码。Object to object mapping. Like, the tool can be used to map entity objects to domain objects instead of writing manual mapping code.
  • Unity/Ninject/Castle Windsor/StructureMap/Spring.Net: 依赖性映射框架,提供很多可用的DI 框架。
  • .NET Reflector: .NET 程序反编译器。
  • dotPeek: .NET 程序反编译器。
  • ILSpy: .NET 程序反编译器。
  • memprofiler: 非常强大的查找内存泄露和优化内存使用的工具。
  • PostSharp: 去除重复编码和避免由于交叉引用产生的代码冗余。
  • ASPhere: Web.config 图形化编辑器
  • ComponentOne Studio for ASP.NET 一整套完备的开发工具包

WCF

  • SOAP UI: API 测试工具,支持所有标准的协议和技术。
  • WireShark:UNIX和Windows系统的网络协议分析器。用于捕获TCP 层的拥塞状况,还能帮你过滤无效信息。
  • Svc TraceViewer: 提供文件追踪视图,是由WFO提供的。
  • Svc Config Editor: 用于管理WCF相关配置的图形化界面工具。

MSMQ

  • QueueExplorer 3.4: 提供消息操作功能,如复制,删除,移动消息,保存和加载,强压测试,浏览编辑等

LINQ

  • LINQ Pad: LINQPad 是一个轻量级工具,用来测试Linq查询。 可以测试由不同语言写的.Net 语言脚本。
  • LINQ Insight: LINQ Insight Express 可嵌入 Visual Studio 中,能够分析设计时的LINQ查询 。

RegEx

  • RegEx tester: 正则表达式插件。
  • regexr: 在线正则表达式开发和测试工具。
  • regexpal: 在线正则表达式开发和测试工具。
  • Expresso: 桌面版的正则表达式工具。
  • RegexMagic : 能够根据文本模式自动生成正则表达式的工具。

Javascript/JQuery/AngularJS

  • JSHint: JavaScript代码质量监控工具,定义了很多非常严格的规则。
  • JSFiddle: 提供了浏览器内部的开发环境,能够测试HTML,CSS,Javascript/JQuery代码
  • Protractor: 端到端的框架,能够测试Angular应用。

SQL Server

  • SQL Profiler: SQL 跟踪监控工具。
  • ExpressProfiler: ExpressProfiler (aka SqlExpress Profiler) 是一个小型快速的SQL Server Profiler的替换工具,自带GUI界面。能够用于企业版和非企业版 的SQL Server。
  • SQL Sentry Plan explorer: 提供了SQL 查询执行计划的很好的物理视图。
  • SQL Complete: 为 SQL Server Management Studio and Visual Studio 提供非常智能的,优化SQL 格式的管理工具。
  • NimbleText:文本操作和代码生成工具。
  • Query Express: 轻量级的SQL 查询分析器。
  • IO Meter: 提供IO 子系统的一些访问具体情况
  • sqldecryptor: 可以解密SQL Server 中的加密对象,如存储过程,方法,触发器,视图。
  • SpatialViewer: 可以预览和创建空间数据。
  • ClearTrace: 导入跟踪和分析文件,并显示汇总信息。
  • Internals Viewer for SQL Server: Internals Viewer 用来在SQL Server 的存储引擎中的查找工具,以及获取数据在物理层是如何分配,组织和存储的。

NHibernate

Tally

Tally ERP 9

  • Tally dll: .net 的动态链接库,能够将Tally Accounting 软件集成到应用程序中 ,通过代码对数据进行push或pull操作。

代码Review

  • StyleCop: StyleCop 是静态代码分析工具,能够统一设置代码样式和规范。 可以在Visual Studio 中使用,也可以集成到 MSBuild 项目。
  • FxCop: FxCop 是静态代码分析工具,能够通过分析.Net 程序集保证开发标准。

运行状况捕获

  • WireShark: It is a network protocol analyzer for Unix and Windows. It can capture traffic at TCP level.
  • HTTP Monitor: enables the developer to view all the HTTP traffic between your computer and the Internet. This includes the request data (such as HTTP headers and form GET and POST data) and the response data (including the HTTP headers and body).

诊断工具

  • Glimpse:提供服务器端诊断数据。如 在ASP.NET MVC 项目,可以通过NuGet添加。

性能

  • PerfMon: 使用 性能计数器监控系统性能。

代码转换器

  • Telerik Code Converter: C# 到 VB 及 VB 到C# 代码转换器. I是一个在线编辑工具,可以选择 ‘Batch Converter’ ,并使用压缩包上传文件。

屏幕记录工具

  • Wink: Using Wink, 可以轻松截图,并为截图添加描述等,也可以录制Demo。

文本编辑器

文档工具

  • GhostDoc: GhostDoc 是 Visual Studio 扩展项,能够自动生成 方法或属性的 文档注释,包括它们的类型,名称,其他上下文信息。
  • helpndoc: helpndoc 用于创建帮助文档工具,能够根据文档源生成多种格式。
  • 其他
  • FileZilla: FileZilla 是开源的FTP 工具. 通过FileZilla 客户端可以将文件上传到FTP 服务器上。
  • TreeTrim: TreeTrim 是调整代码的工具,能够删除一些无效的debug文件和临时文件等。
  • BrowserStack: 支持跨浏览器测试的工具。
  • BugShooting: 屏幕截图软件,能够铺货和附加工作项,bug,问题跟踪项等。
  • Postman: REST 客户端,能够发送http请求,分析REST 应用程序发出的响应。
  • Web developer checklist: checklist可用来管理开发计划
  • PowerGUI: 能够快接收和使用PowerShell 来有效管理 Windows 开发环境。
  • Beyond Compare: 提供文件对比功能。
  • PostMan: REST Chrome 器扩展项
  • Devart Codecompare: 文件区分工具,能够读取 C#, C++,VB 代码结构 。包括:文件夹对比工具,独立App 比较合并文件夹和文件,代码review 支持。

C++文件操作详解

Standard

原文:http://www.cnblogs.com/likebeta/archive/2012/06/16/2551662.html

C++ 通过以下几个类支持文件的输入输出:

ofstream: 写操作(输出)的文件类 (由ostream引申而来)
ifstream: 读操作(输入)的文件类(由istream引申而来)
fstream: 可同时读写操作的文件类 (由iostream引申而来)
打开文件(Open a file)
对这些类的一个对象所做的第一个操作通常就是将它和一个真正的文件联系起来,也就是说打开一个文件。被打开的文件在程序中由一个流对象(stream object)来表示 (这些类的一个实例) ,而对这个流对象所做的任何输入输出操作实际就是对该文件所做的操作。

要通过一个流对象打开一个文件,我们使用它的成员函数open():void open (const char * filename, openmode mode);

这里filename 是一个字符串,代表要打开的文件名,mode 是以下标志符的一个组合: ios::in 为输入(读)而打开文件
ios::out 为输出(写)而打开文件
ios::ate 初始位置:文件尾
ios::app 所有输出附加在文件末尾
ios::trunc 如果文件已存在则先删除该文件
ios::binary 二进制方式
这些标识符可以被组合使用,中间以”或”操作符(|)间隔。例如,如果我们想要以二进制方式打开文件”example.bin” 来写入一些数据,我们可以通过以下方式调用成员函数open()来实现:ofstream file;
file.open (“example.bin”, ios::out | ios::app | ios::binary);

ofstream, ifstream 和 fstream所有这些类的成员函数open 都包含了一个默认打开文件的方式,这三个类的默认方式各不相同: 类 参数的默认方式
ofstream ios::out | ios::trunc
ifstream ios::in
fstream ios::in | ios::out
只有当函数被调用时没有声明方式参数的情况下,默认值才会被采用。如果函数被调用时声明了任何参数,默认值将被完全改写,而不会与调用参数组合。

由 于对类ofstream, ifstream 和 fstream 的对象所进行的第一个操作通常都是打开文件,这些类都有一个构造函数可以直接调用open 函数,并拥有同样的参数。这样,我们就可以通过以下方式进行与上面同样的定义对象和打开文件的操作:ofstream file (“example.bin”, ios::out | ios::app | ios::binary);

两种打开文件的方式都是正确的。

你可以通过调用成员函数is_open()来检查一个文件是否已经被顺利的打开了:bool is_open();

它返回一个布尔(bool)值,为真(true)代表文件已经被顺利打开,假( false )则相反。

关闭文件(Closing a file)
当文件读写操作完成之后,我们必须将文件关闭以使文件重新变为可访问的。关闭文件需要调用成员函数close(),它负责将缓存中的数据排放出来并关闭文件。它的格式很简单:void close ();

这个函数一旦被调用,原先的流对象(stream object)就可以被用来打开其它的文件了,这个文件也就可以重新被其它的进程(process)所有访问了。

为防止流对象被销毁时还联系着打开的文件,析构函数(destructor)将会自动调用关闭函数close。

文本文件(Text mode files)
类ofstream, ifstream 和fstream 是分别从ostream, istream 和iostream 中引申而来的。这就是为什么 fstream 的对象可以使用其父类的成员来访问数据。

一般来说,我们将使用这些类与同控制台(console)交互同样的成员函数(cin 和 cout)来进行输入输出。如下面的例题所示,我们使用重载的插入操作符<<:

// writing on a text file
#include &lt;fstream&gt;
using namespace std;

int main()
{
    ofstream examplefile("example.txt");
    if (examplefile.is_open())
    {
        examplefile &lt;&lt; "This is a line.\n";
        examplefile &lt;&lt; "This is another line.\n";
        examplefile.close();
    }
    return 0;
}

从文件中读入数据也可以用与 cin的使用同样的方法:

// reading a text file
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;cstdlib&gt;
using namespace std;
int main ()
{
    char buffer[256];
    ifstream examplefile("example.txt");
    if (! examplefile.is_open())
    {
        cout &lt;&lt; "Error opening file"; exit (1);
    }
    while (!examplefile.eof())
    {
        examplefile.getline(buffer,100);
        cout&lt;&lt;buffer&lt;&lt; endl;
    }
    return 0;
}
//This is a line.
//This is another line.

上面的例子读入一个文本文件的内容,然后将它打印到屏幕上。注意我们使用了一个新的成员函数叫做eof ,它是ifstream 从类 ios 中继承过来的,当到达文件末尾时返回true 。

状态标志符的验证(Verification of state flags)
除了eof()以外,还有一些验证流的状态的成员函数(所有都返回bool型返回值):

bad()
如果在读写过程中出错,返回 true 。例如:当我们要对一个不是打开为写状态的文件进行写入时,或者我们要写入的设备没有剩余空间的时候。

fail()
除了与bad() 同样的情况下会返回 true 以外,加上格式错误时也返回true ,例如当想要读入一个整数,而获得了一个字母的时候。

eof()
如果读文件到达文件末尾,返回true。

good()
这是最通用的:如果调用以上任何一个函数返回true 的话,此函数返回 false 。

要想重置以上成员函数所检查的状态标志,你可以使用成员函数clear(),没有参数。

获得和设置流指针(get and put stream pointers)
所有输入/输出流对象(i/o streams objects)都有至少一个流指针:

ifstream, 类似istream, 有一个被称为get pointer的指针,指向下一个将被读取的元素。
ofstream, 类似 ostream, 有一个指针 put pointer ,指向写入下一个元素的位置。
fstream, 类似 iostream, 同时继承了get 和 put
我们可以通过使用以下成员函数来读出或配置这些指向流中读写位置的流指针:

tellg() 和 tellp()
这两个成员函数不用传入参数,返回pos_type 类型的值(根据ANSI-C++ 标准) ,就是一个整数,代表当前get 流指针的位置 (用tellg) 或 put 流指针的位置(用tellp).

seekg() 和seekp()
这对函数分别用来改变流指针get 和put的位置。两个函数都被重载为两种不同的原型:
seekg ( pos_type position );
seekp ( pos_type position );
使用这个原型,流指针被改变为指向从文件开始计算的一个绝对位置。要求传入的参数类型与函数 tellg 和tellp 的返回值类型相同。
seekg ( off_type offset, seekdir direction );
seekp ( off_type offset, seekdir direction );
使用这个原型可以指定由参数direction决定的一个具体的指针开始计算的一个位移(offset)。它可以是: ios::beg 从流开始位置计算的位移
ios::cur 从流指针当前位置开始计算的位移
ios::end 从流末尾处开始计算的位移
流指针 get 和 put 的值对文本文件(text file)和二进制文件(binary file)的计算方法都是不同的,因为文本模式的文件中某些特殊字符可能被修改。由于这个原因,建议对以文本文件模式打开的文件总是使用seekg 和 seekp的第一种原型,而且不要对tellg 或 tellp 的返回值进行修改。对二进制文件,你可以任意使用这些函数,应该不会有任何意外的行为产生。

以下例子使用这些函数来获得一个二进制文件的大小:

// obtaining file size
#include &lt;iostream&gt;
#include &lt;fstream&gt;
using namespace std;

int main ()
{
    const char * filename = "example.txt";
    long l,m;
    ifstream file(filename, ios::in|ios::binary);
    l = file.tellg();
    file.seekg(0, ios::end);
    m = file.tellg();
    file.close();
    cout &lt;&lt;"size of "&lt;&lt; filename;
    cout &lt;&lt;" is "&lt;&lt; (m-l)&lt;&lt;" bytes.\n";
    return 0;
}
//size of example.txt is 40 bytes.

二进制文件(Binary files)
在二进制文件中,使用<< 和>>,以及函数(如getline)来操作符输入和输出数据,没有什么实际意义,虽然它们是符合语法的。

文 件流包括两个为顺序读写数据特殊设计的成员函数:write 和 read。第一个函数 (write) 是ostream 的一个成员函数,都是被ofstream所继承。而read 是istream 的一个成员函数,被ifstream 所继承。类 fstream 的对象同时拥有这两个函数。它们的原型是:
write ( char * buffer, streamsize size );
read ( char * buffer, streamsize size );
这里 buffer 是一块内存的地址,用来存储或读出数据。参数size 是一个整数值,表示要从缓存(buffer)中读出或写入的字符数。

// reading binary file
#include &lt;iostream&gt;
#include &lt;fstream&gt;
using namespace std;
int main ()
{
    const char * filename = "example.txt";
    char * buffer;
    long size;
    ifstream file(filename, ios::in|ios::binary|ios::ate);
    size = file.tellg();
    file.seekg(0, ios::beg);
    buffer = new char [size];
    file.read(buffer, size);
    file.close();
    cout &lt;&lt;"the complete file is in a buffer";
    delete[] buffer;
    return 0;
}
//The complete file is in a buffer

缓存和同步(Buffers and Synchronization)
当我们对文件流进行操作的时候,它们与一个streambuf 类型的缓存(buffer)联系在一起。这个缓存(buffer)实际是一块内存空间,作为流(stream)和物理文件的媒介。例如,对于一个输出流, 每次成员函数put (写一个单个字符)被调用,这个字符不是直接被写入该输出流所对应的物理文件中的,而是首先被插入到该流的缓存(buffer)中。

当缓存被排放出来(flush)时,它里面的所有数据或者被写入物理媒质中(如果是一个输出流的话),或者简单的被抹掉(如果是一个输入流的话)。这个过程称为同步(synchronization),它会在以下任一情况下发生:

当文件被关闭时: 在文件被关闭之前,所有还没有被完全写出或读取的缓存都将被同步。
当缓存buffer 满时:缓存Buffers 有一定的空间限制。当缓存满时,它会被自动同步。
控制符明确指明:当遇到流中某些特定的控制符时,同步会发生。这些控制符包括:flush 和endl。
明确调用函数sync(): 调用成员函数sync() (无参数)可以引发立即同步。这个函数返回一个int 值,等于-1 表示流没有联系的缓存或操作失败。
在C++中,有一个stream这个类,所有的I/O都以这个“流”类为基础的,包括我们要认识的文件I/O,stream这个类有两个重要的运算符:

1、插入器(<<)
向流输出数据。比如说系统有一个默认的标准输出流(cout),一般情况下就是指的显示器,所以,cout<<“Write Stdout”<<‘n’;就表示把字符串”Write Stdout”和换行字符(‘n’)输出到标准输出流。

2、析取器(>>)
从流中输入数据。比如说系统有一个默认的标准输入流(cin),一般情况下就是指的键盘,所以,cin>>x;就表示从标准输入流中读取一个指定类型(即变量x的类型)的数据。

在C++中,对文件的操作是通过stream的子类fstream(file stream)来实现的,所以,要用这种方式操作文件,就必须加入头文件fstream.h。下面就把此类的文件操作过程一一道来。

一、打开文件
在fstream类中,有一个成员函数open(),就是用来打开文件的,其原型是:

void open(const char* filename,int mode,int access);

参数:

filename: 要打开的文件名
mode: 要打开文件的方式
access: 打开文件的属性
打开文件的方式在类ios(是所有流式I/O类的基类)中定义,常用的值如下:

ios::app: 以追加的方式打开文件
ios::ate: 文件打开后定位到文件尾,ios:app就包含有此属性
ios::binary: 以二进制方式打开文件,缺省的方式是文本方式。两种方式的区别见前文
ios::in: 文件以输入方式打开
ios::out: 文件以输出方式打开
ios::nocreate: 不建立文件,所以文件不存在时打开失败
ios::noreplace:不覆盖文件,所以打开文件时如果文件存在失败
ios::trunc: 如果文件存在,把文件长度设为0
可以用“或”把以上属性连接起来,如ios::out|ios::binary

打开文件的属性取值是:

0:普通文件,打开访问
1:只读文件
2:隐含文件
4:系统文件
可以用“或”或者“+”把以上属性连接起来 ,如3或1|2就是以只读和隐含属性打开文件。

例如:以二进制输入方式打开文件c:config.sys

fstream file1;
file1.open("c:config.sys",ios::binary|ios::in,0);

如果open函数只有文件名一个参数,则是以读/写普通文件打开,即:

file1.open("c:config.sys");&lt;=&gt;file1.open("c:config.sys",ios::in|ios::out,0);

另外,fstream还有和open()一样的构造函数,对于上例,在定义的时侯就可以打开文件了:

fstream file1("c:config.sys");

特别提出的是,fstream有两个子类:ifstream(input file stream)和ofstream(outpu file stream),ifstream默认以输入方式打开文件,而ofstream默认以输出方式打开文件。

ifstream file2("c:pdos.def");//以输入方式打开文件
ofstream file3("c:x.123");//以输出方式打开文件

所以,在实际应用中,根据需要的不同,选择不同的类来定义:如果想以输入方式打开,就用ifstream来定义;如果想以输出方式打开,就用ofstream来定义;如果想以输入/输出方式来打开,就用fstream来定义。

二、关闭文件
打开的文件使用完成后一定要关闭,fstream提供了成员函数close()来完成此操作,如:file1.close();就把file1相连的文件关闭。

三、读写文件
读写文件分为文本文件和二进制文件的读取,对于文本文件的读取比较简单,用插入器和析取器就可以了;而对于二进制的读取就要复杂些,下要就详细的介绍这两种方式

1、文本文件的读写
文本文件的读写很简单:用插入器(<<)向文件输出;用析取器(>>)从文件输入。假设file1是以输入方式打开,file2以输出打开。示例如下:

file2&lt;&lt;"I Love You";//向文件写入字符串"I Love You"
int i;
file1&gt;&gt;i;//从文件输入一个整数值。

这种方式还有一种简单的格式化能力,比如可以指定输出为16进制等等,具体的格式有以下一些

操纵符 功能 输入/输出
dec 格式化为十进制数值数据 输入和输出
endl 输出一个换行符并刷新此流 输出
ends 输出一个空字符 输出
hex 格式化为十六进制数值数据 输入和输出
oct 格式化为八进制数值数据 输入和输出
setpxecision(int p) 设置浮点数的精度位数 输出

比如要把123当作十六进制输出:file1<<hex<<123;要把3.1415926以5位精度输出:file1<<setpxecision(5)<<3.1415926。

2、二进制文件的读写
①put()
put()函数向流写入一个字符,其原型是ofstream &put(char ch),使用也比较简单,如file1.put(‘c’);就是向流写一个字符’c’。

②get()
get()函数比较灵活,有3种常用的重载形式:

一种就是和put()对应的形式:ifstream &get(char &ch);功能是从流中读取一个字符,结果保存在引用ch中,如果到文件尾,返回空字符。如file2.get(x);表示从文件中读取一个字符,并把读取的字符保存在x中。

另一种重载形式的原型是: int get();这种形式是从流中返回一个字符,如果到达文件尾,返回EOF,如x=file2.get();和上例功能是一样的。

还 有一种形式的原型是:ifstream &get(char *buf,int num,char delim=’n’);这种形式把字符读入由 buf 指向的数组,直到读入了 num 个字符或遇到了由 delim 指定的字符,如果没使用 delim 这个参数,将使用缺省值换行符’n’。例如:

file2.get(str1,127,’A’);//从文件中读取字符到字符串str1,当遇到字符’A’或读取了127个字符时终止。

③读写数据块
要读写二进制数据块,使用成员函数read()和write()成员函数,它们原型如下:

read(unsigned char *buf,int num);
write(const unsigned char *buf,int num);

read() 从文件中读取 num 个字符到 buf 指向的缓存中,如果在还未读入 num 个字符时就到了文件尾,可以用成员函数 int gcount();来取得实际读取的字符数;而 write() 从buf 指向的缓存写 num 个字符到文件中,值得注意的是缓存的类型是 unsigned char *,有时可能需要类型转换。

例:

unsigned char str1[]="I Love You";
int n[5];
ifstream in("xxx.xxx");
ofstream out("yyy.yyy");
out.write(str1,strlen(str1));//把字符串str1全部写到yyy.yyy中
in.read((unsigned char*)n,sizeof(n));//从xxx.xxx中读取指定个整数,注意类型转换
in.close();out.close();

四、检测EOF
成员函数eof()用来检测是否到达文件尾,如果到达文件尾返回非0值,否则返回0。原型是int eof();

例:

if(in.eof())ShowMessage("已经到达文件尾!");

五、文件定位
和 C的文件操作方式不同的是,C++ I/O系统管理两个与一个文件相联系的指针。一个是读指针,它说明输入操作在文件中的位置;另一个是写指针,它下次写操作的位置。每次执行输入或输出时, 相应的指针自动变化。所以,C++的文件定位分为读位置和写位置的定位,对应的成员函数是 seekg()和 seekp(),seekg()是设置读位置,seekp是设置写位置。它们最通用的形式如下:

istream &amp;seekg(streamoff offset,seek_dir origin);
ostream &amp;seekp(streamoff offset,seek_dir origin);

streamoff定义于 iostream.h 中,定义有偏移量 offset 所能取得的最大值,seek_dir 表示移动的基准位置,是一个有以下值的枚举:

ios::beg: 文件开头
ios::cur: 文件当前位置
ios::end: 文件结尾
这两个函数一般用于二进制文件,因为文本文件会因为系统对字符的解释而可能与预想的值不同。

例:

file1.seekg(1234,ios::cur);//把文件的读指针从当前位置向后移1234个字节
file2.seekp(1234,ios::beg);//把文件的写指针从文件开头向后移1234个字节

pandasql: Make python speak SQL

Standard

http://blog.yhat.com/posts/pandasql-intro.html

Introduction

One of my favorite things about Python is that users get the benefit of observing the R community and then emulating the best parts of it. I’m a big believer that a language is only as helpful as its libraries and tools.

This post is about pandasql, a Python package we (Yhat) wrote that emulates the R package sqldf. It’s a small but mighty library comprised of just 358 lines of code. The idea of pandasql is to make Python speak SQL. For those of you who come from a SQL-first background or still “think in SQL”, pandasql is a nice way to take advantage of the strengths of both languages.

In this introduction, we’ll show you to get up and running with pandasql inside of Rodeo, the integrated development environment (IDE) we built for data exploration and analysis. Rodeo is an open source and completely free tool. If you’re an R user, its a comparable tool with a similar feel to RStudio. As of today, Rodeo can only run Python code, but last week we added syntax highlighting for a bunch of other languages to the editor (markdown, JSON, julia, SQL, markdown). As you may have read or guessed, we’ve got big plans for Rodeo, including adding SQL support so that you can run your SQL queries right inside of Rodeo, even without our handy little pandasql. More on that in the next week or two!

Downloading Rodeo

Start by downloading Rodeo for Mac, Windows or Linux from the Rodeo page on the Yhat website.

ps If you download Rodeo and encounter a problem or simply have a question, we monitor our discourse forum 24/7 (okay, almost).

A bit of background, if you’re curious

Behind the scenes, pandasql uses the pandas.io.sql module to transfer data between DataFrame and SQLite databases. Operations are performed in SQL, the results returned, and the database is then torn down. The library makes heavy use of pandas write_frame and frame_query, two functions which let you read and write to/from pandas and (most) any SQL database.

Install pandasql

Install pandasql using the package manager pane in Rodeo. Simply search for pandasql and click Install Package.

You can also run ! pip install pandasql from the text editor if you prefer to install that way.

Check out the datasets

pandasql has two built-in datasets which we’ll use for the examples below.

  • meat: Dataset from the U.S. Dept. of Agriculture containing metrics on livestock, dairy, and poultry outlook and production
  • births: Dataset from the United Nations Statistics Division containing demographic statistics on live births by month

Run the following code to check out the data sets.

<code>#Checking out meat and birth data
from pandasql import sqldf
from pandasql import load_meat, load_births

meat = load_meat()
births = load_births()

#You can inspect the dataframes directly if you're using Rodeo
#These print statements are here just in case you want to check out your data in the editor, too
print meat.head()
print births.head()
</code>

Inside Rodeo, you really don’t even need the print.variable.head() statements, since you can actually just examine the dataframes directly.

An odd graph

<code># Let's make a graph to visualize the data
# Bet you haven't had a title quite like this before
import matplotlib.pyplot as plt
from pandasql import *
import pandas as pd

pysqldf = lambda q: sqldf(q, globals())

q  = """
SELECT
  m.date
  , m.beef
  , b.births
FROM
  meat m
LEFT JOIN
  births b
    ON m.date = b.date
WHERE
    m.date &gt; '1974-12-31';
"""

meat = load_meat()
births = load_births()

df = pysqldf(q)
df.births = df.births.fillna(method='backfill')

fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(pd.rolling_mean(df['beef'], 12), color='b')
ax1.set_xlabel('months since 1975')
ax1.set_ylabel('cattle slaughtered', color='b')

ax2 = ax1.twinx()
ax2.plot(pd.rolling_mean(df['births'], 12), color='r')
ax2.set_ylabel('babies born', color='r')
plt.title("Beef Consumption and the Birth Rate")
plt.show()
</code>

Notice that the plot appears both in the console and the plot tab (bottom right tab).

Tip: You can “pop out” your plot by clicking the arrows at the top of the pane. This is handy if you’re working on multiple monitors and want to dedicate one just to your data visualzations.

Usage

To keep this post concise and easy to read, we’ve just given the code snippets and a few lines of results for most of the queries below.

If you’re following along in Rodeo, a few tips as you’re getting started:

  • Run Script will indeed run everything you have written in the text editor
  • You can highlight a code chunk and run it by clicking Run Line or pressing Command + Enter
  • You can resize the panes (when I’m not making plots I shrink down the bottom right pane)

Basics

Write some SQL and execute it against your pandas DataFrame by substituting DataFrames for tables.

<code>q = """
    SELECT
        *
    FROM
        meat
    LIMIT 10;"""

print sqldf(q, locals())

#                   date  beef  veal  pork  lamb_and_mutton broilers other_chicken turkey
# 0  1944-01-01 00:00:00   751    85  1280               89     None          None   None
# 1  1944-02-01 00:00:00   713    77  1169               72     None          None   None
# 2  1944-03-01 00:00:00   741    90  1128               75     None          None   None
# 3  1944-04-01 00:00:00   650    89   978               66     None          None   None
</code>

pandasql creates a DB, schema and all, loads your data, and runs your SQL.

Aggregation

pandasql supports aggregation. You can use aliased column names or column numbers in your group byclause.

<code># births per year
q = """
    SELECT
        strftime("%Y", date)
        , SUM(births)
    FROM births
    GROUP BY 1
    ORDER BY 1;
            """

print sqldf(q, locals())

#    strftime("%Y", date)  SUM(births)
# 0                  1975      3136965
# 1                  1976      6304156
# 2                  1979      3333279
# 3                  1982      3612258
</code>

locals() vs. globals()

pandasql needs to have access to other variables in your session/environment. You can pass locals() to pandasql when executing a SQL statement, but if you’re running a lot of queries that might be a pain. To avoid passing locals all the time, you can add this helper function to your script to set globals() like so:

<code>def pysqldf(q):
    return sqldf(q, globals())

q = """
    SELECT
        *
    FROM
        births
    LIMIT 10;"""

print pysqldf(q)
# 0  1975-01-01 00:00:00  265775
# 1  1975-02-01 00:00:00  241045
# 2  1975-03-01 00:00:00  268849
</code>

joins

You can join dataframes using normal SQL syntax.

<code># joining meats + births on date
q = """
    SELECT
        m.date
        , b.births
        , m.beef
    FROM
        meat m
    INNER JOIN
        births b
            on m.date = b.date
    ORDER BY
        m.date
    LIMIT 100;
    """

joined = pysqldf(q)
print joined.head()
#date  births    beef
#0  1975-01-01 00:00:00.000000  265775  2106.0
#1  1975-02-01 00:00:00.000000  241045  1845.0
#2  1975-03-01 00:00:00.000000  268849  1891.0
</code>

WHERE conditions

Here’s a WHERE clause.

<code>q = """
    SELECT
        date
        , beef
        , veal
        , pork
        , lamb_and_mutton
    FROM
        meat
    WHERE
        lamb_and_mutton &gt;= veal
    ORDER BY date DESC
    LIMIT 10;
    """

print pysqldf(q)
#                   date    beef  veal    pork  lamb_and_mutton
# 0  2012-11-01 00:00:00  2206.6  10.1  2078.7             12.4
# 1  2012-10-01 00:00:00  2343.7  10.3  2210.4             14.2
# 2  2012-09-01 00:00:00  2016.0   8.8  1911.0             12.5
# 3  2012-08-01 00:00:00  2367.5  10.1  1997.9             14.2
</code>

It’s just SQL

Since pandasql is powered by SQLite3, you can do most anything you can do in SQL. Here are some examples using common SQL features such as subqueries, order by, functions, and unions.

<code>#################################################
# SQL FUNCTIONS
# e.g. `RANDOM()`
#################################################
q = """SELECT
    *
    FROM
        meat
    ORDER BY RANDOM()
    LIMIT 10;"""
print pysqldf(q)
#                   date  beef  veal  pork  lamb_and_mutton  broilers other_chicken  turkey
# 0  1967-03-01 00:00:00  1693    65  1136               61     472.0          None    26.5
# 1  1944-12-01 00:00:00   764   146  1013               91       NaN          None     NaN
# 2  1969-06-01 00:00:00  1666    50   964               42     573.9          None    85.4
# 3  1983-03-01 00:00:00  1892    37  1303               36    1106.2          None   182.7

#################################################
# UNION ALL
#################################################
q = """
        SELECT
            date
            , 'beef' AS meat_type
            , beef AS value
        FROM meat
        UNION ALL
        SELECT
            date
            , 'veal' AS meat_type
            , veal AS value
        FROM meat

        UNION ALL

        SELECT
            date
            , 'pork' AS meat_type
            , pork AS value
        FROM meat
        UNION ALL
        SELECT
            date
            , 'lamb_and_mutton' AS meat_type
            , lamb_and_mutton AS value
        FROM meat
        ORDER BY 1
    """
print pysqldf(q).head(20)
#                    date        meat_type  value
# 0   1944-01-01 00:00:00             beef    751
# 1   1944-01-01 00:00:00             veal     85
# 2   1944-01-01 00:00:00             pork   1280
# 3   1944-01-01 00:00:00  lamb_and_mutton     89


#################################################
# subqueries
# fancy!
#################################################
q = """
    SELECT
        m1.date
        , m1.beef
    FROM
        meat m1
    WHERE m1.date IN
        (SELECT
            date
        FROM meat
        WHERE
            beef &gt;= broilers
        ORDER BY date)
"""

more_beef_than_broilers = pysqldf(q)
print more_beef_than_broilers.head(10)
#                   date  beef
# 0  1960-01-01 00:00:00  1196
# 1  1960-02-01 00:00:00  1089
# 2  1960-03-01 00:00:00  1201
# 3  1960-04-01 00:00:00  1066
</code>

Final thoughts

pandas is an incredible tool for data analysis in large part, we think, because it is extremely digestible, succinct, and expressive. Ultimately, there are tons of reasons to learn the nuances of mergejoinconcatenatemelt and other native pandas features for slicing and dicing data. Check out the docs for some examples.

Our hope is that pandasql will be a helpful learning tool for folks new to Python and pandas. In my own personal experience learning R, sqldf was a familiar interface helping me become highly productive with a new tool as quickly as possible.

关于python文件操作

Standard

python中对文件、文件夹(文件操作函数)的操作需要涉及到os模块和shutil模块。

得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd()

返回指定目录下的所有文件和目录名:os.listdir()

函数用来删除一个文件:os.remove()

删除多个目录:os.removedirs(r“c:\python”)

检验给出的路径是否是一个文件:os.path.isfile()

检验给出的路径是否是一个目录:os.path.isdir()

判断是否是绝对路径:os.path.isabs()

检验给出的路径是否真地存:os.path.exists()

返回一个路径的目录名和文件名:os.path.split()     eg os.path.split(‘/home/swaroop/byte/code/poem.txt’) 结果:(‘/home/swaroop/byte/code’, ‘poem.txt’)

分离扩展名:os.path.splitext()

获取路径名:os.path.dirname()

获取文件名:os.path.basename()

运行shell命令: os.system()

读取和设置环境变量:os.getenv() 与os.putenv()

给出当前平台使用的行终止符:os.linesep    Windows使用’\r\n’,Linux使用’\n’而Mac使用’\r’

指示你正在使用的平台:os.name       对于Windows,它是’nt’,而对于Linux/Unix用户,它是’posix’

重命名:os.rename(old, new)

创建多级目录:os.makedirs(r“c:\python\test”)

创建单个目录:os.mkdir(“test”)

获取文件属性:os.stat(file)

修改文件权限与时间戳:os.chmod(file)

终止当前进程:os.exit()

获取文件大小:os.path.getsize(filename)
文件操作:
os.mknod(“test.txt”)        创建空文件
fp = open(“test.txt”,w)     直接打开一个文件,如果文件不存在则创建文件

关于open 模式:

w     以写方式打开,
a     以追加模式打开 (从 EOF 开始, 必要时创建新文件)
r+     以读写模式打开
w+     以读写模式打开 (参见 w )
a+     以读写模式打开 (参见 a )
rb     以二进制读模式打开
wb     以二进制写模式打开 (参见 w )
ab     以二进制追加模式打开 (参见 a )
rb+    以二进制读写模式打开 (参见 r+ )
wb+    以二进制读写模式打开 (参见 w+ )
ab+    以二进制读写模式打开 (参见 a+ )

 

fp.read([size])                     #size为读取的长度,以byte为单位

fp.readline([size])                 #读一行,如果定义了size,有可能返回的只是一行的一部分

fp.readlines([size])                #把文件每一行作为一个list的一个成员,并返回这个list。其实它的内部是通过循环调用readline()来实现的。如果提供size参数,size是表示读取内容的总长,也就是说可能只读到文件的一部分。

fp.write(str)                      #把str写到文件中,write()并不会在str后加上一个换行符

fp.writelines(seq)            #把seq的内容全部写到文件中(多行一次性写入)。这个函数也只是忠实地写入,不会在每行后面加上任何东西。

fp.close()                        #关闭文件。python会在一个文件不用后自动关闭文件,不过这一功能没有保证,最好还是养成自己关闭的习惯。  如果一个文件在关闭后还对其进行操作会产生ValueError

fp.flush()                                      #把缓冲区的内容写入硬盘

fp.fileno()                                      #返回一个长整型的”文件标签“

fp.isatty()                                      #文件是否是一个终端设备文件(unix系统中的)

fp.tell()                                         #返回文件操作标记的当前位置,以文件的开头为原点

fp.next()                                       #返回下一行,并将文件操作标记位移到下一行。把一个file用于for … in file这样的语句时,就是调用next()函数来实现遍历的。

fp.seek(offset[,whence])              #将文件打操作标记移到offset的位置。这个offset一般是相对于文件的开头来计算的,一般为正数。但如果提供了whence参数就不一定了,whence可以为0表示从头开始计算,1表示以当前位置为原点计算。2表示以文件末尾为原点进行计算。需要注意,如果文件以a或a+的模式打开,每次进行写操作时,文件操作标记会自动返回到文件末尾。

fp.truncate([size])                       #把文件裁成规定的大小,默认的是裁到当前文件操作标记的位置。如果size比文件的大小还要大,依据系统的不同可能是不改变文件,也可能是用0把文件补到相应的大小,也可能是以一些随机的内容加上去。

 

目录操作:
os.mkdir(“file”)                   创建目录
复制文件:
shutil.copyfile(“oldfile”,”newfile”)       oldfile和newfile都只能是文件
shutil.copy(“oldfile”,”newfile”)            oldfile只能是文件夹,newfile可以是文件,也可以是目标目录
复制文件夹:
shutil.copytree(“olddir”,”newdir”)        olddir和newdir都只能是目录,且newdir必须不存在
重命名文件(目录)
os.rename(“oldname”,”newname”)       文件或目录都是使用这条命令
移动文件(目录)
shutil.move(“oldpos”,”newpos”)   
删除文件
os.remove(“file”)
删除目录
os.rmdir(“dir”)只能删除空目录
shutil.rmtree(“dir”)    空目录、有内容的目录都可以删
转换目录
os.chdir(“path”)   换路径

 

相关例子 

 1 将文件夹下所有图片名称加上’_fc’

python代码:

# -*- coding:utf-8 -*-
import re
import os
import time
#str.split(string)分割字符串
#’连接符’.join(list) 将列表组成字符串
def change_name(path):
global i
if not os.path.isdir(path) and not os.path.isfile(path):
return False
if os.path.isfile(path):
file_path = os.path.split(path) #分割出目录与文件
lists = file_path[1].split(‘.’) #分割出文件与文件扩展名
file_ext = lists[-1] #取出后缀名(列表切片操作)
img_ext = [‘bmp’,’jpeg’,’gif’,’psd’,’png’,’jpg’]
if file_ext in img_ext:
os.rename(path,file_path[0]+’/’+lists[0]+’_fc.’+file_ext)
i+=1 #注意这里的i是一个陷阱
#或者
#img_ext = ‘bmp|jpeg|gif|psd|png|jpg’
#if file_ext in img_ext:
#    print(‘ok—‘+file_ext)
elif os.path.isdir(path):
for x in os.listdir(path):
change_name(os.path.join(path,x)) #os.path.join()在路径处理上很有用
img_dir = ‘D:\\xx\\xx\\images’
img_dir = img_dir.replace(‘\\’,’/’)
start = time.time()
i = 0
change_name(img_dir)
c = time.time() – start
print(‘程序运行耗时:%0.2f’%(c))
print(‘总共处理了 %s 张图片’%(i))

输出结果:

程序运行耗时:0.11
总共处理了 109 张图片

对ASP.NET程序员都非常有用的85个工具

Standard

介绍

这篇文章列出了针对ASP.NET开发人员的有用工具。

工具

1.Visual Studio

  1. Visual Studio Productivity Power tool:Visual Studio专业版(及以上)的扩展,具有丰富的功能,如快速查找,导航解决方案,可搜索的附加参考对话框等
  2. ReSharper:提高.NET开发人员生产力的工具,提高代码质量,通过提供快速修复消除错误,等等
  3. MZ-Tools:它可以在方法、文件、项目、解决方案或项目组、选定的文本,文件组合或项目组合中找到字符串。结果示于下面的结果窗口中,比由Microsoft IDE提供的要更方便。
  4. Web Essentials:提高生产力和帮助高效编写CSS,JavaScript,HTML等
  5. MSVSMON:远程调试监视器(msvsmon.exe)是一个Visual Studio连接进行远程调试的小型应用程序。在远程调试时,Visual Studio运行在一台计算机(调试器主机)上,远程调试监视器运行与你正在调试的应用程序运行在一台远程计算机上。
  6. WIX toolset:从XML源代码构建Windows安装程序包。
  7. Code digger::Code Digger是Visual Studio 2012/2013扩展程序,它可以帮助你了解你的代码行为。
  8. CodeMaid:CodeMaid是一个开源的Visual Studio 2012/2013/2015扩展程序,用于清理,挖掘和简化你的代码。
  9. OzCode:强大的Visual Studio调试器可视化工具。
  10. CodeRush:这是一个Visual Studio的重构和生产率插件。
  11. T4 Text Template::在Visual Studio中,T4 Text Template用作生成代码文件的模板。模板可以通过编写文本块和控制逻辑来定义。
  12. Indent Guides:在每个缩进级别添加垂直线。
  13. PowerShell Tools:一套用于开发和调试PowerShell脚本以及Visual Studio 2015中模块的工具。
  14. Visual Studio Code:免费的跨平台编辑器,用来构建和调试现代web和云的应用程序。 [由Cheung Tat Ming提供]
  15. AutoPoco:AutoPoco是一个高度可配置的框架,用于流畅构建可读的来自于Plain Old CLRObjects的测试数据。
  16. Supercharger:这是一个旨在显著改善Visual Studio开发体验的扩展程序。它建立在并增强了先前的VS10x产品,如CodeMAP、Editor View Enhancer、Comments Extender,同时还增加了新的高品质工具。

2.ASP.NET

  1. Fiddler:捕捉HTTP请求/响应以及模拟请求行为。
  2. AutoMapper:对象到对象的映射。例如,该工具可用于映射实体对象到领域对象,而不是写手动映射代码。
  3. Unity/Ninject/Castle Windsor/StructureMap/Spring.Net:依赖注入框架。有很多可用的DI框架。
  4. .NET Reflector:.NET程序集反编译器。
  5. dotPeek:.NET程序集反编译器。
  6. ILSpy::.NET程序集反编译器。
  7. memprofiler:查找内存泄漏并优化内存使用的强大工具。
  8. PostSharp:删除重复编码,并防止由于横切关注点以及面向方面编程而造成的代码膨胀。
  9. ASPhere:有GUI的web.config编辑器。

3.REST API

  1. Swagger UI:API测试和文档工具。[视频]
  2. PostMan:REST客户端Chrom扩展程序。 [由 Cheung Tat Ming提供]

4.WCF

  1. SOAP UI:API测试工具,支持所有标准协议和技术。
  2. WireShark:这是一个针对Unix和Windows的网络协议分析仪。它可以在TCP层捕获流量,帮助你发现soap封套。
  3. Svc TraceViewer:可以更好地查看由WCF产出的巨大跟踪文件。
  4. Svc Config Editor:用于管理WCF相关配置的GUI工具。

5.MSMQ

  1. QueueExplorer 3.4:复制,移动或删除邮件,保存和加载,压力测试,查看和编辑完整的邮件主体(通过.NET序列化对象的特殊支持),以及更多可对MSMQ做的。

6.LINQ

  1. LINQ Pad?:LINQPad是一个轻量级的工具,用于测试对SQL Server数据库的LINQ查询。它也可以测试用不同的.NET语言,如C#,VB等写的代码片断。
  2. LINQ Insight:LINQ Insight Express是一个Visual Studio插件,它允许你在设计时分析你的LINQ查询,并简化了编写和调试LINQ查询。

7.RegEx

  1. RegEx tester:用于正则表达式测试的Visual Studio扩展程序。
  2. regexr:在线RegEx开发和测试工具。
  3. regexpal:在线RegEx开发和测试工具。
  4. Expresso:Expresso是一个用于RegEx开发和测试的桌面工具。
  5. RegexMagic :用于自动生成来自于文本模式的正则表达式的工具。用户需要通过标记字串和选择不同的选项来培养模式。在此基础上,将自动生成正则表达式。这些工具还可以生成不同语言所需的代码。 [由: Samuel Christison提供]

8.Javascript / JQuery/ AngularJS

  1. JSHint:JavaScript代码质量的工具。还有一个工具,JSLine,它执行更严格的规则。
  2. JSFiddle:提供在浏览器中的一个环境,用来测试HTML,CSS和Javascript / JQuery。
  3. Protractor:端到端的框架用来测试angular应用程序。
  4. Batarang:添加工具用于调试和分析AngularJS应用程序。

9.SQL服务器

  1. SQL Profiler:SQL跟踪用来监测数据库引擎实例。
  2. ExpressProfiler:ExpressProfiler(又名SqlExpress Profiler)是有着基本GUI和集成的SQL Server Profiler简单又快捷的替代品。这可以与Express 和SQL Server 2005/2008 / 2008R2 / 2012/2014的non-Express 版本一起使用。 [由RickZeeland提供]
  3. SQL Sentry Plan explorer:工具提供SQL查询执行计划更好的图形视图。
  4. SQL Complete:提供SQL Server Management Studio和Visual Studio智能感知功能和改进的SQL格式器。
  5. NimbleText:文本操作和代码生成工具。
  6. Query Express:轻量级SQL查询分析器。
  7. IO Meter:提供IO子系统的细节。
  8. sqldecryptor:破译SQL Server对象,如存储过程,函数,触发器,视图,通过加密选项加密。
  9. SpatialViewer:查看和创建空间数据。
  10. ClearTrace:导入跟踪和探查文件到SQL Server并显示汇总性能信息。
  11. Internals Viewer for SQL Server:Internals Viewer是一个查看SQL Server存储引擎,查阅数据如何物理分配,组织和存储的工具。
  12. PAL:在性能日志读取,使用已知阈值分析。
  13. sqlquerystress:用T-SQL查询和程序的性能压力测试助攻。

10.NHibernate

  1. NHibernate Mapping Generator:生成NHibernate映射文件和对应于现有DB表的实体类。

11.Tally

  1. Tally ERP 9
  2. Tally dll:.NET的一个动态链接库,用于集成Tally Accounting软件以便于用编程的方式push和pull数据。

12.代码审查

  1. StyleCop:StyleCop是静态的代码分析工具,它强制你的C#源代码执行配置风格和一致性规则设置。它可以从Visual Studio内部运行或集成到MSBuild项目。
  2. FxCop?:FxCop是一个静态代码分析工具,它通过分析.NET程序集强制开发标准。

13.流量捕获

  1. WireShark:这是一个用于Unix和Windows的网络协议分析仪。它可以捕获TCP层的流量。
  2. HTTP Monitor:使开发人员可以查看你的计算机和互联网之间的所有HTTP流量。这包括请求数据(例如HTTP响应头和表单GET和POST数据)和响应数据(包括HTTP响应头和正文)。

14.诊断

  1. Glimpse:提供服务器端诊断数据。如,对于ASP.NET MVC项目,你需要从NuGet添加它。Glimpse的数据可以告诉你不同层面的延迟,真正表明你可以优化代码/解决方案以提高性能的区域。

15.性能

  1. PerfMon:使用性能计数器监控系统性能。
  2. yslow:YSlow分析web页面,并基于Yahoo!高性能网站的规则指出它们为什么这么缓慢。

16.代码转换器

  1. Telerik Code Converter:C#到VB以及VB到C#的代码转换器。这是一个在线编辑器。但是你可以选择“批量转换”以及zip格式上传文件。

17.数据提取和加载

  1. FileHelpers:.NET库,导入/导出文件、字符串或流中固定长度或有分隔记录的数据。
  2. LogParser:你可以写SQL到查询来应对各种日志文件,以及导出数据到各种目的地,如SQL表、CSV文件。

18.屏幕录制

  1. Wink:演示文稿制作软件。使用Wink,你可以捕捉截图,添加说明,注释等,以及创建演示。

19.文本编辑器

  1. Notepad++:源代码编辑器。
  2. Notepad2:轻量级又功能丰富的记事本般的文本编辑器。
  3. sublimetext:一个功能丰富的文本编辑器。

20.文档

  1. GhostDoc:GhostDoc是一个Visual Studio扩展程序,自动生成类型、参数、名称及其他相关信息方法和属性的XML文档注释。
  2. helpndoc:helpndoc是一个创建帮助文件的工具。它可以从单个源生成不同格式的文件。

21.其他

  1. FileZilla:FileZilla是一个免费的FTP解决方案。FileZilla Client用于FTP文件上传,FileZilla Server用于文件共享。
  2. TreeTrim:TreeTrim是用于修整源代码树的工具。它消除了调试文件,源代码控制绑定和临时文件。
  3. BrowserStack:跨浏览器测试网站。
  4. Firebug:功能丰富的针对于CSS,HTML和JavaScript开发关于生成网页的Firefox插件。
  5. BugShooting:屏幕截图软件,截屏并放到工作项,bug,问题跟踪项等。
  6. Web developer checklist:确保web开发最佳实践。
  7. XRAY:Firefox插件。功能丰富的书签。提供有关网页元素的信息。
  8. PowerGUI:有助于快速接纳和使用PowerShell来高效管理完整的Windows环境。
  9. Beyond Compare:它允许比较目录树和单个文件的内容。适应强,有流行语言的插件。 [由Ron Matuszek提供]
  10. Devart Codecompare:文件diff工具,读取C#,C ++,VB代码的结构。包括:文件夹比较工具,比较和合并文件和文件夹的独立app,代码审查支持。 [由Cheung Tat Ming提供]

警告

使用之前请验证工具。

许可证

这篇文章以及任何相关的源代码和文件,遵循 The Code Project Open License (CPOL)。

 

译文链接:http://www.codeceo.com/article/85-aspnet-tools.html
英文原文:Useful Tools for ASP.NET Developers

知道这20个正则表达式,能让你少写1,000行代码

Standard

知道这20个正则表达式,能让你少写1,000行代码

正则表达式,一个十分古老而又强大的文本处理工具,仅仅用一段非常简短的表达式语句,便能够快速实现一个非常复杂的业务逻辑。熟练地掌握正则表达式的话,能够使你的开发效率得到极大的提升。

正则表达式经常被用于字段或任意字符串的校验,如下面这段校验基本日期格式的JavaScript代码:

<code class="scala"><span class="hljs-keyword">var</span> reg = /^(\\d{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>})(-|\\/)(\\d{<span class="hljs-number">1</span>,<span class="hljs-number">2</span>})\\<span class="hljs-number">2</span>(\\d{<span class="hljs-number">1</span>,<span class="hljs-number">2</span>})$/; 
<span class="hljs-keyword">var</span> r = fieldValue.<span class="hljs-keyword">match</span>(reg);             
<span class="hljs-keyword">if</span>(r==<span class="hljs-literal">null</span>)alert(<span class="hljs-symbol">'Date</span> format error!');</code>

下面是技匠整理的,在前端开发中经常使用到的20个正则表达式。


1 . 校验密码强度

密码的强度必须是包含大小写字母和数字的组合,不能使用特殊字符,长度在8-10之间。

<code class="cpp">^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{<span class="hljs-number">8</span>,<span class="hljs-number">10</span>}$</code>

2. 校验中文

字符串仅能是中文。

<code class="tex">^<span class="hljs-special">[</span><span class="hljs-command">\\</span>u4e00-<span class="hljs-command">\\</span>u9fa5<span class="hljs-special">]</span><span class="hljs-special">{</span>0,<span class="hljs-special">}</span><span class="hljs-formula">$</span></code>

3. 由数字、26个英文字母或下划线组成的字符串

<code class="tex">^<span class="hljs-command">\\</span>w+<span class="hljs-formula">$</span></code>

4. 校验E-Mail 地址

同密码一样,下面是E-mail地址合规性的正则检查语句。

<code class="markdown">[<span class="hljs-link_label">\\w!#$%&amp;'*+/=?^_`{|}~-</span>]+(?:\\.[<span class="hljs-link_label">\\w!#$%&amp;'*+/=?^_`{|}~-</span>]+)<span class="hljs-emphasis">*@(?:[\\w](?:[\\w-]*</span>[<span class="hljs-link_label">\\w</span>])?\\.)+[<span class="hljs-link_label">\\w</span>](<span class="hljs-link_url">?:[\\w-]*[\\w]</span>)?</code>

5. 校验身份证号码

下面是身份证号码的正则校验。15 或 18位。

15位:

<code class="cpp">^[<span class="hljs-number">1</span>-<span class="hljs-number">9</span>]\\d{<span class="hljs-number">7</span>}((<span class="hljs-number">0</span>\\d)|(<span class="hljs-number">1</span>[<span class="hljs-number">0</span>-<span class="hljs-number">2</span>]))(([<span class="hljs-number">0</span>|<span class="hljs-number">1</span>|<span class="hljs-number">2</span>]\\d)|<span class="hljs-number">3</span>[<span class="hljs-number">0</span>-<span class="hljs-number">1</span>])\\d{<span class="hljs-number">3</span>}$</code>

18位:

<code class="cpp">^[<span class="hljs-number">1</span>-<span class="hljs-number">9</span>]\\d{<span class="hljs-number">5</span>}[<span class="hljs-number">1</span>-<span class="hljs-number">9</span>]\\d{<span class="hljs-number">3</span>}((<span class="hljs-number">0</span>\\d)|(<span class="hljs-number">1</span>[<span class="hljs-number">0</span>-<span class="hljs-number">2</span>]))(([<span class="hljs-number">0</span>|<span class="hljs-number">1</span>|<span class="hljs-number">2</span>]\\d)|<span class="hljs-number">3</span>[<span class="hljs-number">0</span>-<span class="hljs-number">1</span>])\\d{<span class="hljs-number">3</span>}([<span class="hljs-number">0</span>-<span class="hljs-number">9</span>]|X)$</code>

6. 校验日期

“yyyy-mm-dd“ 格式的日期校验,已考虑平闰年。

<code class="markdown">^(?:(?!0000)[<span class="hljs-link_label">0-9</span>]{4}-(?:(?:0[<span class="hljs-link_label">1-9</span>]|1[<span class="hljs-link_label">0-2</span>])-(?:0[<span class="hljs-link_label">1-9</span>]|1[<span class="hljs-link_label">0-9</span>]|2[<span class="hljs-link_label">0-8</span>])|(?:0[<span class="hljs-link_label">13-9</span>]|1[<span class="hljs-link_label">0-2</span>])-(?:29|30)|(?:0[<span class="hljs-link_label">13578</span>]|1[<span class="hljs-link_label">02</span>])-31)|(?:[<span class="hljs-link_label">0-9</span>]{2}(?:0[<span class="hljs-link_label">48</span>]|[<span class="hljs-link_label">2468</span>][<span class="hljs-link_reference">048</span>]|[<span class="hljs-link_label">13579</span>][<span class="hljs-link_reference">26</span>])|(?:0[<span class="hljs-link_label">48</span>]|[<span class="hljs-link_label">2468</span>][<span class="hljs-link_reference">048</span>]|[<span class="hljs-link_label">13579</span>][<span class="hljs-link_reference">26</span>])00)-02-29)$</code>

7. 校验金额

金额校验,精确到2位小数。

<code class="cpp">^[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>]+(.[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>]{<span class="hljs-number">2</span>})?$</code>

8. 校验手机号

下面是国内 13、15、18开头的手机号正则表达式。(可根据目前国内收集号扩展前两位开头号码)

<code class="cpp">^(<span class="hljs-number">13</span>[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>]|<span class="hljs-number">14</span>[<span class="hljs-number">5</span>|<span class="hljs-number">7</span>]|<span class="hljs-number">15</span>[<span class="hljs-number">0</span>|<span class="hljs-number">1</span>|<span class="hljs-number">2</span>|<span class="hljs-number">3</span>|<span class="hljs-number">5</span>|<span class="hljs-number">6</span>|<span class="hljs-number">7</span>|<span class="hljs-number">8</span>|<span class="hljs-number">9</span>]|<span class="hljs-number">18</span>[<span class="hljs-number">0</span>|<span class="hljs-number">1</span>|<span class="hljs-number">2</span>|<span class="hljs-number">3</span>|<span class="hljs-number">5</span>|<span class="hljs-number">6</span>|<span class="hljs-number">7</span>|<span class="hljs-number">8</span>|<span class="hljs-number">9</span>])\\d{<span class="hljs-number">8</span>}$</code>

9. 判断IE的版本

IE目前还没被完全取代,很多页面还是需要做版本兼容,下面是IE版本检查的表达式。

<code class="cpp">^.*MSIE [<span class="hljs-number">5</span>-<span class="hljs-number">8</span>](?:\\.[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>]+)?(?!.*Trident\\/[<span class="hljs-number">5</span>-<span class="hljs-number">9</span>]\\<span class="hljs-number">.0</span>).*$</code>

10. 校验IP-v4地址

IP4 正则语句。

<code class="markdown">\\b(?:(?:25[<span class="hljs-link_label">0-5</span>]|2[<span class="hljs-link_label">0-4</span>][<span class="hljs-link_reference">0-9</span>]|[<span class="hljs-link_label">01</span>]?[<span class="hljs-link_label">0-9</span>][<span class="hljs-link_reference">0-9</span>]?)\\.){3}(?:25[<span class="hljs-link_label">0-5</span>]|2[<span class="hljs-link_label">0-4</span>][<span class="hljs-link_reference">0-9</span>]|[<span class="hljs-link_label">01</span>]?[<span class="hljs-link_label">0-9</span>][<span class="hljs-link_reference">0-9</span>]?)\\b</code>

11. 校验IP-v6地址

IP6 正则语句。

<code class="cpp">(([<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-fA-F]{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}:){<span class="hljs-number">7</span>,<span class="hljs-number">7</span>}[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-fA-F]{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}|([<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-fA-F]{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}:){<span class="hljs-number">1</span>,<span class="hljs-number">7</span>}:|([<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-fA-F]{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}:){<span class="hljs-number">1</span>,<span class="hljs-number">6</span>}:[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-fA-F]{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}|([<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-fA-F]{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}:){<span class="hljs-number">1</span>,<span class="hljs-number">5</span>}(:[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-fA-F]{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}){<span class="hljs-number">1</span>,<span class="hljs-number">2</span>}|([<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-fA-F]{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}:){<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}(:[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-fA-F]{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}){<span class="hljs-number">1</span>,<span class="hljs-number">3</span>}|([<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-fA-F]{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}:){<span class="hljs-number">1</span>,<span class="hljs-number">3</span>}(:[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-fA-F]{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}){<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}|([<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-fA-F]{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}:){<span class="hljs-number">1</span>,<span class="hljs-number">2</span>}(:[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-fA-F]{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}){<span class="hljs-number">1</span>,<span class="hljs-number">5</span>}|[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-fA-F]{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}:((:[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-fA-F]{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}){<span class="hljs-number">1</span>,<span class="hljs-number">6</span>})|:((:[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-fA-F]{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}){<span class="hljs-number">1</span>,<span class="hljs-number">7</span>}|:)|fe80:(:[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-fA-F]{<span class="hljs-number">0</span>,<span class="hljs-number">4</span>}){<span class="hljs-number">0</span>,<span class="hljs-number">4</span>}%[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-zA-Z]{<span class="hljs-number">1</span>,}|::(ffff(:<span class="hljs-number">0</span>{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}){<span class="hljs-number">0</span>,<span class="hljs-number">1</span>}:){<span class="hljs-number">0</span>,<span class="hljs-number">1</span>}((<span class="hljs-number">25</span>[<span class="hljs-number">0</span>-<span class="hljs-number">5</span>]|(<span class="hljs-number">2</span>[<span class="hljs-number">0</span>-<span class="hljs-number">4</span>]|<span class="hljs-number">1</span>{<span class="hljs-number">0</span>,<span class="hljs-number">1</span>}[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>]){<span class="hljs-number">0</span>,<span class="hljs-number">1</span>}[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>])\\.){<span class="hljs-number">3</span>,<span class="hljs-number">3</span>}(<span class="hljs-number">25</span>[<span class="hljs-number">0</span>-<span class="hljs-number">5</span>]|(<span class="hljs-number">2</span>[<span class="hljs-number">0</span>-<span class="hljs-number">4</span>]|<span class="hljs-number">1</span>{<span class="hljs-number">0</span>,<span class="hljs-number">1</span>}[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>]){<span class="hljs-number">0</span>,<span class="hljs-number">1</span>}[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>])|([<span class="hljs-number">0</span>-<span class="hljs-number">9</span>a-fA-F]{<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}:){<span class="hljs-number">1</span>,<span class="hljs-number">4</span>}:((<span class="hljs-number">25</span>[<span class="hljs-number">0</span>-<span class="hljs-number">5</span>]|(<span class="hljs-number">2</span>[<span class="hljs-number">0</span>-<span class="hljs-number">4</span>]|<span class="hljs-number">1</span>{<span class="hljs-number">0</span>,<span class="hljs-number">1</span>}[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>]){<span class="hljs-number">0</span>,<span class="hljs-number">1</span>}[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>])\\.){<span class="hljs-number">3</span>,<span class="hljs-number">3</span>}(<span class="hljs-number">25</span>[<span class="hljs-number">0</span>-<span class="hljs-number">5</span>]|(<span class="hljs-number">2</span>[<span class="hljs-number">0</span>-<span class="hljs-number">4</span>]|<span class="hljs-number">1</span>{<span class="hljs-number">0</span>,<span class="hljs-number">1</span>}[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>]){<span class="hljs-number">0</span>,<span class="hljs-number">1</span>}[<span class="hljs-number">0</span>-<span class="hljs-number">9</span>]))</code>

12. 检查URL的前缀

应用开发中很多时候需要区分请求是HTTPS还是HTTP,通过下面的表达式可以取出一个url的前缀然后再逻辑判断。

<code class="scala"><span class="hljs-keyword">if</span> (!s.<span class="hljs-keyword">match</span>(/^[a-zA-<span class="hljs-type">Z</span>]+:\\/\\<span class="hljs-comment">//))</span>
{
    s = <span class="hljs-symbol">'http</span>:<span class="hljs-comment">//' + s;</span>
}</code>

13. 提取URL链接

下面的这个表达式可以筛选出一段文本中的URL。

<code class="tex">^(f|ht)<span class="hljs-special">{</span>1<span class="hljs-special">}</span>(tp|tps):<span class="hljs-command">\\</span>/<span class="hljs-command">\\</span>/(<span class="hljs-special">[</span><span class="hljs-command">\\</span>w-<span class="hljs-special">]</span>+<span class="hljs-command">\\</span>.)+<span class="hljs-special">[</span><span class="hljs-command">\\</span>w-<span class="hljs-special">]</span>+(<span class="hljs-command">\\</span>/<span class="hljs-special">[</span><span class="hljs-command">\\</span>w- ./?<span class="hljs-comment">%&amp;=]*)?</span></code>

14. 文件路径及扩展名校验

验证windows下文件路径和扩展名(下面的例子中为.txt文件)

<code class="tex">^(<span class="hljs-special">[</span>a-zA-Z<span class="hljs-special">]</span><span class="hljs-command">\\</span>:|<span class="hljs-command">\\</span><span class="hljs-command">\\</span>)<span class="hljs-command">\\</span><span class="hljs-command">\\</span>(<span class="hljs-special">[</span>^<span class="hljs-command">\\</span><span class="hljs-command">\\</span><span class="hljs-special">]</span>+<span class="hljs-command">\\</span><span class="hljs-command">\\</span>)*<span class="hljs-special">[</span>^<span class="hljs-command">\\</span>/:*?"&lt;&gt;|<span class="hljs-special">]</span>+<span class="hljs-command">\\</span>.txt(l)?<span class="hljs-formula">$</span></code>

15. 提取Color Hex Codes

有时需要抽取网页中的颜色代码,可以使用下面的表达式。

<code class="cpp">^<span class="hljs-preprocessor">#([A-Fa-f0-<span class="hljs-number">9</span>]{<span class="hljs-number">6</span>}|[A-Fa-f0-<span class="hljs-number">9</span>]{<span class="hljs-number">3</span>})$</span></code>

16. 提取网页图片

假若你想提取网页中所有图片信息,可以利用下面的表达式。

<code class="tex"><span class="hljs-command">\\</span>&lt; *<span class="hljs-special">[</span>img<span class="hljs-special">]</span><span class="hljs-special">[</span>^<span class="hljs-command">\\</span><span class="hljs-command">\\</span>&gt;<span class="hljs-special">]</span>*<span class="hljs-special">[</span>src<span class="hljs-special">]</span> *= *<span class="hljs-special">[</span><span class="hljs-command">\\</span>"<span class="hljs-command">\\</span>'<span class="hljs-special">]</span><span class="hljs-special">{</span>0,1<span class="hljs-special">}</span>(<span class="hljs-special">[</span>^<span class="hljs-command">\\</span>"<span class="hljs-command">\\</span>'<span class="hljs-command">\\</span> &gt;<span class="hljs-special">]</span>*)</code>

17. 提取页面超链接

提取html中的超链接。

<code class="tex">(&lt;a<span class="hljs-command">\\</span>s*(?!.*<span class="hljs-command">\\</span>brel=)<span class="hljs-special">[</span>^&gt;<span class="hljs-special">]</span>*)(href="https?:<span class="hljs-command">\\</span>/<span class="hljs-command">\\</span>/)((?!(?:(?:www<span class="hljs-command">\\</span>.)?'.implode('|(?:www<span class="hljs-command">\\</span>.)?', <span class="hljs-formula">$follow_list).'))<span class="hljs-special">[</span>^"<span class="hljs-special">]</span>+)"((?!.*<span class="hljs-command">\\</span>brel=)<span class="hljs-special">[</span>^&gt;<span class="hljs-special">]</span>*)(?:<span class="hljs-special">[</span>^&gt;<span class="hljs-special">]</span>*)&gt;</span></code>

18. 查找CSS属性

通过下面的表达式,可以搜索到相匹配的CSS属性。

<code class="tex">^<span class="hljs-command">\\</span>s*<span class="hljs-special">[</span>a-zA-Z<span class="hljs-command">\\</span>-<span class="hljs-special">]</span>+<span class="hljs-command">\\</span>s*<span class="hljs-special">[</span>:<span class="hljs-special">]</span><span class="hljs-special">{</span>1<span class="hljs-special">}</span><span class="hljs-command">\\</span>s<span class="hljs-special">[</span>a-zA-Z0-9<span class="hljs-command">\\</span>s.<span class="hljs-special">#</span><span class="hljs-special">]</span>+<span class="hljs-special">[</span>;<span class="hljs-special">]</span><span class="hljs-special">{</span>1<span class="hljs-special">}</span></code>

19. 抽取注释

如果你需要移除HMTL中的注释,可以使用如下的表达式。

<code class="xml"><span class="hljs-comment">&lt;!--(.*?)--&gt;</span></code>

20. 匹配HTML标签

通过下面的表达式可以匹配出HTML中的标签属性。

<code class="tex">&lt;<span class="hljs-command">\\</span>/?<span class="hljs-command">\\</span>w+((<span class="hljs-command">\\</span>s+<span class="hljs-command">\\</span>w+(<span class="hljs-command">\\</span>s*=<span class="hljs-command">\\</span>s*(?:".*?"|'.*?'|<span class="hljs-special">[</span><span class="hljs-command">\\</span>^'"&gt;<span class="hljs-command">\\</span>s<span class="hljs-special">]</span>+))?)+<span class="hljs-command">\\</span>s*|<span class="hljs-command">\\</span>s*)<span class="hljs-command">\\</span>/?&gt;</code>

正则表达式的相关语法

下面是我找到的一张非常不错的正则表达式 Cheat Sheet,可以用来快速查找相关语法。


学习正则表达式

我在网上看到了一篇相当不错的正则表达式快速学习指南,有兴趣继续深入学习的同学可以参考。


正则表达式在线测试工具

regex101是一个非常不错的正则表达式在线测试工具,你可以直接在线测试你的正则表达式哦。


转:http://www.jianshu.com/p/e7bb97218946

Connecting to MS SQL Server from Ubuntu

Standard

And now, in a break from the previous trend of fluffy posts, we have a tutorial on how to (deep breath): connect PHP to a MSSQL Server 2008 instance over ODBC from Ubuntu Linux using the FreeTDS driver and unixODBC. Theoretically it would also work for SQL Server 2005.

I don’t know whether half of the settings flags are necessary or even correct, but what follows Worked for Me™, YMMV, etc, etc.

In the commands below, I’ll use 192.168.0.1 as the server housing the SQL Server instance, with a SQL Server user name of devuser, password devpass. I’m assuming SQL Server is set up to listen on its default port, 1433. Keep an eye out, because you’ll need to change these things to your own settings.

First, install unixODBC:

sudo apt-get install unixodbc unixodbc-dev

I also installed the following (perhaps necessary) packages:
sudo apt-get install tdsodbc php5-odbc
Then download, untar, compile, and install FreeTDS (warning, the URL may change):
cd /usr/local
wget http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
tar xvfz freetds-stable.tgz
cd freetds-0.82
./configure --enable-msdblib --with-tdsver=8.0 --with-unixodbc=/usr
make
make install
make clean

Attempt a connection over Telnet to your SQL Server instance:
telnet 192.168.0.1 1433

Use the tsql tool to test out the connection:
tsql -S 192.168.0.1 -U devuser

This should prompt you for the password, after which you can hope against hope to see this beautiful sign:
1>

If that worked, I recommend throwing a (coding) party. Next up is some configging. Open the FreeTDS config file.
/usr/local/etc/freetds.conf

Add the following entry to the bottom of the file. We’re setting up a datasource name (DSN) called ‘MSSQL’.
[MSSQL]
host = 192.168.0.1
port = 1433
tds version = 8.0

Now open the ODBC configuration file:
/usr/local/etc/odbcinst.ini

And add the following MSSQL driver entry (FreeTDS) at the end:
[FreeTDS]
Description = FreeTDS driver
Driver = /usr/local/lib/libtdsodbc.so
Setup=/usr/lib/odbc/libtdsS.so
FileUsage = 1
UsageCount = 1 

Then, finally, set up the DSN within ODBC in the odbc.ini file here
/usr/local/etc/odbc.ini
By adding this bit to the file:
[MSSQL]
Description = MS SQL Server
Driver = /usr/local/lib/libtdsodbc.so
Server = 192.168.2.3
UID = devuser
PWD = devpass
ReadOnly = No
Port = 1433

Test out the connection using the isql tool:
isql -v MSSQL devuser 'devpass'
If you see “Connected!” you’re golden, congratulations! If not, I’m truly sorry; see below where there are some resources that might help.

Now restart Apache and test it from PHP using ‘MSSQL’ as the DSN. If something doesn’t work, you might try installing any or all of these packages:
mdbtools libmdbodbc libmdbtools mdbtools-gmdb

Here are some other resources that were helpful to me through this disastrous journey.

Eight Terminal Utilities Every OS X Command Line User Should Know

Standard

http://www.mitchchn.me/2014/os-x-terminal/?x

The OS X Terminal opens up a world of powerful UNIX utilities and scripts. If you’re migrating from Linux, you’ll find many familiar commands work the way you expect. But power users often aren’t aware that OS X comes with a number of its own text-based utilities not found on any other operating system. Learning about these Mac-only programs can make you more productive on the command line and help you bridge the gap between UNIX and your Mac.

Update: Thanks to reader feedback, I’ve written about a few more commands in a follow-up post: (And eight hundred more).

1. open

open opens files, directories and applications. Exciting, right? But it really does come in handy as a command-line double-click. For instance, typing:

<code class=" hljs ruby"><span class="hljs-variable">$ </span>open /<span class="hljs-constant">Applications</span>/<span class="hljs-constant">Safari</span>.app/
</code>

…will launch Safari as if you had double-clicked its icon in the Finder.

If you point open at a file instead, it will try to load the file with its associated GUI application. open screenshot.png on an image will open that image in Preview. You can set the -a flag to choose the app yourself, or -e to open the file for editing in TextEdit.

Running open on a directory will take you straight to that directory in a Finder window. This is especially useful for bringing up the current directory by typing open .

Remember that the integration between Finder and Terminal goes both ways – if you drag a file from Finder into a Terminal window, its full path gets pasted into the command line.

2. pbcopy and pbpaste

These two commands let you copy and paste text from the command line. Of course, you could also just use your mouse—but the real power of pbcopy and pbpaste comes from the fact that they’re UNIX commands, and that means they benefit from piping, redirection, and the ability to be in scripts in conjunction with other commands. Typing:

<code class=" hljs ruby"><span class="hljs-variable">$ </span>ls ~ | pbcopy
</code>

…will copy a list of files in your home directory to the OS X clipboard. You can easily capture the contents of a file:

<code class=" hljs ruby"><span class="hljs-variable">$ </span>pbcopy &lt; blogpost.txt
</code>

..or do something crazier. This hacked-up script will grab the link of the latest Google doodle and copy it to your clipboard.

<code class=" hljs coffeescript">$ curl <span class="hljs-attribute">http</span>:<span class="hljs-regexp">//</span>www.google.com<span class="hljs-regexp">/doodles#oodles/archive | grep -A5 'latest-doodle on' | grep 'img src' | sed s/</span>.*<span class="hljs-string">'&lt;img src="\/\/'</span><span class="hljs-regexp">/''/</span> | sed s<span class="hljs-regexp">/'" alt=".*'/</span><span class="hljs-string">''</span>/ | pbcopy
</code>

Using pbcopy with pipes is a great way to capture the output of a command without having to scroll up and carefully select it. This makes it easy to share diagnostic information. pbcopy and pbpaste can also be used to automate or speed up certain kinds of tasks. For instance, if you want to save email subject lines to a task list, you could copy the subjects from Mail.app and run:

<code class=" hljs ruby"><span class="hljs-variable">$ </span>pbpaste &gt;&gt; tasklist.txt
</code>

3. mdfind

Many a Linux power user has tried to use locate to search for files on a Mac and then quickly discovered that it didn’t work. There’s always the venerable UNIX find command, but OS X comes with its own killer search tool: Spotlight. So why not tap into its power from the command line?

That’s exactly what mdfind does. Anything Spotlight can find, mdfind can find too. That includes the ability to search inside files and metadata.

mdfind comes with a few conveniences that make it stand out from its big blue brother. For instance, the -onlyin flag can restrict the search to a single directory:

<code class=" hljs ">$ mdfind -onlyin ~/Documents essay
</code>

The mdfind database should stay up to date in the background, but you can also troubleshoot it (as well as Spotlight) using mdutil. If Spotlight isn’t working the way it should, mdutil -E will erase the index and rebuild it from scratch. You can also turn off indexing entirely with mdutil -i off.

4. screencapture

screencapture lets you take many different kinds of screenshots. It’s similar to Grab.app and the keyboard shortcuts cmd + shift + 3 and cmd + shift + 4, except it’s far more flexible. Here are just a few different ways you can use screencapture:

Capture the contents of the screen, including the cursor, and attach the resulting image (named ‘image.png’) to a new Mail message:

<code class=" hljs ruby"><span class="hljs-variable">$ </span>screencapture -<span class="hljs-constant">C</span> -<span class="hljs-constant">M</span> image.png
</code>

Select a window using your mouse, then capture its contents without the window’s drop shadow and copy the image to the clipboard:

<code class=" hljs ruby"><span class="hljs-variable">$ </span>screencapture -c -<span class="hljs-constant">W</span>
</code>

Capture the screen after a delay of 10 seconds and then open the new image in Preview:

<code class=" hljs ruby"><span class="hljs-variable">$ </span>screencapture -<span class="hljs-constant">T</span> <span class="hljs-number">10</span> -<span class="hljs-constant">P</span> image.png
</code>

Select a portion of the screen with your mouse, capture its contents, and save the image as a pdf:

<code class=" hljs bash">$ screencapture <span class="hljs-operator">-s</span> -t pdf image.pdf
</code>

To see more options, type screencapture --help

5. launchctl

launchctl lets you interact with the OS X init script system, launchd. With launch daemons and launch agents, you can control the services that start up when you boot your computer. You can even set up scripts to run periodically or at timed intervals in the background, similar to cron jobs on Linux.

For example, if you’d like to have the Apache web server start automatically when you turn on your Mac, simply type:

<code class=" hljs bash">$ <span class="hljs-built_in">sudo</span> launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
</code>

Running launchctl list will show you what launch scripts are currently loaded. sudo launchctl unload [path/to/script] will stop and unload running scripts, and adding the -w flag will remove those scripts permanently from your boot sequence. I like to run this one on all the auto-update “helpers” created by Adobe apps and Microsoft Office.

Launchd scripts are stored in the folllowing locations:

<code class=" hljs ruby">~<span class="hljs-regexp">/Library/</span><span class="hljs-constant">LaunchAgents</span>    
/<span class="hljs-constant">Library</span>/<span class="hljs-constant">LaunchAgents</span>          
/<span class="hljs-constant">Library</span>/<span class="hljs-constant">LaunchDaemons</span>
/<span class="hljs-constant">System</span>/<span class="hljs-constant">Library</span>/<span class="hljs-constant">LaunchAgents</span>
/<span class="hljs-constant">System</span>/<span class="hljs-constant">Library</span>/<span class="hljs-constant">LaunchDaemons</span>
</code>

To see what goes into a launch agent or daemon, there’s a great blog post by Paul Annesley that walks you through the file format. And if you’d like to learn how to write your own launchd scripts, Apple provides some helpful documentation on their Developer site. There’s also the fantastic Lingon app if you’d prefer to avoid the command line entirely.

6. say

This is a fun one: say converts text to speech, using the same TTS engine OS X uses for VoiceOver. Without any options, say will simply speak whatever text you give it out loud.:

<code class=" hljs ruby"><span class="hljs-variable">$ </span>say <span class="hljs-string">"Never trust a computer you can't lift."</span>
</code>

You can also use say to speak the contents of a text file with the -f flag, and you can store the resulting audio clip with the -o flag:

<code class=" hljs bash">$ say <span class="hljs-operator">-f</span> mynovel.txt -o myaudiobook.aiff
</code>

The say command can be useful in place of console logging or alert sounds in scripts. For instance, you can set up an Automator or Hazel script to do batch file processing and then announce the task’s completion with say.

But the most enjoyable use for say is rather more sinister: if you have ssh access to a friend or coworker’s Mac, you can silently log into their machine and haunt them through the command line. Give ‘em a Siri-ous surprise.

You can set the voice (and language!) used by say by changing the default setting in the Dictation & Speech panel in System Preferences.

7. diskutil

diskutil is a command line interface to the Disk Utility app that comes with OS X. It can do everything its graphical cousin can, but it also has some extra capabilities—such as filling a disk with zeroes or random data. Simply type diskutil list to see the path names of disks and removable media attached to your machine, and then point the command at the volume you want to operate on. Be careful: diskutil can permanently destroy data if it’s used incorrectly.

8. brew

Alright–this isn’t technically a native command. But no OS X power user should be without Homebrew. The website calls it “The missing package manager for OS X,” and that couldn’t be truer. If you’ve ever used apt-get in Linux, you will feel right at home in Homebrew.

brew gives you easy access to thousands of free utilities and libraries from the open source community. For instance, brew install imagemagick will set you up with ImageMagick, a powerful utility that makes it possible to do anything from whipping up animated gifs to converting images between dozens of different types. brew install node will introduce you to NodeJS, the hot new tool for developing and running server-side JavaScript apps.

You can have fun with Homebrew too: brew install archey will get you Archey, a cool little script for displaying your Mac’s specs next to a colourful Apple logo. The selection in Homebrew is huge—and because it’s so easy to create formulas, new packages are being added all the time.


ARCHEY—My command line brings all the boys to the yard.

But the best part about Homebrew? It keeps all its files in a single directory: /usr/local/. That means you can install newer versions of system software, such as python and mysql, without interfering with the built-in equivalents. And if you ever want to get rid of your Homebrew installation, it’s easy to remove.

Edit—May 15: Someone suggested to me that that you should not blindly delete the contents of /usr/local/. That’s a fair precaution. To remove Homebrew safely, use the uninstall script.

For more fun with Terminal.app, here is an A-Z list of all available console commands in OS X 10.9 Mavericks.

80 Linux Monitoring Tools for SysAdmins

Standard

By Jonathan Sundqvist, Engineer at Server Density.
Published on the 4th February, 2015.

 

The industry is hotting up at the moment, and there are more tools than you can shake a stick at. Here lies the most comprehensive list on the Internet (of monitoring tools). Featuring over 80 ways to monitor your machines. Within this article we outline:

  • Command line tools
  • Network related
  • System related monitoring
  • Log monitoring tools
  • Infrastructure monitoring tools

It’s hard work monitoring and debugging performance problems, but it’s easier with the right tools at the right time. But how much of your valuable time do you think it would take you to investigate all of these tools and find out which one is best for you?

Why not check out Server Density first, it has a beautiful UI, an api that’s easy to use and alerts that will keep downtime to a minimum.

server-monitoring-tool

Top 10  System Monitoring Tools

1. Top

Top
This is a small tool which is pre-installed in many unix systems. When you want an overview of all the processes or threads running in the system: top is a good tool. You can order these processes on different criteria and the default criteria is CPU.

2. htop

Top
Htop is essentially an enhanced version of top. It’s easier to sort by processes. It’s visually easier to understand and has built in commands for common things you would like to do. Plus it’s fully interactive.

3. atop

Atop monitors all processes much like top and htop, unlike top and htop however it has daily logging of the processes for long-term analysis. It also shows resource consumption by all processes. It will also highlight resources that have reached a critical load.

4. apachetop

Apachetop monitors the overall performance of your apache webserver. It’s largely based on mytop. It displays current number of reads, writes and the overall number of requests processed.

5. ftptop

ftptop gives you basic information of all the current ftp connections to your server such as the total amount of sessions, how many are uploading and downloading and who the client is.

6. mytop

Top
mytop is a neat tool for monitoring threads and performance of mysql. It gives you a live look into the database and what queries it’s processing in real time.

7. powertop

Top
powertop helps you diagnose issues that has to do with power consumption and power management. It can also help you experiment with power management settings to achieve the most efficient settings for your server. You switch tabs with the tab key.

8. iotop

Top
iotop checks the I/O usage information and gives you a top-like interface to that. It displays columns on read and write and each row represents a process. It also displays the percentage of time the process spent while swapping in and while waiting on I/O.

Network related monitoring

9. ntopng

Top
ntopng is the next generation of ntop and the tool provides a graphical user interface via the browser for network monitoring. It can do stuff such as: geolocate hosts, get network traffic and show ip traffic distribution and analyze it.

10. iftop

Top
iftop is similar to top, but instead of mainly checking for cpu usage it listens to network traffic on selected network interfaces and displays a table of current usage. It can be handy for answering questions such as “Why on earth is my internet connection so slow?!”.

11. jnettop

Top
jnettop visualises network traffic in much the same way as iftop does. It also supports customizable text output and a machine-friendly mode to support further analysis.

12. bandwidthd

Top
BandwidthD tracks usage of TCP/IP network subnets and visualises that in the browser by building a html page with graphs in png. There is a database driven system that supports searching, filtering, multiple sensors and custom reports.

13. EtherApe

EtherApe displays network traffic graphically, the more talkative the bigger the node. It either captures live traffic or can read it from a tcpdump. The displayed can also be refined using a network filter with pcap syntax.

14. ethtool

Top
ethtool is used for displaying and modifying some parameters of the network interface controllers. It can also be used to diagnose Ethernet devices and get more statistics from the devices.

15. NetHogs

Top
NetHogs breaks down network traffic per protocol or per subnet. It then groups by process. So if there’s a surge in network traffic you can fire up NetHogs and see which process is causing it.

16. iptraf

Top
iptraf gathers a variety of metrics such as TCP connection packet and byte count, interface statistics and activity indicators, TCP/UDP traffic breakdowns and station packet and byte counts.

17. ngrep

Top
ngrep is grep but for the network layer. It’s pcap aware and will allow to specify extended regular or hexadecimal expressions to match against packets of .

18. MRTG

Top
MRTG was orginally developed to monitor router traffic, but now it’s able to monitor other network related things as well. It typically collects every five minutes and then generates a html page. It also has the capability of sending warning emails.

19. bmon

Top
Bmon monitors and helps you debug networks. It captures network related statistics and presents it in human friendly way. You can also interact with bmon through curses or through scripting.

20. traceroute

Top
Traceroute is a built-in tool for displaying the route and measuring the delay of packets across a network.

21. IPTState

IPTState allows you to watch where traffic that crosses your iptables is going and then sort that by different criteria as you please. The tool also allows you to delete states from the table.

22. darkstat

Top
Darkstat captures network traffic and calculates statistics about usage. The reports are served over a simple HTTP server and gives you a nice graphical user interface of the graphs.

23. vnStat

Top
vnStat is a network traffic monitor that uses statistics provided by the kernel which ensures light use of system resources. The gathered statistics persists through system reboots. It has color options for the artistic sysadmins.

24. netstat

Top
Netstat is a built-in tool that displays TCP network connections, routing tables and a number of network interfaces. It’s used to find problems in the network.

25. ss

Instead of using netstat, it’s however preferable to use ss. The ss command is capable of showing more information than netstat and is actually faster. If you want a summary statistics you can use the command ss -s.

26. nmap

Top
Nmap allows you to scan your server for open ports or detect which OS is being used. But you could also use this for SQL injection vulnerabilities, network discovery and other means related to penetration testing.

27. MTR


MTR combines the functionality of traceroute and the ping tool into a single network diagnostic tool. When using the tool it will limit the number hops individual packets has to travel while also listening to their expiry. It then repeats this every second.

28. Tcpdump


Tcpdump will output a description of the contents of the packet it just captured which matches the expression that you provided in the command. You can also save the this data for further analysis.

29. Justniffer


Justniffer is a tcp packet sniffer. You can choose whether you would like to collect low-level data or high-level data with this sniffer. It also allows you to generate logs in customizable way. You could for instance mimic the access log that apache has.

System related monitoring

30. nmon


nmon either outputs the data on screen or saves it in a comma separated file. You can display CPU, memory, network, filesystems, top processes. The data can also be added to a RRD database for further analysis.

31. conky


Conky monitors a plethora of different OS stats. It has support for IMAP and POP3 and even support for many popular music players! For the handy person you could extend it with your own scripts or programs using Lua.

32. Glances


Glances monitors your system and aims to present a maximum amount of information in a minimum amount of space. It has the capability to function in a client/server mode as well as monitoring remotely. It also has a web interface.

33. saidar


Saidar is a very small tool that gives you basic information about your system resources. It displays a full screen of the standard system resources. The emphasis for saidar is being as simple as possible.

34. RRDtool


RRDtool is a tool developed to handle round-robin databases or RRD. RRD aims to handle time-series data like CPU load, temperatures etc. This tool provides a way to extract RRD data in a graphical format.

35. monit


Monit has the capability of sending you alerts as well as restarting services if they run into trouble. It’s possible to perform any type of check you could write a script for with monit and it has a web user interface to ease your eyes.

36. Linux process explorer

linux-process-monitor
Linux process explorer is akin to the activity monitor for OSX or the windows equivalent. It aims to be more usable than top or ps. You can view each process and see how much memory usage or CPU it uses.

37. df


df is an abbreviation for disk free and is pre-installed program in all unix systems used to display the amount of available disk space for filesystems which the user have access to.

38. discus


Discus is similar to df however it aims to improve df by making it prettier using fancy features as colors, graphs and smart formatting of numbers.

39. xosview


xosview is a classic system monitoring tool and it gives you a simple overview of all the different parts of the including IRQ.

40. Dstat


Dstat aims to be a replacement for vmstat, iostat, netstat and ifstat. It allows you to view all of your system resources in real-time. The data can then be exported into csv. Most importantly dstat allows for plugins and could thus be extended into areas not yet known to mankind.

41. Net-SNMP

SNMP is the protocol ‘simple network management protocol’ and the Net-SNMP tool suite helps you collect accurate information about your servers using this protocol.

42. incron

Incron allows you to monitor a directory tree and then take action on those changes. If you wanted to copy files to directory ‘b’ once new files appeared in directory ‘a’ that’s exactly what incron does.

43. monitorix

Monitorix is lightweight system monitoring tool. It helps you monitor a single machine and gives you a wealth of metrics. It also has a built-in HTTP server to view graphs and a reporting mechanism of all metrics.

44. vmstat


vmstat or virtual memory statistics is a small built-in tool that monitors and displays a summary about the memory in the machine.

45. uptime

This small command that quickly gives you information about how long the machine has been running, how many users currently are logged on and the system load average for the past 1, 5 and 15 minutes.

46. mpstat


mpstat is a built-in tool that monitors cpu usage. The most common command is using mpstat -P ALL which gives you the usage of all the cores. You can also get an interval update of the CPU usage.

47. pmap


pmap is a built-in tool that reports the memory map of a process. You can use this command to find out causes of memory bottlenecks.

48. ps


The ps command will give you an overview of all the current processes. You can easily select all processes using the command ps -A

49. sar


sar is a part of the sysstat package and helps you to collect, report and save different system metrics. With different commands it will give you CPU, memory and I/O usage among other things.

50. collectl


Similar to sar collectl collects performance metrics for your machine. By default it shows cpu, network and disk stats but it collects a lot more. The difference to sar is collectl is able to deal with times below 1 second, it can be fed into a plotting tool directly and collectl monitors processes more extensively.

51. iostat


iostat is also part of the sysstat package. This command is used for monitoring system input/output. The reports themselves can be used to change system configurations to better balance input/output load between hard drives in your machine.

52. free


This is a built-in command that displays the total amount of free and used physical memory on your machine. It also displays the buffers used by the kernel at that given moment.

53. /Proc file system


The proc file system gives you a peek into kernel statistics. From these statistics you can get detailed information about the different hardware devices on your machine. Take a look at the full list of the proc file statistics

54. GKrellM

GKrellm is a gui application that monitor the status of your hardware such CPU, main memory, hard disks, network interfaces and many other things. It can also monitor and launch a mail reader of your choice.

55. Gnome system monitor


Gnome system monitor is a basic system monitoring tool that has features looking at process dependencies from a tree view, kill or renice processes and graphs of all server metrics.

Log monitoring tools

56. GoAccess


GoAccess is a real-time web log analyzer which analyzes the access log from either apache, nginx or amazon cloudfront. It’s also possible to output the data into HTML, JSON or CSV. It will give you general statistics, top visitors, 404s, geolocation and many other things.

57. Logwatch

Logwatch is a log analysis system. It parses through your system’s logs and creates a report analyzing the areas that you specify. It can give you daily reports with short digests of the activities taking place on your machine.

58. Swatch


Much like Logwatch Swatch also monitors your logs, but instead of giving reports it watches for regular expression and notifies you via mail or the console when there is a match. It could be used for intruder detection for example.

59. MultiTail


MultiTail helps you monitor logfiles in multiple windows. You can merge two or more of these logfiles into one. It will also use colors to display the logfiles for easier reading with the help of regular expressions.

System tools

60. acct or psacct

acct or psacct (depending on if you use apt-get or yum) allows you to monitor all the commands a users executes inside the system including CPU and memory time. Once installed you get that summary with the command ‘sa’.

61. whowatch

Similar to acct this tool monitors users on your system and allows you to see in real time what commands and processes they are using. It gives you a tree structure of all the processes and so you can see exactly what’s happening.

62. strace


strace is used to diagnose, debug and monitor interactions between processes. The most common thing to do is making strace print a list of system calls made by the program which is useful if the program does not behave as expected.

63. DTrace


DTrace is the big brother of strace. It dynamically patches live running instructions with instrumentation code. This allows you to do in-depth performance analysis and troubleshooting. However, it’s not for the weak of heart as there is a 1200 book written on the topic.

64. webmin


Webmin is a web-based system administration tool. It removes the need to manually edit unix configuration files and lets you manage the system remotely if need be. It has a couple of monitoring modules that you can attach to it.

65. stat


Stat is a built-in tool for displaying status information of files and file systems. It will give you information such as when the file was modified, accessed or changed.

66. ifconfig


ifconfig is a built-in tool used to configure the network interfaces. Behind the scenes network monitor tools use ifconfig to set it into promiscuous mode to capture all packets. You can do it yourself with ifconfig eth0 promiscand return to normal mode with ifconfig eth0 -promisc.

67. ulimit


ulimit is a built-in tool that monitors system resources and keeps a limit so any of the monitored resources don’t go overboard. For instance making a fork bomb where a properly configured ulimit is in place would be totally fine.

68. cpulimit

CPUlimit is a small tool that monitors and then limits the CPU usage of a process. It’s particularly useful to make batch jobs not eat up too many CPU cycles.

69. lshw


lshw is a small built-in tool extract detailed information about the hardware configuration of the machine. It can output everything from CPU version and speed to mainboard configuration.

70. w

W is a built-in command that displays information about the users currently using the machine and their processes.

71. lsof


lsof is a built-in tool that gives you a list of all open files and network connections. From there you can narrow it down to files opened by processes, based on the process name, by a specific user or perhaps kill all processes that belongs to a specific user.

Infrastructure monitoring tools

72. Server Density


Our linux monitoring tool! It has a web interface that allows you to set alerts and view graphs for all system and network metrics. You can also set up monitoring of websites whether they are up or down. Server Density allows you to set permissions for users and you can extend your monitoring with our plugin infrastructure or api. The service already supports Nagios plugins.

73. OpenNMS


OpenNMS has four main functional areas: event management and notifications; discovery and provisioning; service monitoring and data collection. It’s designed to be customizable to work in a variety of network environments.

74. SysUsage


SysUsage monitors your system continuously via Sar and other system commands. It also allows notifications to alarm you once a threshold is reached. SysUsage itself can be run from a centralized place where all the collected statistics are also being stored. It has a web interface where you can view all the stats.

75. brainypdm


brainypdm is a data management and monitoring tool that has the capability to gather data from nagios or another generic source to make graphs. It’s cross-platform, has custom graphs and is web based.

76. PCP


PCP has the capability of collating metrics from multiple hosts and does so efficiently. It also has a plugin framework so you can make it collect specific metrics that is important to you. You can access graph data through either a web interface or a GUI. Good for monitoring large systems.

77. KDE system guard


This tool is both a system monitor and task manager. You can view server metrics from several machines through the worksheet and if a process needs to be killed or if you need to start a process it can be done within KDE system guard.

78. Munin


Munin is both a network and a system monitoring tool which offers alerts for when metrics go beyond a given threshold. It uses RRDtool to create the graphs and it has web interface to display these graphs. Its emphasis is on plug and play capabilities with a number of plugins available.

79. Nagios


Nagios is system and network monitoring tool that helps you monitor monitor your many servers. It has support for alerting for when things go wrong. It also has many plugins written for the platform.

80. Zenoss


Zenoss provides a web interface that allows you to monitor all system and network metrics. Moreover it discovers network resources and changes in network configurations. It has alerts for you to take action on and it supports the Nagios plugins.

81. Cacti


(And one for luck!) Cacti is network graphing solution that uses the RRDtool data storage. It allows a user to poll services at predetermined intervals and graph the result. Cacti can be extended to monitor a source of your choice through shell scripts.

82. Zabbix

Zabbix Monitoring
Zabbix is an open source infrastructure monitoring solution. It can use most databases out there to store the monitoring statistics. The Core is written in C and has a frontend in PHP. If you don’t like installing an agent, Zabbix might be an option for you.

Bonus section:

Thanks for your suggestions. It’s an oversight on our part that we’ll have to go back trough and renumber all the headings. In light of that, here’s a short section at the end for some of the Linux monitoring tools recommended by you:

83. collectd

Collectd is a Unix daemon that collects all your monitoring statistics. It uses a modular design and plugins to fill in any niche monitoring. This way collectd stays as lightweight and customizable as possible.

84. Observium

Observium is an auto-discovering network monitoring platform supporting a wide range of hardware platforms and operating systems. Observium focuses on providing a beautiful and powerful yet simple and intuitive interface to the health and status of your network.

85. Nload

It’s a command line tool that monitors network throughput. It’s neat because it visualizes the in and and outgoing traffic using two graphs and some additional useful data like total amount of transferred data. You can install it with

or

84. SmokePing

SmokePing keeps track of the network latencies of your network and it visualises them too. There are a wide range of latency measurement plugins developed for SmokePing. If a GUI is important to you it’s there is an ongoing development to make that happen.

85. MobaXterm

If you’re working in windows environment day in and day out. You may feel limited by the terminal Windows provides. MobaXterm comes to the rescue and allows you to use many of the terminal commands commonly found in Linux. Which will help you tremendously in your monitoring needs!

86. Shinken monitoring

Shinken is a monitoring framework which is a total rewrite of Nagios in python. It aims to enhance flexibility and managing a large environment. While still keeping all your nagios configuration and plugins.

 

10个惊艳的Swift单行代码

Standard

http://www.codeceo.com/article/10-swift-oneline-code.html

1 数组中的每个元素乘以2

特别简单,尤其是使用map解决的话。

(1...1024).map{$0 * 2}

2 数组中的元素求和

虽然这里使用reduce和加号运算符,借助了加号运算符是函数这样一个事实,但解决办法是显而易见的,我们可以看到 reduce更具创意的用法。

(1...1024).reduce(0,combine: +)

3 验证在字符串中是否存在指定单词

让我们使用 filter来验证tweet中是否包含选定的若干关键字中的一个:

let words = ["Swift","iOS","cocoa","OSX","tvOS"]
let tweet = "This is an example tweet larking about Swift"

let valid = !words.filter({tweet.containsString($0)}).isEmpty
valid //true

更新:@oisdk提出一些更好的选择:

words.contains(tweet.containsString)

方式更简洁,还有这一个:

tweet.characters
  .split(" ")
  .lazy
  .map(String.init)
  .contains(Set(words).contains)

4 读取文件

像其他语言一样,通过简单的内置来读取文件到数组中是不可能,但我们可以结合使用 split 和 map创造一些不需要for循环的简短代码:

let path = NSBundle.mainBundle().pathForResource("test", ofType: "txt")

let lines = try? String(contentsOfFile: path!).characters.split{$0 == "\n"}.map(String.init)
if let lines=lines {
    lines[0] // O! for a Muse of fire, that would ascend
    lines[1] // The brightest heaven of invention!
    lines[2] // A kingdom for a stage, princes to act
    lines[3] // And monarchs to behold the swelling scene.
}

map和字符串构造函数的最后一步把我们的数组字符转换为字符串。

5 祝你生日快乐!

这将显示生日快乐歌到控制台,通过map以及范围和三元运算符的简单使用。

let name = "uraimo"
(1...4).forEach{print("Happy Birthday " + (($0 == 3) ? "dear \(name)":"to You"))}

6 过滤数组中的数字

在这种情况下,我们需要使用提供的过滤函数分区一个序列。许多语言除了拥有常用的map、flatMap、reduce、filter等,还有正好能做这件事的 partitionBy 函数,Swift如你所知没有类似的东西(NSPredicate提供的可以过滤的NSArray函数在这里不是我们所需要的)。

因此,我们可以用 partitionBy 函数扩展 SequenceType 来解决这个问题,我们将使用 partitionBy 函数来分区整型数组:

extension SequenceType{
    typealias Element = Self.Generator.Element

    func partitionBy(fu: (Element)-&gt;Bool)-&gt;([Element],[Element]){
        var first=[Element]()
        var second=[Element]()
        for el in self {
            if fu(el) {
                first.append(el)
            }else{
                second.append(el)
            }
        }
        return (first,second)
    }
}

let part = [82, 58, 76, 49, 88, 90].partitionBy{$0 &lt; 60}
part // ([58, 49], [82, 76, 88, 90])

不是真正的单行代码。那么,我们是否可以使用过滤器来改善它?

extension SequenceType{

    func anotherPartitionBy(fu: (Self.Generator.Element)-&gt;Bool)-&gt;([Self.Generator.Element],[Self.Generator.Element]){
        return (self.filter(fu),self.filter({!fu($0)}))
    }
}

let part2 = [82, 58, 76, 49, 88, 90].anotherPartitionBy{$0 &lt; 60}
part2 // ([58, 49], [82, 76, 88, 90])

稍微好了一点,但它遍历了序列两次,并且试图把它变成单行代码删除闭包功能将会导致太多重复的东西(过滤函数和数组会在两个地方使用)。

我们是否使用单个数据流建立一些能够将初始序列转换为分区元组的东西?是的,我们可以用 reduce

var part3 = [82, 58, 76, 49, 88, 90].reduce( ([],[]), combine: {
	(a:([Int],[Int]),n:Int) -&gt; ([Int],[Int]) in
	(n&lt;60) ? (a.0+[n],a.1) : (a.0,a.1+[n]) 
})
part3 // ([58, 49], [82, 76, 88, 90])

我们在这里构建了包含两个分区的结果元组,一次一个元素,使用过滤函数测试初始序列中的每个元素,并根据过滤结果追加该元素到第一或第二分区数组中。

最后得到真正的单行代码,但要注意这样一个事实,即分区数组通过追加被构建,实际上会使其比前两个实施方式要慢。

7 获取并解析XML Web服务

上面的有些语言不依赖外部库,并默认提供多个选项来处理XML(例如Scala虽然笨拙但“本地”地支持XML解析成对象),但Foundation只提供了SAX解析器NSXMLParser,并且正如你可能已经猜到的那样,我们不打算使用它。

有几个替代的开源库,我们可以在这种情况下使用,其中一些用C或Objective-C编写,其他为纯Swift。

这次,我们打算使用纯Swift的AEXML:

let xmlDoc = try? AEXMLDocument(xmlData: NSData(contentsOfURL: NSURL(string:"https://www.ibiblio.org/xml/examples/shakespeare/hen_v.xml")!)!)

if let xmlDoc=xmlDoc {
    var prologue = xmlDoc.root.children[6]["PROLOGUE"]["SPEECH"]
    prologue.children[1].stringValue // Now all the youth of England are on fire,
    prologue.children[2].stringValue // And silken dalliance in the wardrobe lies:
    prologue.children[3].stringValue // Now thrive the armourers, and honour's thought
    prologue.children[4].stringValue // Reigns solely in the breast of every man:
    prologue.children[5].stringValue // They sell the pasture now to buy the horse,
}

8 在数组中查找最小(或最大)值

我们有各种方法来找到序列中的最小和最大值,其中有 minElement 和maxElement 函数:

//Find the minimum of an array of Ints
[10,-22,753,55,137,-1,-279,1034,77].sort().first
[10,-22,753,55,137,-1,-279,1034,77].reduce(Int.max, combine: min)
[10,-22,753,55,137,-1,-279,1034,77].minElement()

//Find the maximum of an array of Ints
[10,-22,753,55,137,-1,-279,1034,77].sort().last
[10,-22,753,55,137,-1,-279,1034,77].reduce(Int.min, combine: max)
[10,-22,753,55,137,-1,-279,1034,77].maxElement()

9 并行处理

某些语言允许用一种简单和透明的方式启用数组对功能,例如map和flatMap的并行处理,以加快顺序和独立操作的执行。

此功能Swift中还不可用,但可以使用GCD构建:http://moreindirection.blogspot.it/2015/07/gcd-and-parallel-collections-in-swift.html

10 埃拉托斯特尼筛法

埃拉托斯特尼筛法用于查找所有的素数直到给定的上限n。

从小于n的所有整数序列开始,算法删除所有整数的倍数,直到只剩下素数。并且为了加快执行速度,我们实际上并不需要检查每个整数的倍数,我们止步于n的平方根就可以了。

根据这一定义首次执行可能是这样的:

var n = 50
var primes = Set(2...n)

(2...Int(sqrt(Double(n)))).forEach{primes.subtractInPlace((2*$0).stride(through:n, by:$0))}
primes.sort()

我们使用外部范围来迭代我们要检查的整数,并且对于每一个整数我们使用 stride(through:Int by:Int)计算出数字的倍数的序列。那些序列然后从Set中减去,Set用所有从2到n的整数初始化。

但正如你所看到的,为了实际移除倍数,我们使用外部可变Set,导致了附带后果。

为了消除附带后果,正如我们通常应该做的那样,我们会先计算所有序列,用倍数的单一数组来flatMap它们,并从初始Set中删除这些整数。

var sameprimes = Set(2...n)

sameprimes.subtractInPlace((2...Int(sqrt(Double(n))))
						   .flatMap{ (2*$0).stride(through:n, by:$0)})
sameprimes.sort()

方式更清洁,使用flatMap的一个很好的例子以生成扁平化的嵌套数组。

11其他:通过解构元组交换

最后一点,并非每个人都知道的是,和其他有tuple类型的语言一样,元组可以用来执行紧凑的变量交换:

var a=1,b=2

(a,b) = (b,a)
a //2
b //1

好了,正如所料,Swift和其他语言一样富有表现力。