About neohope

一直在努力,还没想过要放弃...

MBP加装SSD

端午期间,自己无聊,MBP的硬盘又不够用了,于是就开始了MBP的升级之旅。

目标很简单:
1、两条2GB的DDR3内存换成一条8GB的DDR3内存;
2、将光驱位的光驱,替换为光驱位硬盘支架+SSD,然后将操作系统切换到SSD上;

说做就做咯。
1、买好SSD、MBP光驱位硬盘支架、MBP移动光驱盒;
2、打开后盖,更换内存;
3、卸掉光驱(请参考淘宝上各种教程);
3、SSD放到光驱位硬盘支架,安装到光驱位,还原后盖;

然后,开始迁移系统~~
1、用MAC自带的备份还原功能,很快将MAC系统迁移好;
2、然后开始安装Win7,悲催了啊~~就:
a、尝试U盘安装Win7,根本无法识别;
b、PE的USB启动盘也无法识别;
c、用高版本MBP生成的Win7的USB启动盘也不行各种尝试;
d、但MAC启动盘就是能识别,最后U盘安装Win7失败;
3、用外置光驱盒装上MBP上的光驱,开始外置光驱安装Win7;
a、用Win7的盘,可以认到,但是点击从光盘启动,就不运行了;
b、用Win8的盘,结果同上;
c、各种尝试,各种挫啊;

最后,去搜索了一下,发现:
1、如果想从U盘安装Win7,需要新版本的MBP,我的是2011 Early,搞不定啊;
这个区分方法很简单,进入Mac系统,如果Bootcamp中,可以制作Windows安装盘,就是可以的咯;
2、如果想从光驱安装Win7,那外置光驱是搞不定的,只能用原装内置光驱,好搓~~;

于是将SSD安装到硬盘位,光驱还原,安装Win7,成功。

然后将SSD+光盘位硬盘支架安装到光盘位,硬盘恢复,光驱+光驱盒做外置光驱。

搞定!!!

好累哦。

后记:
成功忽悠了潘爷加装了一块1T的硬盘。
成功忽悠了朱姐加装了一块1T的硬盘,但有一颗螺丝拧花了,搞了好久,吐血。。。但还是成功啦:)

修改WordPress域名

比如,我需要把域名dm01.neohope.org换为dm02.neohope.org,需要进行以下操作:

1、如果需要,可以重命名wordpress文件夹

2、如果需要,修改wordpress的数据库设置

3、更新wordpress主配置

UPDATE wp_options SET option_value = replace( option_value, 'dm01.neohope.org', 'dm02.neohope.org' ) WHERE option_name = 'home' OR option_name = 'siteurl';  

4、更新posts

UPDATE wp_posts SET post_content = replace( post_content, 'dm01.neohope.org', 'dm02.neohope.org' ) ;  
UPDATE wp_posts SET guid = replace( guid, 'dm01.neohope.org', 'dm02.neohope.org' ) ;  

5、更新comments

UPDATE wp_comments SET comment_content = replace(comment_content, 'dm01.neohope.org', 'dm02.neohope.org') ;
UPDATE wp_comments SET comment_author_url = replace(comment_author_url, 'dm01.neohope.org', 'dm02.neohope.org')

6、搞定

修改WordPress数据库前缀

一般来说,为了数据安全,大家都很修改一下WordPress数据的前缀,而不是使用默认的wp_。
修改WordPress数据库前缀步骤如下:

1、备份数据库
2、打开wp-config.php文件,修改table_prefix变量

$table_prefix  = 'wp_a123456_';

3、使用phpMyAdmin修改数据库中的表名

