Coding Diary II

总结 spimbot mp:

1. 不仅register s0-s7可以存入stack,t0-t9也可以存入stack,并在新的function区域内自由使用而不会产生和function外部的register冲突的问题。

2. (k==i)&&(l==j) can be implemented as:

xor $t0, $s4, $s0   #k==i?

xor $t1, $t8, $s1   #l==j?

or $t0, $t0, $t1   # k==i && l==j

beq $t0, 0, r2_loop5_next

3. 当code检查了很多遍都觉得没问题时,也要检查test case有没有错。

4. For mp7: 有些时候尝试逆向思维也不错(boolean 反过来)。

Posted in OC, TechCruSH | Comments Off

Coding Diary I

总结mp5,mp6:

1. 切勿偷懒,即使偷懒复制相同功能的代码,也要通读,把不一样的地方改完 (mp5)

2. Pass by reference 比直接pass by object快很多,在helper function中用,否则object太大,     运行时会take forever。 但是也不是所有情况都用,否则会影响const correctness

3. 总有些细小的地方让我们痛苦不堪 (mp6)

Posted in OC, TechCruSH | Comments Off

《在路上》系列相册集

这次密歇根之旅途中,我百无聊赖的玩着相机,一下下在大太阳底下,用1/250的快门摇拍,同行的室友问我在干吗,我说我要拍下这一路上所有黄颜色的路标。本来就是说着玩的,我的耐心又短暂得令人惋惜,回到家我发现这是个不错的主意,就此决定成立《在路上》这个庸俗名字的相册,用来放载关于在路上的照片。http://minus.com/m6ebAMa2B/

Posted in Uncategorized | Comments Off

gcc cross-compiler

自己电脑上试着编译mips的gcc cross compiler,好烦,一直没成功,编译binutils的时候就貌似出了问题,等到编译gcc的时候就更不对了。。。说缺少东西。好麻烦,先放一阵。看看有没有现成的包,自己编译有点麻烦阿。

You’re adverse to using someone else’s toolchains, and cannot remember how to build one yourself, no matter how hard you try. Fear not. Outlined here is the proceedure to build a bootstrap toolchain; one which is minus the C library and is just enough to build the kernel.

Prologue

What you’ll need:

Note that in general you want to use the latest versions released by the time a kernel was released. The versions listed here are known to be working well for recent kernels as of the time of writing. Using tools more recent than the kernel means that combination will not have been tested exhaustively so the likelihood of encountering incompatibilities increases. Sometimes tool compatibility versions are fixed in -stable but there is no guarantee that this also covers your favourite esoteric configuration.

Now, export a few environment variables for your convenience. If you’re building for big-endian MIPS, your TARGET should be mips-unknown-linux-gnu instead. If you wish to install to a different location other than /opt/cross/, substitute in your PREFIX accordingly. A common alternative is /usr/local/.

% export WDIR=/tmp
% export TARGET=mipsel-unknown-linux-gnu
% export PREFIX=/opt/cross

You’ll need to re-export your PATH with the new install location so when building a bootstrap gcc, it may locate the shiny new cross-binutils:

% export PATH="${PATH}":${PREFIX}/bin

Now change to the staging directory:

% cd $WDIR
% mkdir ${TARGET}-toolchain  && cd ${TARGET}-toolchain

Binutils

Extract, configure, build and install:

% tar xjf binutils-2.16.1.tar.bz2
% mkdir build-binutils && cd build-binutils
% ../binutils-2.16.1/configure --target=$TARGET --prefix=$PREFIX
% make
% make install
% cd ..

You should now have the cross-binutils installed under ${PREFIX}/bin/ with names prefixed by mipsel-unknown-linux-gnu-* (or mips-unknown-linux-gnu-* if you’re building for big-endian MIPS).

GCC

Extract, configure, build and install a bootstrap GCC.

Enable any other language front-ends as you see fit. For building the kernel however, you can get away with just the C language front-end. Also, tell the configure script not to look for target libc headers — we don’t have them, and don’t need them at this point.

