摘要: 今天在G+发现一个帖子(https://plus.google.com/u/0/114741495643730382543/posts/HWDJ5jrwuXW),很有意思,只有一行,但是实现了一个一般要循环3次的功能,这一行神奇的代码如下:>>> [''.join(l) for l in [list(t) for t in list(itertools.product(*[['m','p'], ['a','e'], ['n','t','w']]))] 阅读全文
posted @ 2014-01-12 21:46 jaw-crusher 阅读(313) 评论(0) 推荐(0)
摘要: 上次一个朋友问的两列布局,半天没搞定,其实他的html没写好,当然我写的也不咋样,哈哈,今天有空再做一个两列布局,参考糯米团的样子:html: 两列布局实例 [2店通用]XX影城 单人影票!可升级套餐,黄金大片,超强视听感觉,惊爆你的眼球! ... 阅读全文
posted @ 2014-01-12 19:25 jaw-crusher 阅读(237) 评论(0) 推荐(0)
摘要: 学习网络编程,调试各种连接和数据很麻烦,也有很多现成工具可以使用,不过还是喜欢再造个轮子来自己玩玩.header.h 定义了IP和TCP包头格式:#include #include #include #include #include #include #include #include #include #include /* 定义TCP和IP的包头格式*//* IP header */struct ip { u_char ip_vhl; /* version > 2 */ u_char ip_tos; ... 阅读全文
posted @ 2014-01-12 16:24 jaw-crusher 阅读(1862) 评论(0) 推荐(0)
摘要: 常用:复制为ctrl-shift-c粘贴为ctrl-shift-vtab=补全ctrl+a=开始位置ctrl+e=最后位置ctrl+k=删除此处至末尾所有内容ctrl+u= 删除此处至开始所有内容Ctrl-L -刷新屏幕Ctrl-C -杀死当前任务较完整:窗口操作:Shift+Ctrl+T:新建标签页Shift+Ctrl+W: 关闭标签页Ctrl+PageUp:前一标签页Ctrl+PageDown:后一标签页Shift+Ctrl+PageUp:标签页左移Shift+Ctrl+PageDown:标签页右移Alt+1:切换到标签页1Alt+2:切换到标签页2Alt+3:切换到标签页3Shift+C 阅读全文
posted @ 2014-01-10 15:17 jaw-crusher 阅读(190) 评论(0) 推荐(0)
摘要: 用一个简单的实例说明一下left join, right join, inner join,建立两个表,使用mysql做一下关联实验:create_db.sql:create database small_product;use small_product;create table `product` ( `id` int(10) unsigned NOT NULL auto_increment, `amount` int(10) unsigned default NULL, PRIMARY KEY (`id`)) ENGINE=MYISAM AUTO_INCREMENT=5... 阅读全文
posted @ 2014-01-08 16:33 jaw-crusher 阅读(311) 评论(0) 推荐(0)
摘要: 一个echo服务器和客户端的实例,基本照着书抄的.如果用过socket写过类似最简单东西应该很好理解,没写过的话就不好办了。不过要是想深入了解一下twsited框架还是需要了解很多东西,比如异步,多线程等等,慢慢深入吧,不然,只能做一些很简单无法用于生产的Echo。EchoServer And Client.EchoServer.py:from twisted.internet import protocol, reactorimport sysclass Echo(protocol.Protocol): # re-write the dataReceived method def... 阅读全文
posted @ 2014-01-06 20:50 jaw-crusher 阅读(339) 评论(0) 推荐(0)
摘要: 据说是外国某个公司的题目。那么这一坨代码到底是啥呢?g = lambda x,y: lambda x: (-1 / y)* x + y先print g, 原来是一个函数对象。那么试试 g(0, 1)还是一个对象。好吧,把它改造一下:def otter_function(x, y): def inner_function(x): return (-1 / y) * x + y return inner_function这样就比较好看了,然后加个函数参数,调用一下.def otter_function(x, y): print locals() def inn... 阅读全文
posted @ 2013-12-29 16:58 jaw-crusher 阅读(171) 评论(0) 推荐(0)
摘要: 可以使用列表解析+count简单实现:def get_ele(alist): return [i for i in alist if alist.count(i) == 2][0]print get_ele([1,2,3,-1,-1])一个列表中只有一个数字出现了一次,其他都出现了两次,可以这么写, 利用异或运算的性质:get_once_ele = lambda alist: reduce(lambda a,b: a ^ b, alist)print get_once_ele([2, 2, 1, 1, 4])print get_once_ele([1, 1, 0, 2, 3, 2, 3]... 阅读全文
posted @ 2013-12-29 16:07 jaw-crusher 阅读(347) 评论(0) 推荐(0)
摘要: 1. Roman numerals将阿拉伯数字转成罗马数字,可以这样写,不过不是很高效:def checkio(num):a_num = range(1, 11) + [50, 100, 500, 1000]r_num = ('I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X',\'L', 'C', 'D', 'M& 阅读全文
posted @ 2013-12-26 20:26 jaw-crusher 阅读(927) 评论(1) 推荐(1)
摘要: 小屁孩日记3里的牛奶歌挺有意思的,和99个瓶子差不多,使用Python实现一下:# -*- coding: utf-8 -*-# 小屁孩日记3 牛奶歌 哈哈from sys import exitclass Song: def __init__(self, num_of_bottles): self.bottles = num_of_bottles def zero(self): return self.bottles == 0 def take_one_down(self): if self.bottles != 0: ... 阅读全文
posted @ 2013-12-21 14:32 jaw-crusher 阅读(427) 评论(0) 推荐(0)