RENAME table `wp_commentmeta` TO `wp_a123456_commentmeta`;
RENAME table `wp_comments` TO `wp_a123456_comments`;
RENAME table `wp_links` TO `wp_a123456_links`;
RENAME table `wp_options` TO `wp_a123456_options`;
RENAME table `wp_postmeta` TO `wp_a123456_postmeta`;
RENAME table `wp_posts` TO `wp_a123456_posts`;
RENAME table `wp_terms` TO `wp_a123456_terms`;
RENAME table `wp_term_relationships` TO `wp_a123456_term_relationships`;
RENAME table `wp_term_taxonomy` TO `wp_a123456_term_taxonomy`;
RENAME table `wp_usermeta` TO `wp_a123456_usermeta`;
RENAME table `wp_users` TO `wp_a123456_users`;

4、修改Options表

SELECT * FROM `wp_a123456_options` WHERE `option_name` LIKE '%wp_%'

将前缀全部修改掉。

5、修改UserMeta表

SELECT * FROM `wp_a123456_usermeta` WHERE `meta_key` LIKE '%wp_%'

将前缀全部修改掉。

6、现在应该正常工作了,记得再次备份哦。

7、数据库很小的话,可以全部导出,用vim修改后,再全部导入,会简单一些哦。

参考:
How to Change the WordPress Database Prefix to Improve Security

Windows下Emacs使用SBCL

今天配置Emacs时,发现Emacs无法使用SBCL,其默认为lisp。
会报下面的错误:

Searching for program: no such file or directory, lisp 

这个问题可以用一个变通的方法解决,在Emacs路径下建立下面的文件:
lisp.bat

@rem start sbcl
D:\CommonLisp\sbcl-1.1.17\sbcl.exe --core "D:\CommonLisp\sbcl-1.1.17\sbcl.core"

然后就可以使用啦。

还是linux下面简单一些,符号链接直接搞定:

ln -s /usr/bin/clisp /usr/bin/lisp

排序算法C Part01

1、冒泡排序

//冒泡排序BubbleSort
//每次扫描,比较和交换相邻元素,保证一次扫描后,最大元素在最后一个
//每次扫描后,扫描队列长度减一
//时间复杂度:O(N^2)
//空间复杂度:O(N)
//稳定性:稳定
//输入:要排序的数组,数组长度
//输出:void,Q[]将处于排序状态
void BubbleSort(int Q[], int N)
{
  int i;
  int swap=1;
  int Temp;
  
  while(swap>0)
    {
      swap=0;
      for(i=1;i<N;i++)
	{
	  if(Q[i-1]>Q[i])
	    {
	      swap++;
	      Temp=Q[i-1];
	      Q[i-1]=Q[i];
	      Q[i]=Temp;
	    }
	}
    }
}

2、选择排序

//选择排序SelectionSort
//从头扫描到尾,每次将最小元素放到第一个
//每次扫描后,队列长度减一
//时间复杂度:O(N^2)
//空间复杂度:O(N)
//稳定性:稳定
//输入:要排序的数组,数组长度
//输出:void,Q[]将处于排序状态
void SelectionSort(int Q[], int N)
{
  int i,j,k;
  int Temp;
  for(i=0;i<N;i++)
    {
      k=i;
      for(j=i+1;j<N;j++)
	{
	  if(Q[j]<Q[i])k=j;
	}  

      Temp=Q[k];
      Q[k]=Q[i];
      Q[i]=Temp;
    }
}

3、插入排序

//插入排序InsertionSort
//起始队列长度为1,每次队列长度加1
//通过元素移动,将队列调整为有序状态
//时间复杂度:O(N^2)
//空间复杂度:O(N)
//稳定性:稳定
//输入:要排序的数组,数组长度
//输出:void,Q[]将处于排序状态
void InsertionSort(int Q[], int N)
{
  int i,j;
  int Temp;
  for(i=1;i<N;i++)
    {
      Temp = Q[i];
      for(j=i;j>0 && Q[j-1]>Temp;j--)
	{
	  Q[j]=Q[j-1];
	}

      Q[j]=Temp;
    }
}

4、希尔排序

