新灵空间

I will go wherever god leads me to!

Dancer::Introduction Notes

1. A route pattern can contain one or more tokens, and tokens can be optional.

 

get '/hello/:name?' => sub {
    "Hello there " . (param('name') || "whoever you are!");
};

2. A route can contain a wildcard (represented by a '*'). Each wildcard match will be returned in an arrayref, accessible via the `splat' keyword:

 

get '/download/*.*' => sub {
    my ($file, $ext) = splat;
    # do something with $file.$ext here
};

3. A route can be defined with a Perl regular expression. In order to tell Dancer to consider the route as a real regexp, the route must be defined explicitly with qr{}, like the following:

 

get qr{/hello/([\w]+)} => sub {
    my ($name) = splat;
    return "Hello $name";
};

4. Routes may include some matching conditions (on the useragent and the hostname at the moment):

 

get '/foo', {agent => 'Songbird (\d\.\d)[\d\/]*?'} => sub {
  'foo method for songbird'
}
 
get '/foo' => sub {
  'all browsers except songbird'
}

5. An action can choose not to serve the current request and ask Dancer to process the request with the next matching route. This is done with the pass keyword, like in the following example:

 

get '/say/:word' => sub {
    return pass if (params->{word} =~ /^\d+$/);
    "I say a word: ".params->{word};
};
 
get '/say/:number' => sub {
    "I say a number: ".params->{number};
};

6. Before hooks, after hooks, before_template_render hooks. 

7. You can use the load method to include additional routes into your application.

8. A Dancer application can access the information from its config file easily with the config keyword:

 

get '/appname' => sub {
    return "This is " . config->{appname};
};

9. In order to enable the logging system for your application, you first have to start the logger engine in your config.yml:

 

logger: 'file'

10. Dancer configures the Template::Toolkit engine to use <% %> brackets instead of its default [% %] brackets, although you can change this in your config file. Of course you have to import the "Template" module.  

11. A layout is a special view, located in the 'layouts' directory (inside the views directory) which must have a token named `content'. That token marks the place where to render the action view. This lets you define a global layout for your actions. Any tokens that you defined when you called the 'template' keyword are available in the layouts, as well as the standard session, request, and params tokens. This allows you to insert per-page content into the HTML boilerplate, such as page titles, current-page tags for navigation, etc. (refer to the standard document for more details).

12. Through  "set serializer => 'JSON';"  we can do data serializer;

git pull problem solving steps.

在git pull的時候遇到下面的問題:

error: Your local changes to the following files would be overwritten by merge:
init.el
Please, commit your changes or stash them before you can merge.
在網上搜索了下, 發現下面的步驟可以把問題解決掉, 雖然我不知道爲什麼:
git checkout HEAD init.el
git pull
 

Algorithms --reading notes

1. 先记录一句盖茨的话:

Only through focus can you do world-class things, no matter how capable you are.

2. 

Push code to a remote server

1. 如果之前已经有了一个original source, 应该先git remote rm origin

2. set up the remote repository:

 mkdir my_project.git

cd my_project.git
git init --bare
git update-server-info # If planning to serve via HTTP

3. on local machine:

cd my_project

git init
git add *
git commit -m "My initial commit message"
git remote add origin git@example.com:my_project.git
git push -u origin master

 

CakePHP -day01

阅读全文

Python notes

1. Backslash ( \ ) continues a line.  Semicolon ( ; ) joins two statements on a line. 

2. Python special underscore identifiers:

  a. _xxx Do not import with 'from module import *'

  b. __xxx__ System-defined name.

  c. __xxx Request private name mangling in classes.

3. Learn the use of lambda.

4. Variables defined within a function have local scope, and those at the highest level in a module have global scope.

5. How to specify a utf-8 file:

# -*- coding: UTF-8 -*-

Some Perl modules

以下是一些常用的Perl模块。 本篇文章先列出来哪些是自己常用的, 以及将会常用的。

1. FindBin;

2. Class::Date;

3. Config::Tiny;

4. Data::Dumper;

5. Getopt::Long;

6. LWP::Simple;

7. Path::Class;

8. Storable;

9 . URI::Escape;

10. File::Slurp;

11. SQL::Smart

暂时先列出这些modules。 等到有新的模块, 会补充到这篇blog中的。

 

 

Random notes on coding

1. 关于在css中使用control flow.

 #container{
            <% IF need_sample %>
            width: 800px;
            <% ELSE %>
            width: 500px;
            <% END %>
 }

2.  对于Perl里的DBI模块, 有以下的routine:

$dbh - DBI->connect();
die("Failed to connect to the DB\n") unless $dbh;
$query = "select ....";
$sth = $dbh->prepare($query);
$sth->execute();
while (my ($mid) = $sth->fetchrow_array()) {
  $cl{$mid}++;
}
$sth->finish();

 

vim 中移动到特定的tab

gt            go to next tab
gT            go to previous tab
{i}gt         go to tab in position i

MongoDB & Python

看Perl代码严重上自尊了。为了抚慰下受伤的心灵, 就来学习下Python & MongoDB. 

1. MongoDB does not support joins.

2. MongoDB does not support transactions. It does have some support for atomicoperations, however.

3. MongoDB schemas are flexible. Not all documents in a collection must adhere to the same schema.

4.  MongoDB is a document-oriented database.

5. The comparison between mongodb and the usual sql.

暂时先写到这里,现在回去继续看Perl还有Dancer。