存档

‘Programming’ 分类的存档

[整理]用CSS自动缩小过宽图片

2010年2月21日 Galaxy 没有评论

简单说,如果要全局改,就是:

img {
	max-width: 600px;
	width: expression(this.width > 600 ? 600: true);
	height: auto;
}

对WP的主题,就是改style.css
阅读全文…

分类: HTML_CSS_JS 标签: , ,

[原创]用Perl写的归并排序(Merge sort)

2010年2月11日 Galaxy 没有评论

说是排序,其实大家用的时候往往都是来合并其他方法排序的局部结果的。
英文wiki直接写具体到排序方法最后才谈大家咋用,中文wiki就上来就谈合并,后面才讲咋排序。老外从小到大,咱从大到小,倒也是常态。
阅读全文…

[ZT]以后谁再跟我说MySQL性能好我跟谁急……

2009年12月20日 Galaxy 没有评论

性能测试, 数据库
http://obmem.com/?p=317

TNND,今天浪费了一天的时间在Mysql上面,先是改代码,然后是转换sqlite3数据库到mysql,然后发现原来好好的网站跑不起来了。 @。@ 然后就这么折腾了半天,基本上确定了,在select语句上,mysql的性能平均落后sqlite十倍左右,内存消耗超过sqlite则是三倍左右。
-
实际上mysql更灵活点,我的意思是:给mysql三倍的内存,那么他的表现只比sqlite慢十倍而已,如果你给他很抠门的内存?那么超时是唯一的结果。就像我一开始网站挂掉那样。
-
阅读全文…

分类: SQL 标签: , , ,

在bash中使用变量中的大于号来重定向

2009年12月2日 Galaxy 没有评论

http://stackoverflow.com/questions/1592859/how-to-supply-many-argv-and-outputredirection-with-one-bash-var

How to supply many argv and outputredirection with one bash var ?
In file a.lst:

in1.a in1.b > out1.a 2> out1.b
in2.a in2.b > out2.a 2> out2.b

In do.sh:

CLI=$(sed -n -e "1 p" a.lst)
perl a.pl $CLI

I want to run like perl a.pl in1.a in1.b > out1.a 2> out1.b, how can I make it work ?


$ARGV is populated with every argument. What doesn’t work is the outputredirection – Vinko Vrsalovic Oct 20 at 7:03

I can’t test it here, but it looks like using eval will work, so:

eval perl a.pl $CLI

阅读全文…

分类: Other Scripts 标签:

GNU C library下的getline

2009年11月19日 Galaxy 没有评论

http://www.gnu.org/s/libc/manual/html_node/Line-Input.html
12.9 Line-Oriented Input

Since many programs interpret input on the basis of lines, it is convenient to have functions to read a line of text from a stream.

Standard C has functions to do this, but they aren’t very safe: null characters and even (for gets) long lines can confuse them. So the GNU library provides the nonstandard getline function that makes it easy to read lines reliably.

Another GNU extension, getdelim, generalizes getline. It reads a delimited record, defined as everything through the next occurrence of a specified delimiter character.

All these functions are declared in stdio.h.


SYNOPSIS

#define _GNU_SOURCE	// 没这个编译时会有warning, 详见下文
#include <stdio .h>
 
ssize_t getline(char **lineptr, size_t *n, FILE *stream);
ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
</stdio>

读到的字符串,当然也是包括结尾的\n的;行末没\n的也不会加\ndelim也是类似。
阅读全文…

分类: C_CPP_CS 标签: ,

[整理]How do you get assembler output from C/C++ source in gcc?

2009年11月18日 Galaxy 没有评论

http://stackoverflow.com/questions/137038/how-do-you-get-assembler-output-from-c-c-source-in-gcc
http://www.delorie.com/djgpp/v2faq/faq8_20.html

http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html#s3

gcc -S -o my_asm_output.s helloworld.c

gcc -c -g -Wa,-a,-ad [other GCC options] foo.c > foo.lst

file helloworld
objdump -s --disassemble helloworld > helloworld.dump

-masm=dialect
Output asm instructions using selected dialect. Supported choices
are intel or att (the default one).
阅读全文…

分类: C_CPP_CS 标签: , ,

[整理]Regular Expressions Libraries

2009年11月18日 Galaxy 没有评论

目前只小程序,暂时先关心C下的。

TRE基本就是把GNU C library那个给抠出来了,能查找匹配的起止位置。说简单还是要自己写代码取具体字符,感觉用处不大。

PCRE是Perl Compatible Regular Expressions,功能上比较接近Perl的,作为Perl程序员,首选之。

regex嘛,不知道……
看到2008年的alpha就懒得试。难道已经终止开发了?

C++下有个专用的:

boost
Linux下搞C++不用boost,那基本就白活了,大概……
我可没说C++下不能用PCRE。


http://www.dmoz.org/Computers/Programming/Languages/Regular_Expressions/C_and_C%2b%2b/

  • C++ Regular Expression Library – A free component that enables the use of regular expression searching in a C++ program.
  • Grammar to parser classes – C++ template classes for declaring grammars directly in the code as set of compound classes. Includes regexp_parser class for parsing input upon regular expression definition provided in its constructor.
  • Oniguruma – A C regular expression library, developed for the programming language Ruby. Provides software-download, description, links and references.
  • PCRE – Perl Compatible Regular Expressions – A C library for matching regular expressions with Perl 5 syntax and semantics. PCRE has its own native API, as well as a set of wrapper functions that correspond to the POSIX regular expression API.
  • PCRE Win32 – Provides compile PCRE libraries for Windows developers, and source code to build with Visual C++.
  • regex – A modified version of Henry Spencer’s regular expression library (Autoconf, Automake and Libtool scripts have been added and a few file names have been changed). Also related links.
  • TRE – Lightweight, robust, and almost fully POSIX compliant regexp matching library which supports approximate matches. [GNU GPL].
  • xpressive – A C++ regex template library that allows regexes to be written as strings or as expression templates and to refer to themselves and other regexes recursively.

  • Text processing for C/C++ programmers – John Maddock, the author of RegEx++, explains how to use Regular Expressions in C/C++ programs. (October 1, 2001)

阅读全文…

分类: C_CPP_CS 标签: ,

[ZT]Static Library & Dynamic Library – linux系统下的静态库与动态库

2009年11月17日 Galaxy 没有评论

http://hi.baidu.com/pigfanfan/blog/item/e4f884a4e9484ef09152ee42.html

Static library & dynamic library — linux系统下的静态库与动态库
2008-12-01 18:17
写这篇文章主要是由于昨天心心同学问了个关于实现动态库链接的makefile。然后我囧了,没能解答=,=
然后今天把《Advanced Linux Programming》看了下,把笔记写下来。。。
难免回有错误,还忘不吝指正:)
我们知道,几乎所有的程序在运行时都会链接到一个或多个库。比如C语言的printf函数,调用此函数时就会用到c的标准输入输出库;而在GUI下面,会用到对应的图形库;调用数据库时,会用到数据库系统提供的相应的库,等等。

补充:objdump可以查看些信息。
阅读全文…

分类: C_CPP_CS 标签: ,
Locations of visitors to this page