//希尔排序ShellSort
//指定一个步长,将需要排序的数字,按序号%步长分组
//对每组进行插入排序,然后减小步长,再次分组,排序直到步长为1结束
//时间复杂度:O(n^2)
//空间复杂度:O(n)
//稳定性:稳定
//输入:要排序的数组,数组长度
//输出:void,Q[]将处于排序状态
void ShellSort(int Q[], int N)
{
  int i,j;
  int Temp;
  int Step;

  for(Step=N/2;Step>0;Step=Step/2)
    {
      for(i=Step;i<N;i++)
	{
	  Temp = Q[i];
	  for(j=i;j>=Step && Q[j-Step]>Temp;j=j-Step)
	    {
	      Q[j]=Q[j-Step];
	    }
	  Q[j]=Temp;
	}
      //dumpArray(Q,N);
    }
}

5、归并排序

//归并排序MergeSort
//二路归并首先将归并长度定为2,在归并集内进行排序
//然后归并长度×2,将有序集合进行归并
//时间复杂度:O(NlogN)
//空间复杂度:O(N)
//稳定性:稳定
//输入:要排序的数组,数组长度
//输出:void,Q[]将处于排序状态
void Merge(int Q[],int TempArray[], int left, int mid, int right)
{
  int i=left,j=mid,k=left;

  while(i<mid && j<=right)
    {
      if(Q[i]>Q[j])
	{
	  TempArray[k++]=Q[j++];
	}
      else
	{
	  TempArray[k++]=Q[i++];
	}
    }

  while(i<mid)
    {
	  TempArray[k++]=Q[i++];
    }

  while(j<=right)
    {
      	  TempArray[k++]=Q[j++];
    }

  for(k=left;k<=right;k++)
    {
      Q[k]=TempArray[k];
    }

}

void MSort(int Q[],int TempArray[], int left, int right)
{
  int center;

  if(left<right)
    {
      center=(left+right)/2;
      MSort(Q,TempArray,left,center);
      MSort(Q,TempArray,center+1,right);
      Merge(Q,TempArray,left,center+1,right);
    }
}

void MergeSort(int Q[], int N)
{
  int *TempArray = malloc(N*sizeof(int));

  if(TempArray!=NULL)
    {
      MSort(Q,TempArray,0,N-1);
    }
  else
    {
      //Todo: deal with not enough memory
      //RaiseError("MergeSort: not enough memory");
    }
}

CommonLisp101(01)

1.hello.lsp

;;hello world test function
(defun sayhello()
(format t “Hello Common Lisp!”))

2.加载并运行文件,打开clisp

[1]> (load "hello.lsp")
;; Loading file hello.lsp ...
;; Loaded file hello.lsp
T
[2]> (sayhello)
Hello Common Lisp!
NIL
[3]>

trunc函数示例

1、时间处理

select trunc(sysdate) from dual  
--2011-3-18 今天的日期为2011-3-18

select trunc(sysdate, 'mm')   from   dual  
--2011-3-1 返回当月第一天.

select trunc(sysdate,'yy') from dual  
--2011-1-1 返回当年第一天

select trunc(sysdate,'dd') from dual  
--2011-3-18 返回当前年月日

select trunc(sysdate,'yyyy') from dual  
--2011-1-1 返回当年第一天

select trunc(sysdate,'d') from dual  
--2011-3-13 (星期天)返回当前星期的第一天

select trunc(sysdate, 'hh') from dual   
--2011-3-18 14:00:00 当前时间为14:41   

select trunc(sysdate, 'mi') from dual  
--2011-3-18 14:41:00 TRUNC()函数没有秒的精确

2、数字处理

select trunc(123.458) from dual 
--123

select trunc(123.458,0) from dual 
--123

select trunc(123.458,1) from dual 
--123.4

select trunc(123.458,-1) from dual 
--120

select trunc(123.458,-4) from dual 
--0

