Search

7/28/2010

My Google Interview ~ C for Coding

Steve Yegge’s Get that job at Google.


The first problem I encountered was that at least two of my interviewers had only passing or no familiarity with Java. This made it particularly difficult as some concepts are unique to one language.

But everyone knew C++. I’ve read about this before. This combined with my own experience now leads me to believe that C++ isn’t optional for any Google applicant. Not because you need to use it to work there. I have no direct experience of this. But because of “interviewer lottery”. Some at Google (it seems) do nothing but C++. You might be interviewed by one of these people.

I had to write several code segments on a whiteboard. This I expected and was fine with. I realize this is necessary (see Why Can't Programmers.. Program? and The Non-Programming Programmer) and have no problem with it but it depends on what kind of problem you ask. Simple is usually best.

Two of the problems I had were extremely finnicky to solve. In one I think the interviewer was understanding and simply wanted to determine if I understand the relevant contract and I could see what the issues were more than coding a completely correct solution (which I appreciated). Another interview got caught short before an efficient solution could be developed and I really don’t think it’s the kind of problem that lends itself to writing a code solution in 40 minute. By this I mean I believe it would be more valuable to speak about the algorithms and problems involved as the code for an efficient solution would be quite complex.

The theme of problem solving and analyzing thought processes remained constant throughout.

For some reason I had expected there would be a lunch break (10-2). There wasn’t. By the end I was mentally exhausted, 3pm (it ran over time) and I hadn’t eaten since the day before. The next day I returned home.

Go through sample interview questions for Google, Microsoft, Amazon and other companies (really - any of them work - they all ask very similar if not the same questions). CareerCup has thousands of these questions (shameless, plus I know :)).
The Official CareerCup Book: Cracking the Coding Interview, 4th Edition

7/27/2010

H-1B visa

Temporary Workers

H-1B Persons in Specialty Occupation which requires the theoretical and practical application of a body of highly specialized knowledge requiring completion of a specific course of higher education. (65,000). This category also includes fashion models and Government-to-Government research and development, or co-production projects administered by the Department of Defense (100);

via: My Google Interview ~ C for Coding

SWIG Tutorial

SWIG Tutorial

SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of languages including common scripting languages such as Perl, PHP, Python, Tcl and Ruby. The list of supported languages also includes non-scripting languages such as C#, Common Lisp (CLISP, Allegro CL, CFFI, UFFI), Java, Lua, Modula-3, OCAML, Octave and R. Also several interpreted and compiled Scheme implementations (Guile, MzScheme, Chicken) are supported. SWIG is most commonly used to create high-level interpreted or compiled programming environments, user interfaces, and as a tool for testing and prototyping C/C++ software. SWIG can also export its parse tree in the form of XML and Lisp s-expressions. SWIG may be freely used, distributed, and modified for commercial and non-commercial use.


So you want to get going in a hurry? To illustrate the use of SWIG, suppose you have some C functions you want added to Tcl, Perl, Python, Java and C#. Specifically, let's say you have them in a file 'example.c'

/* File : example.c */
double My_variable = 3.0;

int fact(int n) {
if (n <= 1) return 1;
else return n*fact(n-1);
}

int my_mod(int x, int y) {
return (x%y);
}

char *get_time()
{
time_t ltime;
time(<ime);
return ctime(<ime);
}


Interface file
Now, in order to add these files to your favorite language, you need to write an "interface file" which is the input to SWIG. An interface file for these C functions might look like this :

/* example.i */
%module example
%{
/* Put header files here or function declarations like below */
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
%}

extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();

Building a Tcl module
At the UNIX prompt, type the following (shown for Linux, see the SWIG Wiki Shared Libraries page for help with other operating systems):

unix % swig -tcl example.i
unix % gcc -fpic -c example.c example_wrap.c \
-I/usr/local/include
unix % gcc -shared example.o example_wrap.o -o example.so
unix % tclsh
% load ./example.so example
% puts $My_variable
3.0
% fact 5
120
% my_mod 7 3
1
% get_time
Sun Feb 11 23:01:07 1996