% tar xjf gcc-3.4.4.tar.bz2
% mkdir build-gcc-bootstrap && cd build-gcc-bootstrap
% ../gcc-3.4.4/configure --target=$TARGET --prefix=$PREFIX \
  --enable-languages=c --without-headers \
  --with-gnu-ld --with-gnu-as \
  --disable-shared --disable-threads
% make -j2
% make install
% cd ..

GDB

You’ll need this for debugging either the kernel (with KGDB) or userspace (natively or with gdbserver). If this doesn’t apply in your case, you may safely skip this section.

Extract, configure, build and install:

% tar xjf gdb-6.3.tar.bz2
% mkdir build-gdb && cd build-gdb
% ../gdb-6.3/configure --target=$TARGET --prefix=$PREFIX
% make
% make install
% cd ..

Summary

Your shiny new toolchain should be in your PATH, given you re-exported it earlier. Otherwise, you’ll need to prefix your PATH with:

% ${PREFIX}/bin/mipsel-unknown-linux-gnu-

or for a big-endian target:

% ${PREFIX}/bin/mips-unknown-linux-gnu-

Enjoy.

 

 

 

Posted in TechCruSH | Comments Off

Linux(Ubuntu) 上Objective-C环境的设置

linux上编译objective-c之初体验:

1. 安装GNUstep相关package:

sudo apt-get install gobjc gnustep gnustep-make gnustep-common libgnustep-base-dev gnustep-devel

2. 将以下代码添加进 .bashrc文件( .bashrc 应该在/home/YOUR_PC_NAME/.bashrc)

#GNUSTEP Environment vars

. /usr/share/GNUstep/Makefiles/GNUstep.sh

(第二行 . 和 /usr/share/GNUstep/Makefiles/GNUstep.sh 之间有一个空格)

3. 写一个简单的Hello world:

#import <stdio.h>

int main( int argc, const char *argv[] ){

NSString* myString = [NSString string];

myString = “Hello world!”;

printf(“%s\n”, myString);

return 0;

}

4. 编写Makefile,用gcc的去编译的话好像后面要打一长串东西,所以不及Makefile简单。

新建GNUmakefile,并输入

GNUSTEP_MAKEFILES=/usr/share/GNUstep/Makefilesinclude $(GNUSTEP_MAKEFILES)/common.make
APP_NAME = Hello_OBJC_FILES =hello.m
include $(GNUSTEP_MAKEFILES)/application.make

5. make

报错:

有一次make另一个程序的时候出现 Can‘t Find Foundation/NSObject.h。后来发现是package没用安装完全。

 

Posted in TechCruSH | Comments Off

“One day I will shoot you with this bullet. Can you still say that you love me?”

今天lab1的grade放了出来,grade.txt里引用了这样一句话,”One day I will shoot you with this bullet. Can you still say that you love me?” from Re-l Mayer,查了下是来自于一部叫Ergo Proxy的日本动漫。在VIM黑白背景和字体的掩盖下,我想到我在不久之前就应该听过这段话:

“君が明日 蛇となり

人を喰らい 始めるとして

人を喰らった その口で

仆を爱すと 吼えたとして

仆は果たして 今日と同じように

君を爱すと 言えるだろうか

你明日为蛇   开始噬人   用你噬人之口   声声嘶吼着说爱我   我是否还能同今日一样   对你说“爱你”呢” by 市丸银

Posted in OC | Comments Off

Vimrc personalizing

昨天换了块混合硬盘,事实上性能似乎没用任何提升,只有重装了系统之后的那种快感,没用ssd的快感,重新装了win7和绝版的ubuntu 10.10,幸好之前拿一个u盘做了启动盘并再也没去动它。不想用10.10之后的版本,因为那些的界面就和学校的里linux不一样。配置VIM的时候才发现自己之前用的vim配置是多么的方便:支持所有格式的自动缩进,好像不包括php的缩进,这点不想去研究了;支持多行注释;行号神马的。要我自己重新配置一遍就不会了,也不知道之前是在哪里配置这个vimrc。。在此备份。This is not my originals. Copyright to Bram Moolenaar <Bram@vim.org>

” An example for a vimrc file.

” Maintainer: Bram Moolenaar <Bram@vim.org>
” Last change: 2008 Dec 17