select trunc(123.458,4) from dual  
--123.458

select trunc(123) from dual  
--123

select trunc(123,1) from dual 
--123

select trunc(123,-1) from dual 
--120

Jeff Dean facts

日常:

Jeff Dean was born on December 31, 1969 at 11:48 PM. It took him twelve minutes to implement his first time counter.

Jeff Dean puts his pants on one leg at a time, but if he had more legs, you would see that his approach is O(log n).

Jeff Dean’s watch displays seconds since January 1st, 1970. He is never late.

During his own Google interview, Jeff Dean was asked the implications if P=NP were true. He said, “P = 0 or N = 1.” Then, before the interviewer had even finished laughing, Jeff examined Google’s public certificate and wrote the private key on the whiteboard.

Jeff dean doesn’t have a wikipedia page. Wikipedia has a page on Jeff Dean.

Jeff Dean has binary readability.

Jeff Dean sorts his phone contacts by their vcard’s md5 checksums.

When Jeff has trouble sleeping, he Mapreduces sheep.

When Jeff Dean listens to mp3s, he just cats them to /dev/dsp and does the decoding in his head.

One day Jeff Dean grabbed his Etch-a-Sketch instead of his laptop on his way out the door. On his way back home to get his real laptop, he programmed the Etch-a-Sketch to play Tetris.

Jeff Dean is still waiting for mathematicians to discover the joke he hid in the digits of PI.

Jeff Dean can beat you at connect four. In three moves.

When Jeff Dean goes on vacation, production services across Google mysteriously stop working within a few days. This is actually true.

Jeff Dean was sick few times… That’s how computer viruses came to existence!

Jeff Dean can determine the exact position and velocity of an electron.

Jeff Dean doesn’t kill processes, he slays them.

In one of Jeff Dean’s Notebooks for Algorithms/Theory Of Computation , written on Margin is ” I have discovered a truly marvelous proof of this, which this margin is too narrow to contain”.

Jeff Dean Map Reduces his cereal.

Jeff Dean made Google Maps using his knitting kit.

The needle in haystack found Jeff Dean.

Jeff Dean’s Dropbox quota is bigger than all of YouTube’s storage farms.

All of the Google App Engine is actually hosted from Jeff Dean’s Nexus S.

PageRank made the Dean’s list.

Jeff Dean wrote a genetic algorithm. It made awesome things amongst which are BigTable and Peter Norvig.

Recently Jeff Dean got promoted even before the performance evaluation cycle started.

They had to invent a new post (Senior Google Fellow) just to promote Jeff (and Sanjay).

其他日常:

When he heard that Jeff Dean’s autobiography would be exclusive to the platform, Richard Stallman bought a Kindle.

God created Jeff Dean. Then he programmed Chuck Norris.

When Graham Bell invented the telephone, he saw a missed call from Jeff Dean.

Why did Vint Cerf invent the Internet? Because Jeff Dean didn’t have time.

Knuth mailed a copy of TAOCP to Google. Jeff Dean autographed it and mailed it back.

Only two people know all Jeff Dean facts. Both Jeff and Chuck think sharing them all would be too much for mere mortals.

Voldemort is scared of Jeff Dean.

Thron movies are based on Jeff Dean’s life.

算法与优化:

Unsatisfied with constant time, Jeff Dean created the world’s first O(1/n) algorithm.

Jeff Dean wrote an O(n^2) algorithm once. It was for the Traveling Salesman Problem.

Jeff Dean’s Bubble Sort runs in O(1) time.

The speed of light in a vacuum used to be about 35 mph. Then Jeff Dean spent a weekend optimizing physics.

Google search went down for a few hours in 2002, and Jeff Dean started handling queries by hand. Search Quality doubled.

Once, in early 2002, when the search back-ends went down, Jeff Dean answered user queries manually for two hours. Result quality improved markedly during this time.”

编程:

Jeff Dean eschews both Emacs and VI. He types his code into zcat, because it’s faster that way.

Jeff Dean writes directly in binary. He then writes the source code as a documentation for other developers.

Jeff Dean can parse HTML with Regular Expressions

All pointers point to Jeff Dean.

You name three pointers, Einstein, Euler, and Turing, when you de-reference them, all you get is Jeff Dean.

Jeff starts his programming sessions with ‘cat > /dev/mem’.

Jeff Dean once shifted a bit so hard, it ended up on another computer.

Jeff Dean’s infinite loops run in 5 seconds.

Jeff Dean can write infinite recursion functions…and have them return.

Jeff Dean has gone to /dev/null and come back.

Jeff Dean can losslessly compress random data.

All Jeff Dean’s code is pure. For fun, he once wrote a function with a side effect, that side effect is known as Gmail.

Jeff Dean can unit test entire applications with a single assert.

When Jeff Dean fires up the profiler, loops unroll themselves in fear.

Jeff Dean once implemented a web server in a single printf() call. Other engineers added thousands of lines of explanatory comments but still don’t understand exactly how it works. Today that program is the front-end to Google Search.

Jeff Dean was forced to invent asynchronous APIs one day when he optimized a function so that it returned before it was invoked.

Jeff once simultaneously reduced all binary sizes by 3% AND raised the severity of a previously known low-priority python bug to critical-priority in a single change that contained no python code.

When your code has undefined behavior, you get a seg fault and corrupted data. When Jeff Dean’s code has undefined behavior, a unicorn rides in on a rainbow and gives everybody free ice cream.

When Jeff Dean sends an ethernet frame there are no collisions because the competing frames retreat back up into the buffer memory on their source nic.

Jeff Dean once failed a Turing test when he correctly identified the 203rd Fibonacci number in less than a second.

命令行及编译器:

Compilers don’t warn Jeff Dean. Jeff Dean warns compilers.

Jeff Dean builds his code before committing it, but only to check for compiler and linker bugs.

gcc -O4 sends your code to Jeff Dean for a complete rewrite.

The x86-64 spec includes several undocumented instructions marked ‘private use.’ They are actually for Jeff Dean’s use.

When Jeff Dean designs software, he first codes the binary and then writes the source as documentation.

mantri@mantri-laptop~$ rm -r /
rm: cannot remove root directory `/’
mantri@mantri-laptop~$ su – jeffdean -c “rm -r /”
I am extremely sorry. Removing root directory…

硬件:

The rate at which Jeff Dean produces code jumped by a factor of 40 in late 2000 when he upgraded his keyboard to USB 2.0.

When Jeff Dean has an ergonomic evaluation, it is for the protection of his keyboard.

Jeff Dean’s ISP routes all traffic through Jeff Dean’s router. It is faster that way.

Jeff Deans’s keyboard doesn’t have a Ctrl key because nothing controls Jeff Dean.

Jeff Dean’s keyboard has two keys: 1 and 0.

参考:
google+
quora

cpp用函数实现sizeof操作符的功能

#include "stdafx.h"
#include <stdlib.h>

using namespace std;

template<class ToT>
int getTypeSize(ToT *t,int len=1);

#define GET_TYPE_LEN(TYPE_NAME) getTypeSize(new TYPE_NAME());

struct MM{
	int m1;
	char m2;
	long m3;
	char* m4;
};

int _tmain(int argc, _TCHAR* argv[])
{
	struct MM mm;
	int nLen1 = getTypeSize(&mm);
	int nLen2 = GET_TYPE_LEN(MM); 

	return 0;
}

template<class ToT>
int getTypeSize(ToT *t, int len)
{
	return((char *)(t+1)-(char *)t)*len;
}

这种实现,有几个问题:
1、区分是类型还是变量,暂时没有找到好的办法
2、对于数组,暂时没有好的方法处理
3、为简化处理,要求输入为指针