Feng erdong's Blog

Life is beautiful

Ubuntu Configuration

| Comments

apt-get

  • Setup proxy for apt-get
1
sudo gedit /etc/apt/apt.conf #This is a new file

add Acquire::http::Proxy "http://username:password@proxyhost:port/" to this file

Gnome desktop

  • Create application shortcut
1
2
  sudo apt-get install --no-install-recommends gnome-panel
  gnome-desktop-item-edit ~/Desktop/ --create-new

Setup ftp server

  • Install vsftpd sudo apt-get install vsftpd

  • Edit /etc/vsftpd.conf

    • anonymous_enable
    • write_enable
    • ftpd_banner
  • Save the file and restart ftp service by sudo /etc/init.d/vsftpd restart

  • Copy files you want to shared to folder /srv/ftp

jQuery Change Element Type

| Comments

By default, jQuery does not allow modify the type of a element, if you do so, a error will occur: Error: type property can't be changed

1
$(':text:visible').attr('type', 'password');

But if when the target element is detached from DOM tree, then the type can be changed, so we can use jQuery to change the type in this way(we need create a new element to mark the position of the target element):

1
2
3
var $marker = $('<span />').insertBefore(':text:visible');
$(':text:visible').detach().attr('type', 'password').insertAfter($marker).focus();
$marker.remove();

Do you think you’ve get the final answer? No ! Dom element supports modify type directly, so the simplest way should be:

1
$(':text:visible')[0].type="password"

Recoding and Playing in VIM

| Comments

  • Start recording by pressing q, followed by a lower case character to name the macro
  • Perform any typical editing, actions inside Vim editor, which will be recorded
  • Stop recording by pressing q
  • Play the recorded macro by pressing @ followed by the macro name
  • To repeat macros multiple times, press : NN @ macro name. NN is a number

.bash_profile vs .bashrc

| Comments

  • /bin/bash
    The bash executable
  • /etc/profile
    The systemwide initialization file, executed for login shells
  • ~/.bash_profile
    The personal initialization file, executed for login shells(type username and password first, e.g. ssh)
  • ~/.bashrc
    The individual per-interactive-shell startup file(executed for non-login shells)
  • ~/.bash_logout
    The individual login shell cleanup file, executed when a login shell exits
  • ~/.inputrc
    Individual readline initialization file

Linux 命令之Sort

| Comments

Sort

  • -u unique
  • -f ignore case
    fold lower case to upper case characters
  • -b –ignore-leading-blanks
    ignore leading blanks
  • -n –numeric-sort
    compare according to string numerical value
  • -t –field-separator=SEP
    use SEP instead of non-blank to blank transition
  • -k –key=POS1[,POS2]
    start a key at POS1, end it at POS2 (origin 1)

-t -k 经常配合使用

1
2
3
4
5
$ cat fruit.txt
banana:30:5.5
apple:10:2.5
pear:90:2.3
orange:20:3.4
1
2
3
4
5
$ sort -n -k 2 -t : fruit.txt
apple:10:2.5
orange:20:3.4
banana:30:5.5
pear:90:2.3
  • -r –reverse
    reverse the result of comparisons

查看Jar包内容

| Comments

已经有快一年没有写过Java代码了,这段时间看Gradle, 发现Java社区还是发展挺快的( 亦或是我已经out很久了 ^_^ ), 以前的打包工作都是Ant或是Maven来完成的,如果接触过Django或是Rails的人看到Ant跟Maven里的那一大堆配置,一定都快吐了,现在好了,基于Groovy的Gradle的代码让这一切变得不再那么麻烦,只需使用gradle build就可以生成jar包了.

不知道什么原因,我在使用生成的jar文件时总是提示类找不到,感觉应该是生成的jar文件有问题,Google了查看jar文件内容的命令, 在这里分享一下:

1
jar tvf filename.jar
Option Description
t Lists the table of contents from jarfile
v Generates verbose output to standard output
f Specifies the file jarfile

CSS之table-layout

| Comments

项目中有好几个页面都用到一个Table, 这个Table中有很多列,而且列数是可变化的,我们通过Javascript来动态计算出列的宽度(total_width/column_count), 但是有时候仍会出现列的宽度不一致的情况, 在W3C school了解了一下,原来有table-layout这个CSS属性:

table-layout有两个值可以设置(见下表)

value isDefault algorithm
auto YES 浏览器在已给定的表格/列/单元格的宽度的基础上,自己重新计算出一个最适合的宽度
fixed NO 禁止浏览器的重新计算行为,按用户给定的宽度显示,可能会出现单元格内容显示不完整的情况
1
2
3
4
#performance_table {
    ...
    table-layout: fixed;
}

加上这个属性之后就OK了.

Border 属性在IE下的奇怪表现

| Comments

今天在调前端的时候遇到一个问题,有一个TABLE中的TR在IE下总是多显示一条很粗的底边框出来, 查看CSS时看到边框的样式是由下面的代码来控制的,似乎是为了强制在IE下显示solid的边框而非虚线.

1
2
3
4
5
6
table {
    td, th {
        // IE's dotted lines look bad
        border-style: solid !important;
    }
}

由于打算修改这段CSS让其不显示下边框,

1
2
3
4
5
6
7
table {
    td, th {
        // IE's dotted lines look bad
        border-style: solid !important;
        border-bottom: none !important;
    }
}

刷新页面后还是没有起作用,Google后发现原来在IE下面对 border-bottom 这种简写形式支持的不好,需要拆分成完整形式,

1
2
3
4
5
6
7
8
table {
    td, th {
        // IE's dotted lines look bad
        border-style: solid !important;
        border-bottom-style: none !important;
        border-bottom-width: 0px;
    }
}

午饭后又去W3C看了一下CSS border相关的reference, 得出 border 由三个属性组成:

  • width
  • style
  • color

我们可以通过border一次性指定width, style, color, 也可以通过

  • border-width
  • border-style
  • border-color

来分别指定属性.

See more HERE

obj.length === +obj.length in Javascript

| Comments

晚上看Underscore.js源码的时候,看到这样的一种写法:

obj.lenght === +obj.length in underscore.jsSource
1
else if (obj.length === +obj.length)

在SO上搜索后得知原来这种写法原来跟if (typeof obj.length == 'number')是等价的,之所以要写成上面的那种形式的原因是前者比后者要节省5个字节的空间。。。

为单个文件添加Django支持

| Comments

1
2
3
import os
#using your own django project settings module name(not file name)
os.environ['DJANGO_SETTINGS_MODULE'] = "datawinners.settings"
必须先完成`DJANGO_SETTINGS_MODULE`的配置,然后再使用Django提供的功能。

在配置DJANGO_SETTINGS_MODULE之前,需要先配置PYTHONPATH, Django在执行的时候会从PYTHONPATH中去查找DJANGO_SETTINGS_MODULE指定的模块。PYTHONPATH跟Java的CLASSPATH作用上是一样的.

1
export PYTHONPATH="/home/twer/workspace/datawinners/datawinners"