简介

《为何家会伤人》

作者:武志红

出版社:北京联合出版公司

目录摘要

1、宠爱自己是溺爱孩子的真相

2、包办型溺爱让子女为父母而活

3、溺爱是温柔的陷阱

4、以爱的名义摧毁孩子的感受

5、放纵性溺爱:最懒惰的爱

6、家里的小霸王,学校小恶魔

7、放纵溺爱是在培养自己的敌人

8、隔代溺爱的六大原因

9、父母,不要把焦虑转嫁给孩子

10、父母像小孩,儿女莫纵容

11、出主意阻止了对方倒苦水

12、谎言:没有父母不爱自己的孩子,我爱你所以你要听我的

内容摘要:

1、02岁,给予孩子无条件的爱;24岁最终孩子自主的探索,但又在孩子需要帮助时候出现在他面前。这种以孩子成长需要为中心的真爱会让孩子成为自爱、爱别人、有鲜明的自我意识、健康的自主人格和高度创造力的人。

2、由于自我焦虑,对自己未来的担忧,转移到孩子身上,有劲往孩子身上使。比如各种培训班,其实是父母内心的恐惧而强加在孩子身上。

3、如果你抵达过某种境界,再去做类似的预言,你就容易相信自己。换句话说,信心是可以培养的,习惯是可以养成的,只要有了第一次信心和习惯,以后自然会更容易达到目标。

4、与家的分离三种模式:成熟分离,爱家又习惯独立;拒绝分离,恋家无法独立;单纯分离,逃离家庭拒绝与家庭保持联系。

5、包办型父母不止剥夺了孩子自我探索的机会,实际上,对孩子的真实感受也视而不见。举例:女儿要香草冰激凌,妈妈说不好吃,要草莓味的。

6、溺爱是对自己的宠爱。举例:还有几块蛋糕,自己舍不得吃,留给孩子吃吧,是对自己内心中小孩子的自己的宠爱。

7、老人之所以溺爱,往往是因为时代原因(自己旧社会吃苦太多)、隔代原因(对自己的孩子不怎么好,就对自己的孙子更好些)、老龄原因(返老还童)等

8、夫妻需要相互倾诉和倾听,而不是直接出主意。

9、婆媳关系往往是嫉妒心理产生。

收获:

1、不溺爱孩子,教给孩子对与错。

2、不把自己的焦虑传递给孩子,要让孩子快乐、健康成长

3、习惯和信心的养成与心流体验比较相似:即时反馈、挑战与技能匹配、目标清晰。做好了这几点,就会上瘾,如同游戏一样。

4、保持流畅的交流和沟通,夫妻、父子、母子、夫妻和双方父母之间。

题目:
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
For example:
Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it.
Follow up:
Could you do it without any loop/recursion in O(1) runtime?

思路:
按照提示,去 wiki 看了下这个算法 Digital root,排列一部分数据,得出原始数-最大9的整数倍,即为目标值。算法复杂度 O(1)!!!!!!

代码:

class Solution
{
public:

int addDigits(int num) 
{
    if( num <= 9 )
    {
        return num;
    }
    int nTargetNum = num / 9;
    int nResult = num - nTargetNum * 9;
    return nResult > 0 ? nResult : 9;
}

};
总结:
1、思路很重要,看到题目的竟然想到的是记录每个数位上的值,这样算法复杂度不知道要高多少倍了
2、临界值!没有无bug的程序,只有未找到的边界值,多想想边界值。
3、提交了3次才通过,很惭愧!

简介:

最近写了一个小工具,用来抓取内涵段子、糗事百科等各种笑话网站的段子和图片,最后保存文本,并发布在微信公众号上。使用谷歌的 v8 做了一个脚本引擎,使用 c++ 的实现了笑话的统计和发布功能,用js实现了网页爬取分析的功能。这样 c++ 调用 v8 引擎,加载 js 脚本,就会爬取一系列的内容。

以下是网页爬取分析的内容,当然js的实现只是思路,用其他语言也是一样能实现。抓取的内容有:文章、图片地址、点赞数。

内涵段子网页抓取分析代码:

//内涵段子
//http://neihanshequ.com/
var webUrl = 'http://neihanshequ.com/';
var imageUrl = 'http://neihanshequ.com/pic/';
var index = 1;
var endIndex = 5;
var retVal =
{

success: false,
items: []

};

