我的HelloWorld

Posted by Kimziv at 2013-06-09 with tags hello world, first

Hello World

hello world.

Top

Linux下关闭多个进程

Posted by Kimziv at 2013-04-12 with tags Linux, shell

很多时候,需要同时关闭一系列的有着相同的关键字的进程,比如说,开着十多个网页的chrome死掉了这种情况。。

在Linux下面,敲几个命令就OK了,以下每行都可以,有些区别

ps -e | grep chorme | cut -c 1-5 | xargs kill -9
ps -e | awk '$4=="chrome" {print $1}' | xargs kill -9ps

ps -e的输出如下

12040 ?        00:00:00 kworker/1:1
12041 ?        00:00:00 kworker/0:0
12052 ?        00:00:09 chrome
12119 ?        00:00:00 kworker/3:0

这个命令输出了当前的所有进程信息,最前面的就是进程的pid。第四列是进程的名称

grep chrome就是查找含有chrome的行并输出。cut -c 1-5意思是对输入的每一行取第1到5个字符(恰好是进程的pid)输出。两个命令合起来,就是输出进程名含有chrome的进程的pid。

awk '$4=="chrome" {print $1}'做了同样的事,不过这个命令输出的是进程名恰好是chrome的进程的pid,而不仅仅是包含。

xargs kill -9这个命令,输入以换行或者空白分割之后,作为参数执行一遍或者多遍后面跟随的命令

最后感叹一下,shell很强大!

Top

编译Linux内核

Posted by Kimziv at 2012-07-14 with tags Linux, 内核, 编译源码

这几天实验室交给任务,编译linux内核。然后就开始做了。

师兄给了两篇参考文章,这篇这篇。第一篇比较简略,说了总体的过程,而第二篇比较而言就比较详细了。

好了,现在说说自己的编译的过程吧。

一、下载源码并解压

源码从这里下载,我下载的是最新的3.5-rc6。具体那个版本都是差不多的。然后需要把源码解压到/usr/src这个目录下,我是ubuntu用户,其他发行版相似

sudo cp /path/to/file/linux-3.5-rc6.tar.bz2 /usr/src
sudo tar jxvf linux-3.5-rc6
cd linux-3.5-rc6/  # 进入源码的目录,以后所有操作均在该目录下完成

二、删除之前编译的残留文件

sudo make mrproper

如果是第一次编译的话,可以不用执行这一步。而如果之前曾经编译过,务必执行这一步,清除残留文件,否则可能会导致编译失败。

三、配置编译选项

sudo make config
sudo make menuconfig
sudo make xconfig

这三个命令任选一个执行就好了。区别是

  • make config
    问答式的配置,选错之后无法更改,所以一般人都不会用这个。

  • make menuconfig
    这个命令需要ncurses库的支持,ncurses是字符界面下的图形界面库。可以通过apt-get install libncurses5-dev来安装。ncurses是字符界面下的图形界面库,所以如果使用的字符控制台,就可以用选用menuconfig了

  • make xconfig
    这个命令需要Qt,这是个跨平台的图形界面库。可以通过sudo apt-get install libqt...来安装,具体是那个包忘记了。xconfig就是图形界面下的配置环境了。

xconfig用着最舒服,menugconfig也可以,不过界面难看了些。config自己没用过,也不推荐用。

这一步其实应该是很重要的一步,不过由于选项众多,且众多选项和硬件相关,需要有足够的硬件知识,并且对自己电脑的硬件配置有足够的了解才可能完全配置的好。网上有许多专门讲这一步的文章,比如金步国的这篇经典文章,不过由于版本还是2.6,所以有许多选项文章里面没有讲到。

由于本人是个菜鸟,对于硬件以及其他的知识都不是很清楚,再加上这么多的选项,所以大部分都是默认的选项。当然,这样就使得modules过多,使得之后的make modules的时候花费了大量的时间。所以应该尽量的减少不需要的模块,特便是其中的许多针对不同的硬件的驱动。

四、编译内核

sudo make bzImage

在我参考的第二篇文章中说,他编译出来的内核大约在800k-900k左右,可是实际上我编译出来的内核一般在4500k左右。可能是由于版本的差异吧,不用纠结在这个上面。

在编译结束后,会告诉你bzImage的位置,然后执行

sudo cp /path/to/bzImage /boot/vmlinuz-3.5-rc6

把其放到/boot目录下。这里我把它重命名为vmlinuz-3.5-rc6?为什么是这个名字?自己看看/boot,更深层原因我也不知道了。

五、编译模块

sudo make modules

上边也说了,这个阶段的时间是和配置选项那一步中选择的模块的多少直接相关的。有时可能会遇到rts5139.ko undefined的错误,可以在配置选项时去掉rts5139这个模块。

