离回家越来越近,写点什么吧。

BDA

不知不觉,已经在北京待了四个多月了,还有不到10天就要回家了。想想在北京这四个多月以来,自己都做了哪些有意义的事情呢?


工作

来北京本来是打算要闭门造车,我司Team成员在一起协作开发出一款新产品。可是到目前为止,也没有一个成型的产品可以拿出来Show的。但是,这并不代表我们没有努力,也在一点点探索,一步步的向前迈步。

学习

终于,我们转到Python了,新语言让我兴奋不已,求知若渴,迷失在Python的世界里。先不说其性能如何,光是简洁优雅的语法就已经让我爱上了这门语言。还有其灵活性,那么多的第三方library可以自由组合使用,太爽了。

Python is a powerful multiparadigm computer programming language, optimized for programmer productivity, code readability, and software quality. ——Mark Lutz

学会了微信公众号开发基础,也了解了怎么样运营一个微信公众号。在我们的新产品上使用了微信授权登录,总共写了PHP、ColdFusion和Python三个版本的Code,算是把微信授权登录给研究透彻了。其实,我想说,学习一门新技术时,必须静下心来学,认真细心是必须的。

读了如下几本书,包括技术类和人文类,当然,人文类的相对少一些,因为毕竟还要工作。

  • 《微信公众平台开发最佳实践》
  • 《用户体验要素》
  • 《在你身边,为你设计》
  • 《我们仨》
  • Make Your Own Text Adventure With Python
  • Flask.Web.Development.Developing.Web.Applications.with.Python

生活

带了两个亲戚走向开发这条不归路。过完年未出正月,我就带了两个学生,一个表哥,一个表弟。让他们照HTML->Div+Css->Javascript->MySQL->PHP这个路线学,其他人也都是这么过来的。我来了北京,带着表弟,表哥虽没有跟来,但是他自己在家学得也很不错。学了差不多四个月左右,现在各自也都找到了工作,并且还比较稳定,这是给我最大的欣慰。

这篇随笔,把妻儿放到最后写也代表了他们在我心里是最重要的。这四个多月以来,他们带给我的不只有欢乐,我知道我努力学习、工作的动力就是他们。每天早上醒来,看到身边一张稚嫩的小脸和另一张美丽的脸庞,就有勇气面对对未来的恐惧。大步向前,为让他们过上更幸福的生活。

This is my first time to use Mankdown to write.

Here are some tips for SQL

SQL Server

Concatenate rows into a comma-separated list,we can do it like this.

[tsql]
SELECT DISTINCT
usr.id, usr.name,
(SELECT STUFF((SELECT ‘,’+title FROM hobby_main AS hm WHERE hm.uid=usr.id FOR XML PATH(”)),1,1,”)) AS hobbies
FROM user AS usr
WHERE name = ‘Pengcheng’
[/tsql]

MySQL

I help my little brother to rank the running data in CampusRun app,there is a release date for this app.It calculates total distance from the release date when user’s registration date before the app release date,then calculates total distance from user’s registration date.so i have to use IF statement inside WHERE clause in SQL like below.

[mysql]
SELECT b.id, b.cnname, SUM(distance)/1000 AS total_distance
FROM `xm__run_infos_by_day` AS a
INNER JOIN `xm__member` AS b
ON a.ydq_openid = b.ydq_openid
WHERE IF(b.ydq_join_time < '1467450000', a.time >= ‘1467450000’, a.time >= b.ydq_join_time)
GROUP BY a.ydq_openid, b.cnname, b.id
ORDER BY SUM(distance)/1000 DESC
[/mysql]

Python Web Development 2 Questions

1.Why do we use virtual environments? The advantage of virtual environments is avoids the effects of different Python projects,each Python project has its own library and interpreter.

virtualenv is most popular tool of Python virtual environments config.It not only support Python 2 but also Python 3,it still can designate interpreter for each virtual environment,but doesn’t inherit the basic library. From Python 3.3,there is a  buildin virtual environment called venv,it similar to  virtualenv,but it only supports Python 3.3 and the versions after Python 3.3. So,we can use command