function getJoyFromOnePage(htmlData, requestParams)
{

var nCount = 0;
var bEndOnePage = false;
while(!bEndOnePage)
{
    var result = 
    {
        webname: 'NeiHanDuanzi',
        webid: '',
        type: '',
        context: '',
        pic_url: '',
        read_count: '',
        publish_time: '',
        best_comment: ''       
    }
     
    //check gif
    {
        var keyWords = '"is_gif":"';
        var startIndex = htmlData.indexOf(keyWords);
        if( startIndex > 0 )
        {
            htmlData = htmlData.substring((startIndex + keyWords.length));
            var endIndex = htmlData.indexOf('"');
            var gif = htmlData.substring(0, endIndex);
            if( gif == 1 )
            {
                alert('NeiHanDuanzi:url is a gif:' + result.pic_url);
                continue;
            }
        }
    }
     
    //webid
    {
        var keyWords = 'data-group-id="';
        var startIndex = htmlData.indexOf(keyWords);
        if( startIndex > 0 )
        {
            htmlData = htmlData.substring((startIndex + keyWords.length));
            var endIndex = htmlData.indexOf('"');
            result.webid = htmlData.substring(0, endIndex);
            alert('NeiHanDuanzi:webid-' + result.webid);
        }
        else
        {
            bEndOnePage = true;
            alert('NeiHanDuanzi:webid not find, page end.');
        }
    }
     
    //read_count
    {
        var keyWords = '<span class="digg">';
        var startIndex = htmlData.indexOf(keyWords);
        if( startIndex > 0 )
        {
            htmlData = htmlData.substring((startIndex + keyWords.length));
            var endIndex = htmlData.indexOf('</span>');
            result.read_count = htmlData.substring(0, endIndex);
            //alert('NeiHanDuanzi:read_count-' + result.read_count);
        }
    }
     
    //context
    {
        var keyWords = 'data-text="';
        var startIndex = htmlData.indexOf(keyWords);
        if( startIndex > 0 )
        {
            htmlData = htmlData.substring((startIndex + keyWords.length));
            var endIndex = htmlData.indexOf('"');
            result.context = htmlData.substring(0, endIndex);
            //alert('NeiHanDuanzi:context-' + result.context);
        }
    }
     
    //pic_url
    {
        var keyWords = 'data-pic="';
        var startIndex = htmlData.indexOf(keyWords);
        if( startIndex > 0 )
        {
            htmlData = htmlData.substring((startIndex + keyWords.length));
            var endIndex = htmlData.indexOf('"');
            result.pic_url = htmlData.substring(0, endIndex);
        }
    }
     
    /*
    nCount++;
    if( nCount >= 20 )
    {
        break;
    }
    */
     
    retVal.items.push(result);
}
 
return;

}