The swig command produces a file example_wrap.c that should be compiled and linked with the rest of the program. In this case, we have built a dynamically loadable extension that can be loaded into the Tcl interpreter using the 'load' command.

Python at Google (Greg Stein - SDForum) [panela.blog-city.com]

Python at Google (Greg Stein - SDForum) [panela.blog-city.com]

Swig is your friend
Google makes extensive use of Swig. Greg indicated that Swig has improved much in recent years. All C++ projects in Google have swig generators created during build time, so python programmers can take advantage of this work. Greg said that neither Boost nor ctypes were as direct or clean as using SWIG.

RPC
RPC is the method Google uses to scale horizontally so well. They have their own internal binary wire format that speaks over http. Programmers can easy speak this format using Java, C++ or Python. Using RPC allows Google to divide computing problems up across large numbers of servers.

Python at Google
Python programmers at Google must follow a strict style guideline (based on PEP8 with 2 spaced indenting). When engineers are first granted commit access to their SCM system, they must pass a style test. All code must pass through two sets of eyes before being checked in. That combined with liberal doses of unittest, pychecker and code coverage eliminates most non-algorithmic issues that might appear in python code.

Where is Python used?
* The Google build system is written in python. All of Google's corporate code is checked into a repository and the dependency and building of this code is managed by python. Greg mentioned that to create code.google.com took about 100 lines of python code. But since it has so many dependencies, the build system generated a 3 megabyte makefile for it!
* Packaging. Google has an internal packaging format like RPM. These packages are created using python.
* Binary Data Pusher. This is the area where Alex Martelli is working, on optimizing pushing bits between thousands of servers
* Production servers. All monitoring, restarting and data collection functionality is done with python
* Reporting. Logs are analyzed and reports are generated using Python.
* A few services including code.google.com and google groups. Most other front ends are in C++ (google.com) and Java (gmail). All web services are built on top of a highly optimizing http server wrapped with SWIG.

7/26/2010

南北貨俱樂部-電冰箱的菜櫥子 - 台式肉燥+黑白魯

南北貨俱樂部-電冰箱的菜櫥子 - 台式肉燥+黑白魯

材料:
1.豬油(絞肉)約2~3斤。沒有豬油可以挑肥一點絞肉效果會比較好。
2.油蔥酥約70克。(類似冰箱買的小包裝兩包)
3.黑豆蔭油約200c.c.。
4.冰糖適量。
5.粉腸一斤、豆干、雞蛋等等隨喜。
6.米酒兩瓶。

1.鍋燒熱後,將豬絞肉下鍋炒。
2.等到肉炒到變白後,加入醬油一起炒。
3.接著,加入冰糖以及油蔥酥,攪拌均勻。
4.最後,加入兩瓶米酒,煮沸後轉小火續魯。
5.大約滾約10分鐘後,將其他要魯的食材放下去一起魯。
6.以小火大概魯個50分鐘之後,台式肉燥黑白魯就大功告成囉。

食譜: 烤地瓜

DIY 烤出專業級香噴噴地瓜

步驟一:把地瓜洗淨後放進冰箱冷凍庫,凍45分鐘。
步驟二:將冷凍後地瓜放進烤箱(200度),烤30分鐘。
專家說~~~
『因為蕃薯冷凍後內水份子變大,破壞纖維密度,並將空氣擠壓,熱傳導加速,可以節省60﹪的烤薯時間,內外熟食度也比較柔軟均勻喔!』


通常購買時會選擇小的或長條型的地瓜,因為家裡是小烤箱,這樣比較不怕高度太高容易烤焦喔!

烤出的地瓜,皮與肉已剝離,撕開外皮後,會有一層QQ的表皮,偶帶焦香,偶帶蜜。

7/14/2010

HTML5 structure—div, section & article ・ @boblet

HTML5 structure—div, section & article ・ @boblet

1. <div>—the "generic flow container" we all know and love. It’s a block-level element with no additional semantic meaning (W3C:Markup, WhatWG)
2. <section>—a "generic document or application section". A <section> normally has a heading (title) and maybe a footer too. It’s a chunk of related content, like a subsection of a long article, a major part of the page (eg the news section on the homepage), or a page in a webapp’s tabbed interface. (W3C:Markup, WhatWG)
3. <article>—an "an independent part of a document or site". This means it should be able to ‘stand alone’, and still make sense if you encountered it somewhere else (eg in an RSS feed). Examples include a weblog article (duh), a forum post or a comment. Like <section> these generally have a header, and maybe a footer (W3C:HTML, WhatWG)