python -m venv myenv

to create our virtual environments,actually,the file of the command is Python Root\Tools\scripts\pyvenv.py,and the official website of the venv is

https://docs.python.org/3/library/venv.html,you can take a look at it.

Why do we use Blueprints? A system has many different modules,if we put all of the code into one file,the file size will be getting bigger and bigger,more and more code, it makes the code harder to maintain. It prone to error,and difficult to find the error where.And we have to spend more time to combine the code if multiple people work on the the same file. Blueprints allows us to separate the different routes,it also has different static resources.Another words,Blueprints makes the code more loose coupling,more flexible and code reusability.It still can increases efficiency for locating the errors and reduce the error rate. Look at this websites:

http://www.pythondoc.com/flask/blueprints.html http://flask.pocoo.org/docs/0.10/blueprints/

Setup Python

1.Creating virtual environments.

On Windows,just run the command like this.

if you don’t have the relevant PATH settings,you may have to invoke the pyvenv script as follows.

c:\Python35\python c:\Python35\Tools\Scripts\pyvenv.py venv

A virtural environments directory will be created when you run the command

2.Activate the virtual environments.

Once a venv has been created,it can be “activated” using a script in the venv’s binary directory,on Windows,in the Command-Prompt,we can run

venv\Scripts\activate.bat

to activate the virtual environments directly.

3.Install Flask.

Now,we are in the activated virtual environments,just run

pip install Flask

command,a few seconds later,the installation is complete.

4.Install pypyodbc

Still in virtual environments in Ccommand-Prompt,just run

pip install pypyodbc

to install it,look at the screenshot below.

How to install Python on Windows

Step 1.Download Python from the official Websites https://www.python.org/,i get the latest version of Python 3.5.1

Step 2. Just double click the python-3.5.1-amd64.exe to start the installation,then click Customize installation, select Add Python 3.5 to PATH,so that the install directory will be added to the system PATH.

Step 3. Cause of it is product environment,i deselect the Documention and IDLE,then click next button.

Step 4. Advanced Options,i just change install location to D:\Python\Python35,then click Install button to start installing Python.

Step 5. Setup was successful,just click the Colse button to finished installing.

Step 6. Check whether the installation is successful.Ctrl + R to open command prompt,type in python -V or python command,the installation is successful if what is seen in the below image.

 

Different Countries Have Different Kinds of Englishes

Voyages of people from England play an important part in spreading the English language.At present.English is frequently spoken as an official or common language in many countries,such as America,Singapore,Malaysia and some African countries.All based on British English,the English spoken in these countries can be well understood by native English speakers.But actually,these Englishes have been gradually changing in accents,spellings,expressions and the usage of vocabulary.Because of this fact,you can make use of the differences to tell which country the foreigners of your block are from.For example,if a boss fluently commands his driver,”Come up straight to my apartment by elevator and take some gas for my trucks and cabs”,instead of requesting,”Please come to my flat by lift and take some petrol for my lorries and taxis”,you can recognize his American identity,while the latter suggests that he is British.

New Words:

  • voyages
  • present
  • frequently
  • gradually
  • accents
  • vocabulary
  • foreigners
  • fluently
  • straight
  • flat
  • petrol
  • lorries
  • recognize
  • identity

Fall in Love with English

Hiding behind the loose dusty curtain,a teenager packed up his overcoat into the suitcase.He planned to leave home at dust though there was thunder and lightning outdoors.He had got to do this because he was tried of his parents’ nagging about his English study and didn’t want to go through it any longer.He couldn’t get along well with English and disliked joining in English classes because he thought his teacher ignored him on purpose.As a result,his score in each exam never added up to over 60.

His partner was concerned about him very much.She understood exactly what he was suffering from,but entirely disagreed with his idea.In order to calm him down and settle his problem,she talked with him face to face and swapped a series of learning tips with him.The items she set down helped him find the highway to studying English well.

The teenager was grateful and got great power from his friend’s words.Now,he has recovered from being upset and has fallen in love with English.