function getJoyContextList( url, parametersString )
{

var parameters = eval("(" + parametersString + ")");
var requestParams =
{
    method: 'GET',
    version: 'HTTP/1.1',
    headers: {},
    scriptParamaters: parameters
};
 
requestParams.headers['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8';
requestParams.headers['Accept-Encoding'] = 'gzip, deflate, sdch';
requestParams.headers['Accept-Language'] = 'zh-CN,zh;q=0.8,en;q=0.6';
requestParams.headers['Cache-Control'] = 'no-cache';
requestParams.headers['Connection'] = 'keep-alive';
requestParams.headers['Cookie'] = 'uuid="w:0ef44d961a6d43c99dd81ecb51596731"; sessionid=57f633c63c5de5d0bc03cddb0c6ee166; tt_webid=5286193655; __utmt=1; csrftoken=d760789fbe1fc31edae4ac6c11c5a700; Hm_lvt_773f1a5aa45c642cf87eef671e4d3f6a=1438825221,1438939411,1440988068,1440996740; Hm_lpvt_773f1a5aa45c642cf87eef671e4d3f6a=1440996782; __utma=101886750.2017161997.1438825217.1440995644.1440996740.6; __utmb=101886750.5.10.1440996740; __utmc=101886750; __utmz=101886750.1440996740.6.4.utmcsr=haosou.com|utmccn=(organic)|utmcmd=organic|utmctr={b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}E5{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}86{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}85{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}E6{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}B6{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}B5{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}E7{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}A4{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}BE{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}E5{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}8C{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}BA';
requestParams.headers['Host'] = 'neihanshequ.com';
requestParams.headers['Pragma'] = 'no-cache';
requestParams.headers['Referer'] = 'http://neihanshequ.com/';
requestParams.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11';

{
    //get web context
    var httpRspString = syncHttpRequest(webUrl, JSON.stringify(requestParams));
    var httpRsp = eval("(" + httpRspString + ")");
    if( !httpRsp || httpRsp.statusCode != 200 )
    {
        alert('NeiHanDuanzi: Request webUrl(' + webUrl + ') failed return code:' + (httpRsp ? httpRsp.statusCode : 'undefined'));
        return JSON.stringify(retVal);
    }
     
    var htmlData = httpRsp.data;
    getJoyFromOnePage(htmlData, requestParams)
}
 
{
    //get image
    var httpRspString = syncHttpRequest(imageUrl, JSON.stringify(requestParams));
    var httpRsp = eval("(" + httpRspString + ")");
    if( !httpRsp || httpRsp.statusCode != 200 )
    {
        alert('NeiHanDuanzi: Request imageUrl(' + imageUrl + ') failed return code:' + (httpRsp ? httpRsp.statusCode : 'undefined'));
        return JSON.stringify(retVal);
    }
     
    var htmlData = httpRsp.data;
    getJoyFromOnePage(htmlData, requestParams)
     
    //alert('NeiHanDuanzi: headers' + httpRsp.data);
}

 
retVal.success = true;
return JSON.stringify(retVal);

}
糗事百科网页抓取分析代码

//糗事百科
//http://www.qiushibaike.com/hot/page/{index}
var webUrl = 'http://www.qiushibaike.com/hot/page/';
var index = 1;
var endIndex = 5;
var retVal =
{

success: false,
items: []

};

function getJoyFromOnePage(htmlData)
{

var bEndOnePage = false;
while(!bEndOnePage)
{
    var result = 
    {
        webname: 'QiuShiBaiKe',
        webid: '',
        type: '',
        context: '',
        pic_url: '',
        read_count: '',
        publish_time: '',
        best_comment: ''       
    }
    //webid
    {
        var keyWords = 'qiushi_tag_';
        var startIndex = htmlData.indexOf(keyWords);
        if( startIndex > 0 )
        {
            htmlData = htmlData.substring((startIndex + keyWords.length));
            var endIndex = htmlData.indexOf("'>");
            result.webid = htmlData.substring(0, endIndex);
            alert('QiuShiBaiKe:webid-' + result.webid);
        }
        else
        {
            bEndOnePage = true;
            alert('QiuShiBaiKe:webid not find, page end.');
        }
    }
    //context
    {
        var keyWords = '<div class="content">';
        var startIndex = htmlData.indexOf(keyWords);
        if( startIndex > 0 )
        {
            htmlData = htmlData.substring((startIndex + keyWords.length));
            var endIndex = htmlData.indexOf("<!");
            result.context = htmlData.substring(0, endIndex);
            //alert('QiuShiBaiKe:context-' + result.context);
        }
    }
     
    //pic_url
    {
        var keyWords = '<a href="/article/' + result.webid + '" target="_blank">';
        var startIndex = htmlData.indexOf(keyWords);
        if( startIndex > 0 )
        {
            htmlData = htmlData.substring((startIndex + keyWords.length));
             
            //get sub
            keyWords = '<img src="';
            startIndex = htmlData.indexOf(keyWords);
            if( startIndex > 0 )
            {
                htmlData = htmlData.substring((startIndex + keyWords.length));
                var endIndex = htmlData.indexOf('" alt="');
                result.pic_url = htmlData.substring(0, endIndex);
                //alert('QiuShiBaiKe:pic_url-' + result.pic_url);
            }
        }
    }
     
    //read_count
    {
        var keyWords = '<span class="stats-vote"><i class="number">';
        var startIndex = htmlData.indexOf(keyWords);
        if( startIndex > 0 )
        {
            htmlData = htmlData.substring((startIndex + keyWords.length));
            var endIndex = htmlData.indexOf("</i>");
            result.read_count = htmlData.substring(0, endIndex);
            //alert('QiuShiBaiKe:read_count-' + result.read_count);
        }
    }
     
    retVal.items.push(result);
}
 
return;

}

function getJoyContextList( url, parametersString )
{

var parameters = eval("(" + parametersString + ")");
var requestParams =
{
    method: 'GET',
    version: 'HTTP/1.1',
    headers: {},
    scriptParamaters: parameters
};
requestParams.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11';
requestParams.headers['Host'] = 'www.qiushibaike.com';
requestParams.headers['Connection'] = 'keep-alive';
requestParams.headers['Accept-Encoding'] = 'gzip, deflate, sdch';
requestParams.headers['Accept-Language'] = 'zh-CN,zh;q=0.8,en;q=0.6';
requestParams.headers['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8';
 
for(var i = index; index <= endIndex; index++)
{
    var trueUrl = webUrl + index;
    var httpRspString = syncHttpRequest(trueUrl, JSON.stringify(requestParams));
    var httpRsp = eval("(" + httpRspString + ")");
    if( !httpRsp || httpRsp.statusCode != 200 )
    {
        alert('QiuShiBaiKe: Request trueUrl(' + trueUrl + ') failed return code:' + (httpRsp ? httpRsp.statusCode : 'undefined'));
        return JSON.stringify(retVal);
    }
     
    var htmlData = httpRsp.data;
    getJoyFromOnePage(htmlData)
}
 
retVal.success = true;
return JSON.stringify(retVal);

}

功能描述:

主账号能输入物料信息(入库),子账号能输出物料信息(出库)。

显示入库和出库的记录。

显示当前剩余物料信息,并导出至excel

开发计划:

1、搭建JAVA SSH开发环境,完成简单的数据库注册 DEMO,并发布。–ok

2、设计数据库表。 ——–ok

3、设计功能及WEB操作界面 ——–ok

4、开发各个功能界面

a、站点管理修改 ———ok

b、物料分类管理 ———ok

c、代码整理 ——ok

d、用户与骑士站点对应关系 ——-ok

e、库存管理 ———-ok

f、BD 申请 ———-ok

g、站长批阅 ———-ok

h、管理员批阅 ———-ok

5、打包发布 ——-ok http://192.157.227.154:8080/Stock

6、测试程序。

a、逻辑优化

b、代码优化

名称:

双色球中奖邮件通知

功能:

1、每个开奖日后第二天以邮件方式通知是否中奖。

思路:

1、使用Python,跨平台,三方库功能强大

2、从网页上爬取当前的开奖号码 http://cp.360.cn/kj/ssq.html?agent=700007

3、与自己填写的号码检测是否匹配中奖

4、判断后发送邮件通知

5、每周2、4、7开奖,则每周3、5、1凌晨1点(可修改为上午十点最好)判断并发送。

-- coding: UTF-8 --

import smtplib
import urllib2
import string
import datetime
import time

from email.mime.text import MIMEText

from email.MIMEText import MIMEText
from email.Header import Header

我的号码

my_code_six = [1, 4, 8, 15, 17, 28]
my_code_one = 3

网页地址

web_url = "http://cp.360.cn/kj/ssq.html?agent=700007"

彩票开奖内容

lottery_date = ""
lottery_code_six = []
lottery_code_one = 0

号码匹配

winning_red_count = 0;
winning_blue_count = 0;

mailto_list=";"
mail_host="" #设置服务器
mail_user="" #用户名
mail_pass="" #口令
mail_postfix="163.com" #发件箱的后缀

def send_mail(to_list,sub,content):

global mailto_list
global mail_host
global mail_user
global mail_pass
global mail_postfix
     
me="中大奖"+"<"+mail_user+"@"+mail_postfix+">" 
msg = MIMEText(content,_subtype='plain',_charset='gb2312')  
msg['Subject'] = sub  
msg['From'] = me  
msg['To'] = to_list
try:  
    server = smtplib.SMTP()  
    server.connect(mail_host)  
    server.login(mail_user,mail_pass)  
    server.sendmail(me, to_list, msg.as_string())  
    server.close()  
    return True 
except Exception, e:  
    print str(e)  
    return False 

def check_lottery():

global lottery_date
global winning_red_count
global winning_blue_count
global lottery_code_six
global lottery_code_one
global my_code_one
global my_code_six
global web_url
 
winning_red_count = 0
winning_blue_count = 0
 
response = urllib2.urlopen(web_url)
html = response.read()
#print html
 
#date
key = "option value='"
nPos = html.index(key)
if nPos <= 0:
    return 0
html = html[nPos + len(key) : nPos + len(key) + 37]
print 'GET NEW RESULT:   ' + html
nPos = html.index("'")
if nPos <= 0:
    return 0
     
lottery_date = html[0 : nPos]
#print lottery_date
 
#first code
key = "code='"
nPos = html.index(key)
if nPos <= 0:
    return 0
html = html[nPos + len(key) : ]
nPos = html.index(" ")
if nPos <= 0:
    return 0
first_code = html[0 : nPos]
#print first_code
html = html[3 : ]
#print html
 
#second code
key = " "
nPos = html.index(key)
if nPos <= 0:
    return 0
 
second_code = html[0 : nPos]
#print second_code
html = html[3 : ]
#print html
 
#three code
key = " "
nPos = html.index(key)
if nPos <= 0:
    return 0
 
three_code = html[0 : nPos]
#print three_code
html = html[3 : ]
 
#four code
key = " "
nPos = html.index(key)
if nPos <= 0:
    return 0
 
four_code = html[0 : nPos]
#print four_code
html = html[3 : ]
 
#five code
key = " "
nPos = html.index(key)
if nPos <= 0:
    return 0
 
five_code = html[0 : nPos]
#print five_code
html = html[3 : ]
 
#six code
key = "+"
nPos = html.index(key)
if nPos <= 0:
    return 0
 
six_code = html[0 : nPos]
#print six_code
html = html[3 : ]
 
#one code
key = "'"
nPos = html.index(key)
if nPos <= 0:
    return 0
 
one_code = html[0 : nPos]
 
lottery_code_six.append(first_code)
lottery_code_six.append(second_code)
lottery_code_six.append(three_code)
lottery_code_six.append(four_code)
lottery_code_six.append(five_code)
lottery_code_six.append(six_code)
 
lottery_code_one = string.atoi(one_code)
 
for lottry_code in lottery_code_six:
    for my_code in my_code_six:
        if string.atoi(lottry_code) == my_code:
            winning_red_count = winning_red_count + 1
            break
if my_code_one == lottery_code_one:
    winning_blue_count = 1
    print "ok"
 
print my_code_one
print one_code
 
need_send_email = 0;
#blue more than 1
if winning_blue_count >= 1 :
    need_send_email = 1
     
#red more than 4
if winning_red_count >= 4:
    need_send_email = 1
     
print need_send_email
return need_send_email

def check_date():

date_vaule = datetime.datetime.now().weekday() + 1
print 'date_vaule:' + str(date_vaule)
if ((date_vaule != 1) and (date_vaule != 3) and (date_vaule != 5)):
    return 0
     
hour = time.strftime("{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}H", time.localtime()) 
minute = time.strftime("{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}M", time.localtime()) 
print 'hour:' + hour + '. minute:' + minute
if string.atoi(hour) != 1 or string.atoi(minute) != 0:
    return 0
 
print 'date_vaule:' + str(date_vaule) + '.hour:' + hour + '.minute:' + minute
return 1
 

if name == '__main__':


while True:
    if check_date() <= 0:
        print 'do noting'
        time.sleep(40)
         
    else:
        print "It's time to check lottery!!"
        result = check_lottery()
        print result
         
        send_message = "您的号码:"
        for my in my_code_six:
            send_message += str(my) + ","
        send_message += ":" + str(my_code_one) + "    "
         
        send_message += "开奖号码:"
         
        for lottery in lottery_code_six:
            send_message += str(lottery) + ','
        send_message += ":" + str(lottery_code_one)
         
        print send_message

        head = ""

        if  result > 0:
            head = "恭喜您中奖了,去看看吧"
             
        else :
            head = "下次一定能中的"
        print head

        if send_mail(mailto_list,head, send_message):  
                print "Send email ok" 
        else:  
            print "Send email faile"
        time.sleep(70)