六、安装模块

sudo make modules_install

这一步没什么说的。有时可能会出错,并让你make CONFIG_MISMATCH=y(这个选项记不清了,不过差不多了),可以不用理。

七、安装内核

sudo make install

这一步比较快。在这一步,系统会自动更新grub。

如果以上完全弄好了,那么就可以重启进入新的内核体验了。不过有的同学在重启后可能会遇到这样一个问题,就是无法进入图形界面了。 提示类似如"ubuntu run in a low-graphic mode","Your screen, graphic card, input devices cannot detected correctly. You need configure it yourself."等等。 这时可以Ctrl-Alt-F1或者Alt-F1进入控制台,sudo apt-get install gdm之后选择gdm即可。如果还不能解决问题,对于ATI显卡,可以安装fglrx。由于我不是ATI的显卡,所以是否可行我就不是很清楚了。更具体的可以google之。

Top

Jekyll Introduction

Posted by Kimziv at 2011-12-29 with tags intro, beginner, jekyll, tutorial

This Jekyll introduction will outline specifically what Jekyll is and why you would want to use it. Directly following the intro we'll learn exactly how Jekyll does what it does.

Overview

What is Jekyll?

Jekyll is a parsing engine bundled as a ruby gem used to build static websites from dynamic components such as templates, partials, liquid code, markdown, etc. Jekyll is known as "a simple, blog aware, static site generator".

Examples

This website is created with Jekyll. Other Jekyll websites.

What does Jekyll Do?

Jekyll is a ruby gem you install on your local system. Once there you can call jekyll --server on a directory and provided that directory is setup in a way jekyll expects, it will do magic stuff like parse markdown/textile files, compute categories, tags, permalinks, and construct your pages from layout templates and partials.

Once parsed, Jekyll stores the result in a self-contained static _site folder. The intention here is that you can serve all contents in this folder statically from a plain static web-server.

You can think of Jekyll as a normalish dynamic blog but rather than parsing content, templates, and tags on each request, Jekyll does this once beforehand and caches the entire website in a folder for serving statically.

Jekyll is Not Blogging Software

Jekyll is a parsing engine.

Jekyll does not come with any content nor does it have any templates or design elements. This is a common source of confusion when getting started. Jekyll does not come with anything you actually use or see on your website - you have to make it.

Why Should I Care?

Jekyll is very minimalistic and very efficient. The most important thing to realize about Jekyll is that it creates a static representation of your website requiring only a static web-server. Traditional dynamic blogs like Wordpress require a database and server-side code. Heavily trafficked dynamic blogs must employ a caching layer that ultimately performs the same job Jekyll sets out to do; serve static content.

Therefore if you like to keep things simple and you prefer the command-line over an admin panel UI then give Jekyll a try.

Developers like Jekyll because we can write content like we write code:

  • Ability to write content in markdown or textile in your favorite text-editor.
  • Ability to write and preview your content via localhost.
  • No internet connection required.
  • Ability to publish via git.
  • Ability to host your blog on a static web-server.
  • Ability to host freely on GitHub Pages.
  • No database required.

How Jekyll Works

The following is a complete but concise outline of exactly how Jekyll works.

Be aware that core concepts are introduced in rapid succession without code examples. This information is not intended to specifically teach you how to do anything, rather it is intended to give you the full picture relative to what is going on in Jekyll-world.

Learning these core concepts should help you avoid common frustrations and ultimately help you better understand the code examples contained throughout Jekyll-Bootstrap.

Initial Setup

After installing jekyll you'll need to format your website directory in a way jekyll expects. Jekyll-bootstrap conveniently provides the base directory format.

The Jekyll Application Base Format

Jekyll expects your website directory to be laid out like so:

.
|-- _config.yml
|-- _includes
|-- _layouts
|   |-- default.html
|   |-- post.html
|-- _posts
|   |-- 2011-10-25-open-source-is-good.markdown
|   |-- 2011-04-26-hello-world.markdown
|-- _site
|-- index.html
|-- assets
    |-- css
        |-- style.css
    |-- javascripts
  • _config.yml
    Stores configuration data.

  • _includes
    This folder is for partial views.

  • _layouts
    This folder is for the main templates your content will be inserted into. You can have different layouts for different pages or page sections.

  • _posts
    This folder contains your dynamic content/posts. the naming format is required to be @YEAR-MONTH-DATE-title.MARKUP@.

  • _site
    This is where the generated site will be placed once Jekyll is done transforming it.

  • assets
    This folder is not part of the standard jekyll structure. The assets folder represents any generic folder you happen to create in your root directory. Directories and files not properly formatted for jekyll will be left untouched for you to serve normally.

