Redian新闻
>
邻居家的树压我的房子,怎么办?
avatar
邻居家的树压我的房子,怎么办?# Living
S*0
1
Web development职位,不是很大的公司,先发邮件来做题,第一次碰到。
刚刚做完,过会发我的sample答案上来
1. Describe a deadlock. What causes it? What are the effects?
2. Consider class Car with method getMake() -> String. Write a function to
retrieve all Toyotas from the following data structure:
ArrayList cars
3. List the bugs/problems in the following code snippets:
a. select * from claim where diagnosis_id in (739.1) and where patient_id in
(select patient_id from patient where name is ‘SMITH’)
b.with a as (select * from claim)
select * from a where patient_id = 1231232;
c. class Test {
x int;
function inc() {
x = x + 1;
}
}
4. The following query is running slowly and returning bad results, fix and
optimize? What information do you need for optimization?
select *
from cars
where make = ?
and color = ?
or id = ?
5. Give three advantages of using the Model View Controller architecture
pattern.
6. What are the key traits of a successful manager?
7. You have a PHP Application that provides a lot of semi-static data to
users joined from many different MySQL schemas and tables in one page. The
elements on this page vary from tables, text, and charts. Over time as usage
and data grows, the page load elapsed time has increased from a half a
second when you first launched to 10 seconds during peak usage time
currently. You’ve spent a lot of time trying to optimize your queries and
PHP code, but no matter what you do, you cannot get it to perform any faster
. Most likely, you’ve run into a limitation in server performance and your
manager says that there is no money in the budget at this point in time for
a new server. You have to get the page to load in less than 2 seconds. What
would you do next?
8. Below is a method that is called from a page for retrieving a user’s
name from a database to return the user’s name and login for presentation
on the top portion of a “homepage”. Please identify the problem(s) with
the below example.
//method in “SomeClass” function
function getUserCreds($userId = null) {
$userId = 12;
$this->sql = “select first,last,login from user where id = $userId”;
$this->resultSet = mysql_query($this->sql);
foreach($row as mysql_fetch_array($this->result)) {
$this->user->first = $row[‘first’];
$this->user->last = $row[‘last’];
$this->user->login = $row[‘login’];
}
return $this->user;
}
//calling page
$userId = $_SESSION[‘userId’];
$user = SomeClass::getUserCreds($userId);
if(empty($user)) $user = “Guest”;
?>
Welcome
avatar
A*o
2
邻居家的树压着我的房子, branches and leaves 压着我的房子, 告诉HOA去协商此事,
邻居居然说 " I do not think so!".
怎么办?
avatar
S*0
3
1. Deadlock describes a situation that two or more threads (processes) are
blocked forever, waiting for each other.
Causes: one thread needs to visit the resource that another thread is
possessing and vice versa.
Effects: If deadlock happens, the threads involved will hang there forever
in an undesired status. Deadlock should be avoided.
2.
public ArrayList getToyotas(ArrayList cars)
{
if(cars == null) return null;

ArrayList toyotas = new ArrayList();
for (ListIterator iterator = cars.listIterator(); iterator.hasNext(
);)
{
if(iterator.next().getMake().equals("Toyota")){
toyotas.add(iterator.next());
}
}
if(toyotas.size() > 0)
return toyotas;
else
return null;
}
3.
a. select * from claim where diagnosis_id in (739.1) and where patient_id in
(select patient_id from patient where name is ‘SMITH’)
Bugs: 1. Second “where” is not needed.
2. Is should be “=”
Correct query:
SELECT * FROM claim WHERE diagnosis_id IN (739.1) and patient_id IN (SELECT
patient_id FROM patient WHERE name=‘SMITH’)
with a as (select * from claim)
b. select * from a where patient_id = 1231232;
The “with as” clause can be used when subquery can be used several times
to improve query speed. It’s not necessary here.
c. class Test {
x int;
function inc() {
x = x + 1;
}
}
Bugs: 1. wrong declaration of variable x
2. no access modifier for both variable x and function inc()
3. no constructor
4. no return type for function inc()
5. no initialization for variable x
Example class definition in Java:
public class Test {
private int x;

public Test(){
x = 0;
}

public void inc(){
x = x + 1;
}
}
4.
It’s bad combination of “and” and “or”. If “id” is unique, then this
query will not return the specific car with the “id”.
If the “id” is known, the query can be:
select * from cars where id=?
If the “id” is unknown, the following can return cars with specific make
and color:
select * from cars where make = ? and color = ?
So, more attention should be paid to query with combination of “and” and
“or”
5.
1. Substitutable user interface: Different views and controllers can be
substituted to provide alternate user interfaces for the same model.
2. Multiple simultaneous views of the same model: Multiple different views
can be active at the same time. Each view simultaneously and independently
presents the same information from the model.
3. Easier testing : With MVC it can be easier to test the core of the
application, as encapsulated by the model.
6. What are the key traits of a successful manager?
Integrity and trustworthiness, Team player, conflict resolution abilities
7.
One possible solution: the elements on the page can be organized in the form
of tabs or index. The tables and charts can be categorized and put in
corresponding tabs. The content for each tab can be loaded using AJAX
without reloading the whole page. In this way, the tables, text and charts
can be arranged in order and page loading time can be significantly reduced.
User can get better experience.
8.
Modified version:
//method in SomeClass function
function getUserCreds($userId) {
//bug 1
//$userId = 12;
if($userId == null) return null;
//bug2: sanitization needed
$userId = mysql_real_escape_string($userId);
$this->sql = select first,last,login from user where id = $userId;
$this->resultSet = mysql_query($this->sql);
//bug3: initialize $this->user
$this->user = null;
//bug4: wrong use of mysql_fetch array. If need associate array, either user
mysql_fetch_assoc() or mysql_fetch_array($query, MYSQL_BOTH) or mysql_fetch
_array($query, MYSQL_ASSOC)
//foreach($row as mysql_fetch_array($this->result)) {
while($row = mysql_fetch_array($this->resultSet, MYSQL_BOTH)) {
$this->user->first = $row['first'];
$this->user->last = $row['last'];
$this->user->login = $row['login'];
}
//bug5: before return, check if user is null
if($this->user) return $this->user;
}
?>
//calling page
$userId = $_SESSION[userId];
$user = SomeClass::getUserCreds($userId);
if(empty($user)) $user = "Guest";
?>
Welcome //bug6: echo out
if($user == "Guest") echo $user;
else echo $user->first.' '.$user->last.' '.$user->login;
?>
avatar
s*d
4
过界你可以砍

