当前位置: 首页 - Archives - 2010-03
显示模式: 普通 | 列表

广州·工作·理想

最近上班都很累,感觉很空虚,每天做着同样的事情。

我不想就这样帮别人打一辈子的工,要是这样的生活持续下去真是生不如死。

我现在最缺乏的是一个想法,一个好的想法,一个可以让我放弃一切努力去实现的想法。

我每天都在思考这个问题,我到底能做什么,我到底该做什么,然后接着怎么办。

每天工作的时候,休息的时候。

我是不是一直浪费自己的青春、浪费自己的时间和生命。

努力地学习,努力地工作,不过一切都是那么的空虚,没有激情,缺少点什么。


一直都是在为别人做,我什么时候能帮自己做一会,努力为自己的愿望和理想而做?


自从看来公司上班以后,以前的自信一下消失不见了,原来自己来这里之后,自己成了一个新人,一个什么都不会的新人,做什么事都小心翼翼的新人。


我不要这样,我要有自己的自信,我有自己的自信,以前的自信,我要把它找回来。

我要努力,为了自己,为了对得起自己。

为了自己,努力,加油!


阅读全文...
分类: Feeling Of Life | Diaries  引用: 0  评论: 0  点击: 39

MySQL分钟数据类型的区别

char、varchar、text、ntext、 bigint、int、smallint、tinyint和bit的区别及数据库的数据类型

Varchar 对每个英文(ASCII)字符都占用2个字节,对一个汉字也只占用两个字节
char 对英文(ASCII)字符占用1个字节,对一个汉字占用2个字节Varchar 的类型不以空格填满,比如varchar(100),但它的值只是"qian",则它的值就是"qian"而char 不一样,比如char(100),它的值是"qian",而实际上它在数据库中是"qian "(qian后共有96个空格,就是把它填满为100个字节)。
由于char是以固定长度的,所以它的速度会比varchar快得多!但程序处 理起来要麻烦一点,要用trim之类的函数把两边的空格去掉!
ntext
可变长度 Unicode 数据的最大长度为 230 - 1 (1,073,741,823) 个字符。存储大小是所输入字符个数的两倍(以字节为单位)。ntext 在 SQL-92 中的同义词是 national text。
text
服务器代码页中的可变长度非 Unicode 数据的最大长度为 231-1 (2,147,483,647) 个字符。当服务器代码页使用双字节字符时,存储量仍是 2,147,483,647 字节。存储大小可能小于 2,147,483,647 字节(取决于字符串)。
bigint:从-2^63(-9223372036854775808)到 2^63-1(9223372036854775807)的整型数据,存储大小为 8 个字节。


阅读全文...

标签: 数据类型  区别 

分类: Database | MySQL  引用: 0  评论: 0  点击: 29

Erlang OTP 之 Application

application

Generic OTP application functions

In OTP, application denotes a component implementing some specific functionality, that can be started and stopped as a unit, and which can be re-used in other systems as well. This module interfaces the application controller, a process started at every Erlang runtime system, and contains functions for controlling applications (for example starting and stopping applications), and functions to access information about applications (for example configuration parameters).
An application is defined by an application specification. The specification is normally located in an application resource file called Application.app, where Application is the name of the application. Refer to app(4) for more information about the application specification.
This module can also be viewed as a behaviour for an application implemented according to the OTP design principles as a supervision tree. The definition of how to start and stop the tree should be located in an application callback module exporting a pre-defined set of functions.
Refer to OTP Design Principles for more information about applications and behaviours.

Functions


get_all_env() -> Env

get_all_env(Application) -> Env

  • Application = atom()
  • Env = [{Par,Val}]
  •  Par = atom()
  •  Val = term()


阅读全文...

标签: OTP  Application 

分类: Programming | Erlang  引用: 0  评论: 0  点击: 46

Erlang OTP 自定义behaviour

为什么要使用behaviour,如果您对erlang有所了解的话,就明白其中的好处。
可以做到代码通用,可以减少错误,可以使用很多成熟的久经考验的模式,可以减轻无谓的重复劳动等等。。
有些时候,你可能需要定义自己的behaviour,这可不仅仅是OTP的权力。
自己定义behaviour非常简单,仅仅需要几步。
下面是一个例子:


Erlang 代码
  1. -module(my_behaviour).  
  2.   
  3. -export([behaviour_info/1]).  
  4. behaviour_info(callbacks) ->  
  5.     [{init,1},  
  6.      {handle, 2}];  
  7. behaviour_info(_Other) ->  
  8.     undefined.  
  9.   
  10. -export([start/1, stop/0]).  
  11. start(Mod) ->  
  12.     State = Mod:init(0),  
  13.     {ok, State2} = Mod:handle(add,  State),  
  14.     io:format("state :~p~n", [State2]).  
  15. stop() ->  
  16.     stop.  


阅读全文...

标签: OTP  自定义  behaviour 

分类: Programming | Erlang  引用: 0  评论: 0  点击: 37

Erlang四大behaviour之三-gen_event

1. 事件处理规则