(read more: https://github.com/mojombo/jekyll/wiki/Usage)

Jekyll Configuration

Jekyll supports various configuration options that are fully outlined here: https://github.com/mojombo/jekyll/wiki/Configuration

Content in Jekyll

Content in Jekyll is either a post or a page. These content "objects" get inserted into one or more templates to build the final output for its respective static-page.

Posts and Pages

Both posts and pages should be written in markdown, textile, or HTML and may also contain Liquid templating syntax. Both posts and pages can have meta-data assigned on a per-page basis such as title, url path, as well as arbitrary custom meta-data.

Working With Posts

Creating a Post
Posts are created by properly formatting a file and placing it the _posts folder.

Formatting
A post must have a valid filename in the form YEAR-MONTH-DATE-title.MARKUP and be placed in the _posts directory. If the data format is invalid Jekyll will not recognize the file as a post. The date and title are automatically parsed from the filename of the post file. Additionally, each file must have YAML Front-Matter prepended to its content. YAML Front-Matter is a valid YAML syntax specifying meta-data for the given file.

Order
Ordering is an important part of Jekyll but it is hard to specify a custom ordering strategy. Only reverse chronological and chronological ordering is supported in Jekyll.

Since the date is hard-coded into the filename format, to change the order, you must change the dates in the filenames.

Tags
Posts can have tags associated with them as part of their meta-data. Tags may be placed on posts by providing them in the post's YAML front matter. You have access to the post-specific tags in the templates. These tags also get added to the sitewide collection.

Categories
Posts may be categorized by providing one or more categories in the YAML front matter. Categories offer more significance over tags in that they can be reflected in the URL path to the given post. Note categories in Jekyll work in a specific way. If you define more than one category you are defining a category hierarchy "set". Example:

---
title :  Hello World
categories : [lessons, beginner]
---

This defines the category hierarchy "lessons/beginner". Note this is one category node in Jekyll. You won't find "lessons" and "beginner" as two separate categories unless you define them elsewhere as singular categories.

Working With Pages

Creating a Page
Pages are created by properly formatting a file and placing it anywhere in the root directory or subdirectories that do not start with an underscore.

Formatting
In order to register as a Jekyll page the file must contain YAML Front-Matter. Registering a page means 1) that Jekyll will process the page and 2) that the page object will be available in the site.pages array for inclusion into your templates.

Categories and Tags
Pages do not compute categories nor tags so defining them will have no effect.

Sub-Directories
If pages are defined in sub-directories, the path to the page will be reflected in the url. Example:

.
|-- people
    |-- bob
        |-- essay.html

This page will be available at http://yourdomain.com/people/bob/essay.html

Recommended Pages

  • index.html
    You will always want to define the root index.html page as this will display on your root URL.
  • 404.html
    Create a root 404.html page and GitHub Pages will serve it as your 404 response.
  • sitemap.html
    Generating a sitemap is good practice for SEO.
  • about.html
    A nice about page is easy to do and gives the human perspective to your website.

Templates in Jekyll

Templates are used to contain a page's or post's content. All templates have access to a global site object variable: site as well as a page object variable: page. The site variable holds all accessible content and metadata relative to the site. The page variable holds accessible data for the given page or post being rendered at that point.

Create a Template
Templates are created by properly formatting a file and placing it in the _layouts directory.

Formatting
Templates should be coded in HTML and contain YAML Front Matter. All templates can contain Liquid code to work with your site's data.

Rending Page/Post Content in a Template
There is a special variable in all templates named : content. The content variable holds the page/post content including any sub-template content previously defined. Render the content variable wherever you want your main content to be injected into your template:

...
<body>
  <div id="sidebar"> ... </div>
  <div id="main">

&#123;{content}&#125;

</div> </body> ...

Sub-Templates

Sub-templates are exactly templates with the only difference being they define another "root" layout/template within their YAML Front Matter. This essentially means a template will render inside of another template.

Includes

In Jekyll you can define include files by placing them in the _includes folder. Includes are NOT templates, rather they are just code snippets that get included into templates. In this way, you can treat the code inside includes as if it was native to the parent template.

Any valid template code may be used in includes.

Using Liquid for Templating

Templating is perhaps the most confusing and frustrating part of Jekyll. This is mainly due to the fact that Jekyll templates must use the Liquid Templating Language.

What is Liquid?

Liquid is a secure templating language developed by Shopify. Liquid is designed for end-users to be able to execute logic within template files without imposing any security risk on the hosting server.

Jekyll uses Liquid to generate the post content within the final page layout structure and as the primary interface for working with your site and post/page data.

Why Do We Have to Use Liquid?

GitHub uses Jekyll to power GitHub Pages. GitHub cannot afford to run arbitrary code on their servers so they lock developers down via Liquid.

Liquid is Not Programmer-Friendly.