【在 A***o 的大作中提到】
: 邻居家的树压着我的房子, branches and leaves 压着我的房子, 告诉HOA去协商此事,
: 邻居居然说 " I do not think so!".
: 怎么办?

avatar
x*i
5
谢谢分享!
avatar
R*U
6
跟压不压着没关系吧,树枝过界了就算,你可以把它砍回分界处。
http://www.nytimes.com/1991/11/03/realestate/talking-trees-a-sp

事,

【在 A***o 的大作中提到】
: 邻居家的树压着我的房子, branches and leaves 压着我的房子, 告诉HOA去协商此事,
: 邻居居然说 " I do not think so!".
: 怎么办?

avatar
g*g
7
Bugs: 1. wrong declaration of variable x
2. no access modifier for both variable x and function inc()
3. no constructor
4. no return type for function inc()
5. no initialization for variable x
X need not initialization, because the system will set int to 0 by default.
the class can be not set constructor because class has default constructor.
avatar
T*e
8
its much more complicated than that. read the whole article, and read local
nuisance law to determine if your right is comprimised.

【在 R***U 的大作中提到】
: 跟压不压着没关系吧,树枝过界了就算,你可以把它砍回分界处。
: http://www.nytimes.com/1991/11/03/realestate/talking-trees-a-sp
:
: 事,

avatar
S*0
9
嗯,对的,varialbes in Java 会初始化default value。
谢谢。

【在 g*********g 的大作中提到】
: Bugs: 1. wrong declaration of variable x
: 2. no access modifier for both variable x and function inc()
: 3. no constructor
: 4. no return type for function inc()
: 5. no initialization for variable x
: X need not initialization, because the system will set int to 0 by default.
: the class can be not set constructor because class has default constructor.

avatar
j*o
10
你们呀,念书都念傻了。邻居家的事最好互相协商解决,动不动就找居委会,邻居肯定
不爽

事,

【在 A***o 的大作中提到】
: 邻居家的树压着我的房子, branches and leaves 压着我的房子, 告诉HOA去协商此事,
: 邻居居然说 " I do not think so!".
: 怎么办?

avatar
n*p
11
谢谢~~~bless lz~~~~~~~`
avatar
m*y
12
Nod, bilateral is always easier and more effective. Everybody will turn
defensive when HOA is involved.

【在 j**o 的大作中提到】
: 你们呀,念书都念傻了。邻居家的事最好互相协商解决,动不动就找居委会,邻居肯定
: 不爽
:
: 事,

avatar
f*e
13
楼主很棒
avatar
i*w
15
最讨厌这种公司了

in

【在 S*******0 的大作中提到】
: Web development职位,不是很大的公司,先发邮件来做题,第一次碰到。
: 刚刚做完,过会发我的sample答案上来
: 1. Describe a deadlock. What causes it? What are the effects?
: 2. Consider class Car with method getMake() -> String. Write a function to
: retrieve all Toyotas from the following data structure:
: ArrayList cars
: 3. List the bugs/problems in the following code snippets:
: a. select * from claim where diagnosis_id in (739.1) and where patient_id in
: (select patient_id from patient where name is ‘SMITH’)
: b.with a as (select * from claim)

avatar
f*u
16
nod

【在 j**o 的大作中提到】
: 你们呀,念书都念傻了。邻居家的事最好互相协商解决,动不动就找居委会,邻居肯定
: 不爽
:
: 事,

avatar
r*n
17
听我agent说是这样的:过了界的可以砍。不过要是把树砍死了,邻居可以找你索赔

事,

【在 A***o 的大作中提到】
: 邻居家的树压着我的房子, branches and leaves 压着我的房子, 告诉HOA去协商此事,
: 邻居居然说 " I do not think so!".
: 怎么办?

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。