在OTP中,事件管理器是一个事件可以发送到的命名对象,一个事件可以是一个错误、一个警告、或者一些要写入日志的信息
在事件管理器中,有0个、一个或者多个事件处理器被安装,当事件管理器被一个事件通知时,这个事件将被安装在事件管理器中的事件处理器处理,
事件管理器用一个进程实现,事件处理器用回调模块实现。事件管理器本质上维护一个{Module, State}列表,每一个Module为一个事件处理器,而State为事件处理器的内部状态。

 

2. 例子

事件处理器的回调模块把错误信息写入终端
 
-module(terminal_logger).
-behaviour(gen_event).
-export([init/1, handle_event/2, terminate/2]).
init(_Args) ->
    {ok, []}.
handle_event(ErrorMsg, State) ->
    io:format("***Error*** ~p~n", [ErrorMsg]),
    {ok, State}.
terminate(_Args, _State) ->
    ok.


阅读全文...

标签: behaviour  gen_event 

分类: Programming | Erlang  引用: 0  评论: 0  点击: 17

Erlang四大behaviour之四 - Supervisor

1. 监督规则

一个监督者负责启动、停止、监控他的子进程。监督者的一个基本概念就是当必要的时候重启子进程保证它们的存活
哪个子进程要重启和被监控是由一个子规程列表决定的,子进程按照列表中指定的顺序启动,并按相反的顺序终止

 

2. 实例

监督者的回调模块
 
-module(ch_sup).
-behaviour(supervisor).
-export([start_link/0]).
-export([init/1]).
start_link() ->
    supervisor:start_link(ch_sup, []).
init(_Args) ->
    {ok, {{one_for_one, 1, 60},
          [{ch3, {ch3, start_link, []},
            permanent, brutal_kill, worker, [ch3]}]}}.


阅读全文...

标签: behaviour  Supervisor 

分类: Programming | Erlang  引用: 0  评论: 0  点击: 32

erl -s make all -s c q


erl -s make all -s c q
的解释


make
A Make Utility for Erlang
The module make provides a set of functions similar to the UNIX type Make functions.
Functions

all() -> up_to_date | error
all(Options) -> up_to_date | error
  • Options = [Option]
  •  Option = noexec | load | netload | <compiler option>
This function first looks in the current working directory for a file named Emakefile (see below) specifying the set of modules to compile and the compile options to use. If no such file is found, the set of modules to compile defaults to all modules in the current working directory.
Traversing the set of modules, it then recompiles every module for which at least one of the following conditions apply:
  • there is no object file, or
  • the source file has been modified since it was last compiled, or,
  • an include file has been modified since the source file was last compiled.
As a side effect, the function prints the name of each module it tries to compile. If compilation fails for a module, the make procedure stops and error is returned.


阅读全文...

标签: 编译 

分类: Programming | Erlang  引用: 1  评论: 0  点击: 13

erlang四大behaviour之二 - gen_fsm

今天介绍erlang的一个非常重要的behaviour,就是gen_fsm-有限状态机,有限状态机的作用非常之多,比如文本解析,模式匹配、 游戏逻辑等等方面的处理都是它的强项,所以这个behaviour非常之重要

1. 有限状态机

有限状态机可以用下面这个公式来表达
 