The short story is liquid is not real code and its not intended to execute real code. The point being you can't do jackshit in liquid that hasn't been allowed explicitly by the implementation. What's more you can only access data-structures that have been explicitly passed to the template.

In Jekyll's case it is not possible to alter what is passed to Liquid without hacking the gem or running custom plugins. Both of which cannot be supported by GitHub Pages.

As a programmer - this is very frustrating.

But rather than look a gift horse in the mouth we are going to suck it up and view it as an opportunity to work around limitations and adopt client-side solutions when possible.

Aside
My personal stance is to not invest time trying to hack liquid. It's really unnecessary from a programmer's perspective. That is to say if you have the ability to run custom plugins (i.e. run arbitrary ruby code) you are better off sticking with ruby. Toward that end I've built Mustache-with-Jekyll

Static Assets

Static assets are any file in the root or non-underscored subfolders that are not pages. That is they have no valid YAML Front Matter and are thus not treated as Jekyll Pages.

Static assets should be used for images, css, and javascript files.

How Jekyll Parses Files

Remember Jekyll is a processing engine. There are two main types of parsing in Jekyll.

  • Content parsing.
    This is done with textile or markdown.
  • Template parsing.
    This is done with the liquid templating language.

And thus there are two main types of file formats needed for this parsing.

  • Post and Page files.
    All content in Jekyll is either a post or a page so valid posts and pages are parsed with markdown or textile.
  • Template files.
    These files go in _layouts folder and contain your blogs templates. They should be made in HTML with the help of Liquid syntax. Since include files are simply injected into templates they are essentially parsed as if they were native to the template.

Arbitrary files and folders.
Files that are not valid pages are treated as static content and pass through Jekyll untouched and reside on your blog in the exact structure and format they originally existed in.

Formatting Files for Parsing.

We've outlined the need for valid formatting using YAML Front Matter. Templates, posts, and pages all need to provide valid YAML Front Matter even if the Matter is empty. This is the only way Jekyll knows you want the file processed.

YAML Front Matter must be prepended to the top of template/post/page files:

---
layout: post
category : pages
tags : [how-to, jekyll]
---

... contents ...

Three hyphens on a new line start the Front-Matter block and three hyphens on a new line end the block. The data inside the block must be valid YAML.

Configuration parameters for YAML Front-Matter is outlined here: A comprehensive explanation of YAML Front Matter

Defining Layouts for Posts and Templates Parsing.

The layout parameter in the YAML Front Matter defines the template file for which the given post or template should be injected into. If a template file specifies its own layout, it is effectively being used as a sub-template. That is to say loading a post file into a template file that refers to another template file with work in the way you'd expect; as a nested sub-template.

How Jekyll Generates the Final Static Files.

Ultimately, Jekyll's job is to generate a static representation of your website. The following is an outline of how that's done:

  1. Jekyll collects data.
    Jekyll scans the posts directory and collects all posts files as post objects. It then scans the layout assets and collects those and finally scans other directories in search of pages.

  2. Jekyll computes data.
    Jekyll takes these objects, computes metadata (permalinks, tags, categories, titles, dates) from them and constructs one big site object that holds all the posts, pages, layouts, and respective metadata. At this stage your site is one big computed ruby object.

  3. Jekyll liquifies posts and templates.
    Next jekyll loops through each post file and converts (through markdown or textile) and liquifies the post inside of its respective layout(s). Once the post is parsed and liquified inside the the proper layout structure, the layout itself is "liquified".
    Liquification is defined as follows: Jekyll initiates a Liquid template, and passes a simpler hash representation of the ruby site object as well as a simpler hash representation of the ruby post object. These simplified data structures are what you have access to in the templates.

  4. Jekyll generates output.
    Finally the liquid templates are "rendered", thereby processing any liquid syntax provided in the templates and saving the final, static representation of the file.

Notes.
Because Jekyll computes the entire site in one fell swoop, each template is given access to a global site hash that contains useful data. It is this data that you'll iterate through and format using the Liquid tags and filters in order to render it onto a given page.

Remember, in Jekyll you are an end-user. Your API has only two components:

  1. The manner in which you setup your directory.
  2. The liquid syntax and variables passed into the liquid templates.

All the data objects available to you in the templates via Liquid are outlined in the API Section of Jekyll-Bootstrap. You can also read the original documentation here: https://github.com/mojombo/jekyll/wiki/Template-Data

Conclusion

I hope this paints a clearer picture of what Jekyll is doing and why it works the way it does. As noted, our main programming constraint is the fact that our API is limited to what is accessible via Liquid and Liquid only.

Jekyll-bootstrap is intended to provide helper methods and strategies aimed at making it more intuitive and easier to work with Jekyll =)

Thank you for reading this far.

Next Steps

Please take a look at or jump right into Usage if you'd like.

Top