すべての出会いが美しいとは限らない。すべての別れが悲しいとは言えない。

0%

Description

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Given a binary tree, find its maximum depth.

The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

Note: A leaf is a node with no children.

Example:

Given binary tree [3,9,20,null,null,15,7],

3
/ \
9 20
/ \
15 7
return its depth = 3.
Read more »

Class

define a class

1
2
3
4
class Klass
def initialize()
end
end

create instance by new

1
2
3
4
5
6
7
8
9
10
11
12
class Hello
def initialize
end

def talk
puts "Hello world"
end
end

hello = Hello.new
hello.talk
# => Hello world
Read more »

Sometimes we need get the form data as a json to put it into another ajax request with other data.
This is a method to get the data of form as json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function getFormJson(name) {
var data = {};
var form_data = $(name).serializeArray()
for (var i = 0; i < form_data.length; i++){
if (data[form_data[i]['name']] != undefined) {
if ($.isArray(data[form_data[i]['name']])) {
data[form_data[i]['name']].push(form_data[i]['value']);
} else {
data[form_data[i]['name']] = [data[form_data[i]['name']], form_data[i]['value']];
}
} else {
data[form_data[i]['name']] = form_data[i]['value'];
}
}
return data;
}

In-House Sever

Pros Cons
Gives you physical control over your backup. Requires a capital investment in hardware and infrastructure.
Keeps critical data in-house. No third party has access to your information. Needs space in your office for a rack or server room/closet, in addition to dedicated IT support.
No need to rely on an Internet connection for access to data. May be more susceptible to data loss during disaster situations due to its in-house location. How often you take the data offsite will reflect how much data you’ll lose in an emergency.
Can be more cost-effective for small to mid-sized companies. No uptime or recovery time guarantees.

Cloud Server

Pros Cons
No need for onsite hardware or capital expenses. Well-suited to smaller companies that may outgrow storage too quickly. The costs of the data recovery could outweigh the benefits for companies that are not as dependent on uptime and instant recovery.
Storage can be added as needed. Solutions are often on-demand, so you only pay for what you need. Every organization will have a limit to data that can be stored in the cloud due to storage availability and cost.
Backup and restore can be initiated from anywhere, using any computer, tablet, or smartphone. If the Internet goes down on your side or on your cloud provider’s side, you won’t have access to any of your information.
Data can be backed up in the cloud as regularly as 15-minute intervals, minimizing data losses in disaster situations. Small data set recovery time is improved. Full data recovery could prove very time-consuming and impactful on systems.

Fog

Tech’s future may lie in the “fog” rather than the cloud. In other words, cloud solutions are great, but businesses may not want to have everything “out there” in the cloud. Some solutions will still need to be kept in-house or on the device, closer to the ground. For many companies, the best configuration will be somewhere in between, which the article refers to as “the fog”.

We usually get the length of a string by length method. But it is not the correct result of the string which composites of chinese charaters because the chinese charaters will take 2 space for each. On the other side, one more method bytesize of String, will return the3, the bytes length of the string.

1
2
"abc123){*~".bytesize #=>10
"あああ".bytesize #=>9

So, I define a function to get the result I want:

1
2
3
def kanjisize(string)
sring.each_char.map{|c| c.bytesize == 1 ? 1 : 2}.reduce(0, &:+)
end

and make it as a monkey patch of String with the path of lib/core_extensions/string/kanji_size.rb:

1
2
3
4
5
6
7
8
9
10
11
module CoreExtensions
module String
module KanjiSize
def kanjisize
self.each_char.map{|c| c.bytesize == 1 ? 1 : 2}.reduce(0, &:+)
end
end
end
end

String.send(:include, CoreExtensions::String::KanjiSize)
1
2
"abc123){*~".bytesize #=>10
"あああ".bytesize #=>6

Problem

One day, the upload feature of our server was failed because there were not enough memory on server.
So I logged into server and excute the free command:

1
2
3
4
5
$ free -g
total used free shared buffers cached
Mem: 15 15 0 0 2 0
-/+ buffers/cache: 12 2
Swap: 17 0 17

However, the result of the top command showed that the free memory was 0 without any process which costed so much memory:

1
2
$ ps aux | awk '{mem += $6} END {print mem/1024/1024}'
0.595089

After a long time research on Google, I found that there was another kind of cache, Slab, whichfree command count as used memory.

Read more »

Step 0: Check OS Info

1
2
$ cat /etc/*-release
CentOS release 6.6 (Final)

Step 1: Install Java

1
2
3
4
5
$ yum install java-1.8.0-openjdk
$ java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

Step 2: Install Jenkins

1
2
3
4
$ sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
$ sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
$ sudo yum install jenkins
$ sudo service jenkins start

Step 3: Start Jenkins When System Reboot

1
2
3
$ chkconfig jenkins on
$ sudo chkconfig --list jenkins
jenkins 0:off 1:off 2:on 3:on 4:on 5:on 6:off

原文地址: http://blog.csdn.net/guolin_blog/article/details/8986299

今天你的leader兴致冲冲地找到你,希望你可以帮他一个小忙,他现在急着要去开会。要帮什么忙呢?你很好奇。
他对你说,当前你们项目的数据库中有一张用户信息表,里面存放了很用户的数据,现在需要完成一个选择性查询用户信息的功能。他说会传递给你一个包含许多用户名的数组,你需要根据这些用户名把他们相应的数据都给查出来。
这个功能很简单的嘛,你爽快地答应了。由于你们项目使用的是MySQL数据库,你很快地写出了如下代码:

Read more »

原文地址: http://blog.csdn.net/guolin_blog/article/details/9153761

  听说你们公司最近新推出了一款电子书阅读应用,市场反应很不错,应用里还有图书商城,用户可以在其中随意选购自己喜欢的书籍。你们公司也是对此项目高度重视,加大了投入力度,决定给此应用再增加点功能。
  好吧,你也知道你是逃不过此劫了,没过多久你的leader就找到了你。他告诉你目前的应用对每本书的浏览量和销售量做了统计,但现在想增加对每个书籍分类的浏览量和销售量以及所有书籍总的浏览量和销售量做统计的功能,希望你可以来完成这项功能。
  领导安排的工作当然是推脱不掉的,你只能硬着头皮上了,不过好在这个功能看起来也不怎么复杂。
  你比较喜欢看小说,那么就从小说类的统计功能开始做起吧。首先通过get_all_novels方法可以获取到所有的小说名,然后将小说名传入get_browse_count方法可以得到该书的浏览量,将小说名传入get_sale_count方法可以得到该书的销售量。你目前只有这几个已知的API可以使用,那么开始动手吧!

Read more »