” To use it, copy it to
”     for Unix and OS/2:  ~/.vimrc
”      for Amiga:  s:.vimrc
”  for MS-DOS and Win32:  $VIM\_vimrc
”    for OpenVMS:  sys$login:.vimrc

” When started as “evim”, evim.vim will already have done these settings.
if v:progname =~? “evim”
finish
endif

” Use Vim settings, rather than Vi settings (much better!).
” This must be first, because it changes other options as a side effect.
set nocompatible

” allow backspacing over everything in insert mode
set backspace=indent,eol,start

if has(“vms”)
set nobackup ” do not keep a backup file, use versions instead
else
set backup ” keep a backup file
endif
set history=50 ” keep 50 lines of command line history
set ruler ” show the cursor position all the time
set showcmd ” display incomplete commands
set incsearch ” do incremental searching

” For Win32 GUI: remove ‘t’ flag from ‘guioptions’: no tearoff menu entries
” let &guioptions = substitute(&guioptions, “t”, “”, “g”)

” Don’t use Ex mode, use Q for formatting
map Q gq

” CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
” so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>

” In many terminal emulators the mouse works just fine, thus enable it.
if has(‘mouse’)
set mouse=a
endif

” Switch syntax highlighting on, when the terminal has colors
” Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has(“gui_running”)
syntax on
set hlsearch
endif

” Only do this part when compiled with support for autocommands.
if has(“autocmd”)

” Enable file type detection.
” Use the default filetype settings, so that mail gets ‘tw’ set to 72,
” ‘cindent’ is on in C files, etc.
” Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on

” Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!

” For all text files set ‘textwidth’ to 78 characters.
autocmd FileType text setlocal textwidth=78

” When editing a file, always jump to the last known cursor position.
” Don’t do it when the position is invalid or when inside an event handler
” (happens when dropping a file on gvim).
” Also don’t do it when the mark is in the first line, that is the default
” position when opening a file.
autocmd BufReadPost *
\ if line(“‘\”") > 1 && line(“‘\”") <= line(“$”) |
\   exe “normal! g`\”" |
\ endif

augroup END

else

set autoindent ” always set autoindenting on

endif ” has(“autocmd”)

” Convenient command to see the difference between the current buffer and the
” file it was loaded from, thus the changes you made.
” Only define it when not defined already.
if !exists(“:DiffOrig”)
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
endif

colorscheme evening “or murphy is good too~
set confirm

Posted in Uncategorized | 17 Comments

主机迁移,内容丢失

前一个月考试实在过于频繁,没有去看主机商的免费空间公告,事实上,主机商说服务器10月14号就迁移了,要用户们重新调整域名的定向,我昨天才发现,crazy-bubble.com登不上去,还以为是临时性的问题。。。可是这迁移之后的半个月内我还写过一些东西,可是昨天我重新做好A记录定向之后,我发现14号之后做的修改全部丢失了。。。郁闷,看来备份确实很重要,用phpmyadmin?

Posted in Wordpress | 6 Comments

泡茶2分28秒

事实上,右手边摆着的这杯茶,是我前天夜里熬夜赶231作业和复习物理的时候泡的。可是这个时间点的具体性很模糊,我隐隐以为这事情发生在昨天晚上。熬夜会扭曲时间,会让人产生错觉,比如我前天熬夜到5点左右去眯了个3,4个小时的,这3,4个小时给我一种好像睡了一整夜的错觉。“时间被扭曲了。”这个论断又一次被证实是在我睡觉前,跑去厨房泡一杯铁观音,这个廉价的水壶煮开水总是很慢,我打算掐表看一下它到底慢到什么程度,于是我开了开关,回到房间拿手表,路过洗手间去撒了泡尿,然后到厨房开始计时

。。。。2分28秒。。。。

水开了。我看着水从平静,到开始长豆豆,到豆豆开始骚动,到豆豆变成大豆豆,这是多么一个漫长的过程啊,可是也只有区区的2分28秒。

这2分28秒,属于深夜的4点43分。喝完半杯,我就撑不下去了,倒到床上,睡觉。

 

Posted in OC | 6 Comments