New Words:

  • loose
  • curtain
  • suitcase
  • dusk
  • thunder
  • lightning
  • nagging
  • partner
  • concerned
  • suffering
  • entirely
  • calm
  • settle
  • upset

i have a dream

i donn’t konw when i began to love traveing on the Google maps,i want to travel around the world,this is my greatest dream.

i left China for the first time in November 2013 to go to Singarpore,feels like this ongoing dream.Many things for the first time to me on this trip.such as my first flight,my first to go ot another country,a lot of things was new for me,i really like it.In Singarpore,i have to speak English,even though i can only speak a little English.it helps me realize that,English is very important.I must learn English well if i want to realize my dream.

So,i forced myself to reading more English books & technical documentation,learn more English words,listen to English songs,write something in English.i want to improve my English quickly,but it looks very difficult,so i have to make a little progress every day.

Traving on the Google maps,looking at some beautiful scenery,it gives me a lot of motivations.i believe that my dream will surely come true.

Getting started with Wechat

This week is about to end,it didn’t receive any email from DHL customers until now,so i am a little bit not used it.

The good news is I can spend more time to study some courses,such as Android or Wechat.i finished the WeChat Public Platform Development Best Practice,know more about Wechat developement and take some notes below.

How to create a Wechat test account?
Just go to http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login and click the login button,then use Scan QR Code functionality on you mobile phone to scan the QR on the desktop,it’s very easy.

How to set up URL & Token with your own server?
First,we should have our own server,and set up a can-access website as wechat developement project,like this http://wx.webtribe.com.cn.I set the URL to http://wx.webtribe.com.cn/api.php,then set the Token to webtribe,so the codes in api.php are:
[php]
/*
Webtribe http://www.webtribe.com.cn
Pengcheng 2016-05-12
*/

define(“TOKEN”, “webtribe”);
$wechatObj = new wechatCallbackapiTest();
if (isset($_GET[‘echostr’])) {
$wechatObj->valid();
}else{
$wechatObj->responseMsg();
}

class wechatCallbackapiTest
{
public function valid()
{
$echoStr = $_GET[“echostr”];
if($this->checkSignature()){
header(‘content-type:text’);
echo $echoStr;
exit;
}
}

private function checkSignature()
{
$signature = $_GET[“signature”];
$timestamp = $_GET[“timestamp”];
$nonce = $_GET[“nonce”];

$token = TOKEN;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );

if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}

public function responseMsg()
{
$postStr = $GLOBALS[“HTTP_RAW_POST_DATA”];

if (!empty($postStr)){
$postObj = simplexml_load_string($postStr, ‘SimpleXMLElement’, LIBXML_NOCDATA);
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$keyword = trim($postObj->Content);
$time = time();
$textTpl = “


%s


0
“;
if($keyword == “?” || $keyword == “?”)
{
$msgType = “text”;
$contentStr = date(“Y-m-d H:i:s”,time());
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
echo $resultStr;
}
}else{
echo “”;
exit;
}
}
}
[/php]

How to get the Access Token?
Just request https://api.weixin.qq.com/cgi-bin/token with your appid and secret of you wechat test account,the final URL maybe is https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret,ok,let me share the codes to you.
[php]
$appid = “wx97fxxxxxxxx9bbda”;
$appsecret = “3efd14bcxxxxxxx38ade06cf697fc40”;
$url = “https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret”;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$jsoninfo = json_decode($output, true);
$access_token = $jsoninfo[“access_token”];
echo $access_token;
exit;
[/php]

i have not finished wechat developement,will write more when i get more,so stay tuned!

Set email notification on Git commits

How do i configure the appropoiate Git hook to send a summary email whenever a set of changes is pushed to the repository?

There is a simplest solution:

  1. Go to one of your repository that you want to setup email notification.
  2. On the right menu,click on Settings,go to repository setting page.
  3. On the left options,click on Webhooks & Services.
  4. In the Services tab,click Add services,from available services,choose Email.
  5. Fill in your email address in field Address.
  6. Check the checkbox Sedn from Author & Active.
  7. Click the Add service button to complete the configuration.
  8. After setting,we can click the Test service button to send the test email.

This is my way to setup email notification. 🙂