当前目录和程序所在目录

Posted on Wed 20 October 2010 in miscLeave a comment

1.python\ 当前目录:

import os
os.getcwd()

程序所在目录:

import os
#os.path.split( os.path.realpath( sys.argv[0] ) )[0]
os.path.dirname(os.path.realpath(__file__))

2.vc/mfc\ 当前目录:

TCHAR path[MAX_PATH];
GetCurrentDirectory(path, MAX_PATH);

程序所在目录:

TCHAR path[MAX_PATH];
GetModuleFileName(NULL, path, MAX_PATH);

3.c/c++(linux)\ 当前目录 ...

Continue reading

确保FileOutputStream将内容写入硬盘

Posted on Thu 14 October 2010 in miscLeave a comment

最近写了一个程序,需要在数据写入文件后立即读取该文件内容。这一简单的功能,却会时不时抛异常,令我十分不解。

原程序如下:\

FileOutputStream os = new FileOutputStream("some_file");\ os.write(data);\ os.close();

在查了jdk中关于flush()函数的介绍后,发现了一些问题。flush只保证数据已交付给了操作系统,无法确定已写入硬盘。

以下是jdk中关于flush()函数的介绍:\

Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that ...

Continue reading

路由器的一些配置命令

Posted on Wed 30 June 2010 in miscLeave a comment

//enter admin

enable

//begine configure

configure terminal

//interface  fast.. configure

-Interface F.. 0/0(0/1)

--ip address a.b.c.d ma.mb.mc.md

//tunnel configure

-Interface T.. number(数字)

--tunnel source ip

--tunnel dest.. ip

--ip address a.b.c.d ma.mb.mc.md

--ip ospf ...

Continue reading

读取jar文件中的资源

Posted on Wed 30 June 2010 in miscLeave a comment

在前面一篇文中,生成仪表盘时使用了背景图片和指针图片,如果将这些图片(资源)和代码打包到一个jar文件中,读取的时候需要注意一下路径问题。

打包后路径如下图所示:

ict\
--Dashboard.java\
image\
-bg.png\
-pointer.png

如需在Dashboard.java中读取bg.png和pointer.png资源,可以使用如下的代码:

this.getClass().getClassLoader().getResourceAsStream("images/bg.png");
this.getClass().getClassLoader().getResourceAsStream("images/pointer.png");
Continue reading

vlc中文字幕乱码(linux下)

Posted on Wed 30 June 2010 in miscLeave a comment

仅仅为了记录...

版本 :   vlc 1.0.5\ 设置:coding gb 选上\ format 去掉\ utf-8 auto detect 去掉\ 中文字体选择

Continue reading

wchar_t相关的一些

Posted on Wed 30 June 2010 in miscLeave a comment

1.单个宽字符的相关函数

wctomb 将wchar_t字符变成多字节表示

[codesyntax lang="cpp"]

wchar_t ch = L'中';
char mb[MB_CUR_MAX];
int len = wctomb(mb, ch);//成功则返回的值大于0

[/codesyntax]

与wctomb类似有int mbtowc ( wchar_t * pwc, const char * pmb, size_t max );

2.宽字符串的相关函数

wcstombs将一个wchar_t数组转为多字节表示

size_t wcstombs ( char * mbstr, const wchar_t * wcstr, size_t max );

其中max是mbstr的最大长度。\ 与mbstowcs相反的是size_t mbstowcs ( wchar_t * wcstr, const ...

Continue reading

java 生成图片(仪表盘)

Posted on Tue 29 June 2010 in miscLeave a comment

[codesyntax lang="java"]

package ict.dashboard;

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;

public class Dashboard{

    public static void generateImage(OutputStream os, double percent, int radius){

        //
        try{
            BufferedImage canvas = new BufferedImage(radius + radius, radius ...
Continue reading

路由器配置备份与恢复(转载)

Posted on Mon 28 June 2010 in miscLeave a comment

Introduction

Routers often get upgraded or swapped out for a number of reasons. This document provides the user with some basic steps to migrate the configuration from an existing router to a new router.\

Prerequisites

Requirements

Before you use the information in this document, make sure that you meet these ...

Continue reading

gdb的基本使用(持续更新)

Posted on Fri 23 April 2010 in miscLeave a comment

gcc -g test.c

通过-g参数,可以生成gdb所需要的debug信息。可能会生成一些只有gdb才能使用的debug信息,这对其他的debug程序会造成影响。要控制这些特殊的debug信息,可以通过-gstabs+, -gstabs, -gxcoff和-gvms参数。\

gdb a.out

通过上条命令,这会启动gdb。之后就可以对a.out进行debug了。

命令list(可以简写为字母"l"),列出代码。如果list后面没有参数,就是列出“上次列出代码”的后10行代码。"list -",列出“上次列出代码”的前10行代码. "list linenumber"列出linenumber附近的10行代码. "list start,end"列出行号从start到end的代码。

命令break, 设置断点。break linenumber,在linenumber处设置断点。break functionname,在函数functionname的入口处出设置断点。

命令run(可以简写为r),运行程序。

命令next ...

Continue reading

python中的import

Posted on Wed 21 April 2010 in miscLeave a comment

[codesyntax lang="python" lines="fancy"]

import test1
import pack1.pack2.test1
from test1 import fun, cla, mod_name
from .pack import test1

[/codesyntax]

第一行是python中导入module或者package的普通方式,通过这个语句,在接下来的代码中就可以使用test1 module中所定义的function, class, var等。这类似C语言中的#include,只是在使用module中的的内容时需要加上"test."前缀(相当于c++中的namespace)。

第二行同第一行,其中的pack1和pack2都是package,而test1只能是package或module(这与第三行有区别)。

第三行是从test1 module中导入fun(方法),cla(类),mod_name(子模块)。在使用这些被导入的内容时,可以不用使用前缀(不同于第一行内容)。

第四行是在python2 ...

Continue reading