State(S) x Event(E) -> Actions(A), State(S')

表示的就是在S状态时如果有事件E发生,那么执行动作A后把状态调整到S’。
对于一个用gen_fsm行为实现的状态机来说,状态转变规则被写为符合如下规定的一系列Erlang函数:
StateName( Event, StateData ) ->
.. code for actions here …
{ next_state, StateName’, StateData’ }



2. 一个例子

erlang手册中用这个例子来解释的:开锁问题,有一个密码锁的门,它就可以看作一个状态机,初始状态门是锁着的,任何时候有人按一个密码键就会 产生一个事件,这个键值和前面的按键组合后与密码相比较,看是否正确,如果输入的密码顺序是对的,那么将门打开30秒,如果输入密码不完全,则等待下次按 钮按下,如果输入密码顺序是错的,则重新开始等待按键按下。

 
-module(code_lock).
-behaviour(gen_fsm).
-export([start_link/1]).
-export([button/1]).
-export([init/1, locked/2, open/2]).
start_link(Code) ->
    gen_fsm:start_link({local, code_lock}, code_lock, Code, []).
button(Digit) ->
    gen_fsm:send_event(code_lock, {button, Digit}).
init(Code) ->
    {ok, locked, {[], Code}}.
locked({button, Digit}, {SoFar, Code}) ->
    case [Digit|SoFar] of
        Code ->
            do_unlock(),
            {next_state, open, {[], Code}, 3000};
        Incomplete when length(Incomplete)<length(Code) ->
            {next_state, locked, {Incomplete, Code}};
        _Wrong ->
            {next_state, locked, {[], Code}}
    end.
open(timeout, State) ->
    do_lock(),
    {next_state, locked, State}.


阅读全文...

标签: gen_fsm  behaviour 

分类: Programming | Erlang  引用: 0  评论: 0  点击: 30

erl启动参数说明

最近被一个问题困扰,先把错误提示发出来:
kernel-poll not supported; "K" parameter ignored
{error_logger,{{2010,3,27},{9,23,16}},"Protocol: ~p: register error: ~p~n",["inet_tcp",{{badmatch,{error,duplicate_name}},[{inet_tcp_dist,listen,1},{net_kernel,start_protos,4},{net_kernel,start_protos,3},{net_kernel,init_node,2},{net_kernel,init,1},{gen_server,init_it,6},{proc_lib,init_p_do_apply,3}]}]}
{error_logger,{{2010,3,27},{9,23,16}},crash_report,[[{initial_call,{net_kernel,init,['Argument__1']}},{pid,<0.20.0>},{registered_name,[]},{error_info,{exit,{error,badarg},[{gen_server,init_it,6},{proc_lib,init_p_do_apply,3}]}},{ancestors,[net_sup,kernel_sup,<0.9.0>]},{messages,[]},{links,[#Port<0.65>,<0.17.0>]},{dictionary,[{longnames,true}]},{trap_exit,true},{status,running},{heap_size,377},{stack_size,24},{reductions,454}],[]]}
{error_logger,{{2010,3,27},{9,23,16}},supervisor_report,[{supervisor,{local,net_sup}},{errorContext,start_error},{reason,{'EXIT',nodistribution}},{offender,[{pid,undefined},{name,net_kernel},{mfa,{net_kernel,start_link,[['xge@127.0.0.1',longnames]]}},{restart_type,permanent},{shutdown,2000},{child_type,worker}]}]}
{error_logger,{{2010,3,27},{9,23,16}},supervisor_report,[{supervisor,{local,kernel_sup}},{errorContext,start_error},{reason,shutdown},{offender,[{pid,undefined},{name,net_sup},{mfa,{erl_distribution,start_link,[]}},{restart_type,permanent},{shutdown,infinity},{child_type,supervisor}]}]}
{error_logger,{{2010,3,27},{9,23,16}},std_info,[{application,kernel},{exited,{shutdown,{kernel,start,[normal,[]]}}},{type,permanent}]}
{"Kernel pid terminated",application_controller,"{application_start_failure,kernel,{shutdown,{kernel,start,[normal,[]]}}}"}

Crash dump was written to: erl_crash.dump
Kernel pid terminated (application_controller) ({application_start_failure,kernel,{shutdown,{kernel,start,[normal,[]]}}})

Crash dump was written to: erl_crash.dump
Kernel pid terminated (application_controller) ({application_start_failure,kernel,{shutdown,{kernel,start,[normal,[]]}}})


Abnormal termination




百思不得其解,接着在运行程序的bat文件上下功夫,该BAT文件的内容是:
cd ebin
start werl +P 102400 +K true +S 2 -smp -name xge@127.0.0.1 -setcookie xge -config elog -s xge start


我想启动SHELL的命令行参数有很大关系,所以参看了下DOC文档,如下,使用到的参数高亮一下。



(最后找到问题的原因在于数据库无法连接,因为创建的用户无法对未授权的数据库进行操作。可是错误太怪了,这样的错误真的不好确定出错的原因!)









阅读全文...

标签: 参数  说明  erl 

分类: Programming | Erlang  引用: 0  评论: 0  点击: 93

Erlang中的错误处理

erlang中错误大体分为四种:

   1. 编译错误
   2. 逻辑错误
   3. 运行时错误
   4. 用户代码生成的错误

编译错误,主要是编译器检测出的代码语法错误
逻辑错误,是指程序没有完成预期的工作,属于开发人员的问题
运行时错误,是指erlang运行时抛出的错误,比如对非数据类型执行算术运算,erlang运行时会捕获异常,并抛出。在erlang中,这类 异常的类型为error
用户自定义错误,是指通过exit/1或者throw/1生成

我们把运行时错误以及用户抛出的错误称为异常(exception),他们具有三种类型:throw, error, exit。
error型异常,通过erlang:error/1, 2生成,也可以使用早期的erlang:fault/1, 2
throw型异常,通过throw/1生成
exit型异常,通过exit/1生成

在erlang中,进程内的异常可以通过try, catch来进行捕获处理。
推荐使用try,其为新添加的语法。进程间的异常可以通过监督树(supervisor tree),监控进程(monitor)来实现。

badarg                   参数错误,参数格式或类型错误
badarith                 算术表达式错误,算术表达式中含有错误的参数
{badmatch,V}       模式匹配错误,V指具体的发生匹配错误的数值
function_clause  函数子句错误,没有找到匹配的函数子句
{case_clause,V} case      匹配错误,没有找到匹配的case pattern
if_clause if           子句错误,没有找到为ture的if子句
{try_clause,V}      try匹配错误,执行try时,没有找到匹配的pattern
undef                     函数未定义错误
{badfun,F}             函数错误
{badarity,F}           函数参数个数错误
timeout_value     超时参数错误,在receive.. after语法中,after对应的超时数据错误(应为不小于0的integer或infinity
noproc Process  错误,Process不存在
{nocatch,V}           throw未被catch
system_limit        系统限制错误,某些性能或数据达到系统极限

try 语法





阅读全文...

标签: 错误  Error 

分类: Programming | Erlang  引用: 0  评论: 0  点击: 34
< 1 2 >