The new HTML5 <section> element is similar to <div> as a general container element, but it *does* have some semantic meaning—the things it contains are a logical group of related content:

The section element represents a generic document or application section. A section, in this context, is a thematic grouping of content, typically with a header, possibly with a footer.


The section element | HTML5 Doctor


# Don’t use it just as hook for styling or scripting; that’s a div
# Don’t use it if article, aside or nav is more appropriate
# Don’t use it unless there is naturally a heading at the start of the section
# The revised spec (as of 16 September) says:
Authors are encouraged to use the article element instead of the section element when it would make sense to syndicate the contents of the element.

As blogposts and comments are often syndicated (by being pulled into other blogs or being linked via twitter, reddit etc) they should be articles.

如何選擇用哪些軟體來開啟/編輯檔案?來試試「開啟專家」吧! | ㊣軟體玩家

如何選擇用哪些軟體來開啟/編輯檔案?來試試「開啟專家」吧! | ㊣軟體玩家

版本:OpenExpert 1.40 (649KB) (個人/家庭使用免費)
官方網站: http://www.baxbex.com/openexpert.html
下載點:http://www.baxbex.com/files/openexp.exe

7/11/2010

Acer Aspire 3810T 灌 XP

1. 到 bios 把硬碟改成 IDE mode
2. 安裝 winxp
3. 按照 分享 解决 Acer Aspire 3810T 灌 XP 时 AHCI 问题 安裝 ACHI driver

1. 先将原本的 Vista 系统 recovery disk 做起来,Acer 网站上提供的 dirver 下载完整,储存起来。
2. 先在 BIOS 将硬碟先设为 IDE 模式,然后安装 XP(因为没有光碟机,我是用随身碟安装 XP SP3,相关准备及设定请参考debbiejames的文章 http://www.mobile01.com/topicdetail.php?f=159&t=665722&p=1
3. 安装 Acer 提供的各项 driver, 其中会发现 "进阶主机控制器介面 Intel SATA AHCI Driver 8.8.0.1009" 执行时会出现 "本系统不符合安装此软体的最低需求,安装程式即将结束" 的错误讯息,这时先不要关闭这个视窗!
4. 接着按 开始 --> 设定 --> 控制台 --> 系统 --> 硬体 --> 装置管理员 , 打开 "IDE ATA/ATAPI 控制器" 项目。
5. 应该会看到 "Intel(R)ICH9M-E/M SATA IDE Controller ",指着它按右键,选 "更新驱动程式" --> "从清单或特定位置安装" --> "不要搜寻,我将选择要安装的驱动程式" --> "从磁片安装" --> 按 "浏览" 将路径指向 C:\Windows\Temp\IIF2\Winall\Driver\iaAHCI.inf
6. 选择对应的硬碟控制器 " Intel(R)ICH9M-E/M SATA AHCI Controller ",在最后面。
7. 按 "下一步" 后 重新开机过程中到 BIOS 内把 硬碟的 AHCI 模式调回来。

4. 到 bios 把硬碟給回 AHCI mode

via: Acer Timeline 3810T 安裝完XP 所發生的問題 - Mobile01 討論群組

7/05/2010

node.js


var sys = require('sys')
filename = process.ARGV[2],
spawn = require('child_process').spawn;

if (!filename)
return sys.puts("Usage: node watcher.js filename");

// Look at http://nodejs.org/api.html#_child_processes for detail.
var tail = spawn("tail", ["-f", filename]);
sys.puts("start tailing");

tail.stdout.addListener("data", function (data) {
sys.puts(data);
});

// From nodejs.org/jsconf.pdf slide 56
var http = require("http");

http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
tail.stdout.addListener("data", function (data) {
response.write(data);
});
//response.end('Hello World\n');
}).listen(8124);

root@core:~# echo 'line 10' >> foo