Alibaba Cloud SDK for Python
truepy - Python library for generating TrueLicense licenses
Scrapy/w3lib - lib for html parsing in scrapy spider framework
Flask/Jinja - template engine for python
Tonado - Python high performace web framework
KafkaOffsetMonitor - Montior tool for Kafaka
fmdb - Object-C wrapper for SQLite
TouchXml - iOS port of NSXMLDocument (XML parser)
Formalchemy - HTML form generation framework by Python
bat
版本。其中一项需求是要生成一个日志文件,文件后缀是当前系统时间的字符串’yyymmddMMHHSS’这种格式的,
所以需要取到当前时间并格式化。
在 Linux 中,这是一个很简单的需求,直接使用 date +'%y%m%d%H%M%S'
就可以拿到,但是在 Windows
中就非常麻烦了。
在 Windows 中,最直接的想法是和 Linux 类似,使用 date /t
和 time /t
命令来获取,然后利用%date:~0,4%
来取到年份(%:~0,4%
是 bat 取子字符串语法,表示取 0 到 4 个字符,前开后闭),
其他分别取到月、日、小时、分钟和秒,最后组合。完整的例子如下.
%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%
这个例子基本上是可以工作的。但为什么说“基本上”?因为这个方法只能适用于部分系统,没有考虑区域(locale)。
由于 Windows
有区域和格式设定,所以 date
和 time
命令显示出来时间格式是经过格式化的,换
句话说,不同的区域由于设置的时间格式不同,返回的格式串就不同。比如中国/中文,经常使用 2020-02-02
这种格式,而欧美/英文,经常使用 02/02/20
这种格式。所以上面那个在英文系统下,多半显示不对。
也在网上找了些例子,有些考虑到了不同的格式,但也是用 date
各种判断拼凑出来,也有提到
直接访问 CMOS 硬件 clock 的方法,都是非常麻烦,不太适用于写短小的bat
批处理文件。
最终,找到了一个比较好的办法,那就是利用 WMI
的接口来直接获得时间。说说它比“比较好”的原因是
因为 WMI
的接口不一定每个机器都有,这个命令也是处于deprecated
即将退休的状态。
1 | @echo off |
此外,利用 PowerShell
也是一个比较好的办法,问题同样是可能有些机器没装。如果想处理时区信息,
可以使用 tzinfo
命令。
总之,根据自身需求和环境,选择合适的方法。
– END –
]]>Flask
template.If use an dash “-“ linked variable name in Flask template, it will cause Flask to hang without
throwing any exception.
At beginning, I guess it may be an issue of Jinja
template rending. But after traced in IDE
(Pycharm community 2019.3), I saw that templating raised the exception and Werkzeug
is handling.
At first I uses Flask debug mode and IDE debug run to step into codes to dig it. IDE gets
slower and slower and the debugger hung in Werkzerg
codes.
Eventually, I found an endless loop in Python\Lib\traceback.py
to walk trackback stacks. The
trackbacks are stored in a link which nodes point to next. In flask\templating.py
,flask\app.py
and werkzeug\debug\tbtools.py
, the exception was catched. Inhandle_exception()
of flask\app.py
, Werkzeug
wants to log it and print it out.
The trackback link has looped reference as below picture.
Simple code to re-produce it as below (“font-size” variable caused.).
1 | import sys |
Raised Github issue at Flask
:
Environment:
Possible related Python issue:
– END –
]]>mermaid
markdown
撰写 流程图,时序图,甘特图,类图 等各种(简直神器)。以下就分别介绍如何在VSCode, Hexo 以及 Hugo 中安装设置来支持 mermaid
.
在 VSCode 中安装插件 Markdown Preview Mermaid Support
,
就可以在编辑时实时预览 markdown
中的 mermaid
图形了,图形编写使用 ``` 包围,并以 mermaid
作为语言标签。
例如(:
1 | ` ` `mermaid |
如图所示:
Hexo 默认是不支持 mermaid
的,需要添加插件支持,在你的 Hexo Blog 目录下,输入命令:
1 | npm install --save hexo-filter-mermaid-diagrams |
此外,如果使用的主题支持mermaid
,需要在所用主题的 _config.yml
中开启 mermaid
支持:
1 | # Mermaid (markdwon to flow chart, seq chart, class chart ...) |
*请稍等一段时间,以下代码会变为SVG流程图*
graph TD; A-->B; A-->C; B-->D; C-->D;
memaid
支持最简单的办法,利用mermaid
官方CDN,直接在 ${blog}\themes\tranquilpeak\layout_partial\script.ejs
中修改,文件最后增加两行如下
1 | <script src="https://unpkg.com/mermaid@8.4.6/dist/mermaid.min.js"></script> |
如果希望这个主题能支持更多配置,可以在主题的 _config.yml
中增加 mermaid
配置:
1 | # Mermaid (markdwon to flow chart, seq chart, class chart ...) |
然后在 ${blog}\themes\tranquilpeak\layout\_partial\script.ejs
中修改,文件最后增加:
1 | <% if (theme.mermaid.enable) { %> |
其中 theme.mermaid.enable
theme.mermaid.theme
就是你增加的主题配置选项,具体
详见 mermaid
官方文档。
最后,可以将 mermaid.min.js
放到主题的js目录 ${blog}\themes\tranquilpeak\source\assets\js\
下,
再使用如下技巧,当 CDN 出问题时,可以使用本地文件。
1 | <!-- if CDN fails, use local file --> |
to be written理论上和 Hexo 类似,待写
— END —
]]>az
来部署生成到网站.az
很方便,但是也有些缺点,例如会把整个网站全部重新上传一遍,速度慢不说,还浪费多次blob
的操作。后来找到了另外一个工具rclone
(下载、安装、文档,或使用各平台包管理器安装),
它可以像rsync
一样同步本地和远端文件,只更新变化过的文件。
使用起来也很简单, 首先新建一个远端配置rclone config
,根据提示,输入名字,类型,account 或者
connection string。例如,我配置 azure-chen
这个名字(本地名称)对应 azure 上 chen
这个 blob 账号。
然后就可以使用了:
1 | # 列出远端容器 |
这样,就可以把远端有,而本地没有到删除,而本地新增到也会复制到远端,减少了很多IO。
另外,还有两个GUI工具(for macOS):
Rclone Browser 略微有点小问题, 并至今有2年没更新了,需要自己查issues解决。
— END —
]]>_所有静态网站都可用采用此方法_
之前,个人博客一直都是用 Hexo
生成并部署为 GitHub Pages
。
最近知道,因为百度的爬虫太频繁而被 GitHub 屏蔽了,所以所有部署在 GitHub 上的网站都没有收录。
不深究这个理由是否靠谱,得给博客换个地方了。
手头有 Azure 和 Vultr 的 VPS,但考虑到部署静态网站到 VPS 有点大材小用,而且需要部署 HTTP
Server 防火墙,FTP/Rsync/SSH 等等挺麻烦,就寻思着是不是能用对象存储来做。于是翻看了 Azure
Blob 到文档,发现真还行,而且还挺简单,内置支持。
首先新建全局唯一的存储账号,比如我选则了 chen
,这个会作为你 Azure 存储的一个 End
Point,比如 chen.blob.core.windows.net,可以直接通过这个域名来访问你的存储对象。这个时候
要注意一点,一定要选择 StorageV2 (通用版 v2)
类型,只有这个类型才支持直接部署静态网站。
我之前就是选择了 v1
类型,导致无法自动识别 index.html
而无法访问。建好后,选择静态网站
菜单并 启用,系统会自动生成名为 $web
的 容器(Container)
,作为存储网站的根目录。
以上配置完成后,就用 hexo generate
命令生成你的网站,网站生成后都在 public
目录
下,这些不细说。然后需要做的是把生成的网站传到刚建立到容器 blog
中,有几种方法可以做到:
存储资源管理器
中上传存储资源管理器
桌面版,上传AzCopy
上传 (需要.net)az
前面2种方法都很简单,找到相应位置或者下载软件就行了,第3个需要.net,不足够通用,我使用到是第4种
方法,简单写了个脚本,每次自动上传,主要是下面这句,其他都省略了:
1 |
|
然后就可以用 https://chen.z?.web.core.windows.net
(?是某个数字,z? 代表一个地区)
访问你的网站了。
安装 Azure Client 的步骤就不写了,直接看文档。安装好后,记得运行 az login
登录。
最后,如果你有自己的域名,可以选择 自定义域
来配置,同时要配置 DNS.
这种方法非常简单,费用也很低,基础 1G 才大概几美分。不过有一点不好的是,v2
类型的 blob 存储
还有存取访问计费,每万次也有几~几十美分,而 Hexo 生成的静态网站文件很多,一次上传就得几百上千
个文件,而且只要改配置或者模版,文件就都大多数都修改了,得全部上传。
Azure Blob 部署的静态网站,如果用 windows.net
访问,是自带 https
的,如果你需要给
自定义域名也用上https,需要配置 CDN
。而且,CDN
会自动选择不同的地区访问,blob 是固定
地区的(比如 blob 账号、容器是在 美国东部 US-EAST,那么亚洲访问就稍慢)。
– END –
]]>So far we have 2 kinds of data need to be encrypted: one is the Alicloud key and secret of customers, the other is the marked sensitive variable or parameters such as VM password. Vault provides several secrets engines to achieve these.
Vault has a secret engine named AliCloud. But it can only manage one account with configuring a pair of its key and secret in a single path. It can only manage the policies of this account. Which means if we want store multiple customer AliCloud accounts, we need to define multiple paths in Vault for each account and configure key/secret pairs for each account manually. It’s no sense. So it’s not useful for us.
Above all, we could only use the Key/Value
secrets engine.
We define some configurations for using Vault.
ENCRYPTION_METHOD
- to identify which method will be used. VAULT
for HashiCorp vault. AES
for encryption with AES algorithm and store in DB. ENCRYPTION_METHOD = “VAULT” | “AES”
VAULT_KV_PATH
- Vault path is related to secrets engine. This need to defined from architecture level so that all components which uses Vault will follow it. And avoid namespace conflict. By default, the base path for Key/Value
engine is “kv”
. e.g. VAULT_KV_PATH = “kv/cpsapi”
“**$:AES:$**qowzobv1GoC8tB7dOrHJpA==PXyKO2kLX6C4oD8a+e5BlMQwD2q8vvu3poI5rishmVM=”
. If data encrypted by Vault, the encrypted data will not be stored in DB. So that it will only remains “$:VAULT:$”
encrypt/decrypt
were created. In them, we automatically check which methods will be used and apply it. If the ENCRYPTION_METHODS
was changed after the system runs for some while, we may be facing some data was encrypted by AES but now the decryption method is VAULT. For this scenario, we have 2 choices:In Alicloud API project, we have some sensitive data such as secret key, vm password and so on stored in database. To avoid store plain text, we need a solution to encrypt and decrypt sensitive data.
Systems that provide ability to store sensitive key/token/password. Encryption and decryption will handled by the system.
IDM
Valut
Need to involve a new system and maintain it.
Reversible character encoding algorithms. Same algorithm will be used for encryption and decryption.
Easy to be decode.
Irreversible algorithm. Not appropriate for us.
Reversible algorithm. Plaint text (data) is encrypted or decrpyted with given private key (shared secret) with same algorithm. https://en.wikipedia.org/wiki/Symmetric-key_algorithm
Need to share the private key.
Reversible algorithm. Plaint text (data) is encrypted with public key. The encrypted data is decrypted only with private key. The public key can be openly distributed without compromising security. Encryption and decryption in different way. https://en.wikipedia.org/wiki/Public-key_cryptography
Maturity | Security | Speed | Load | Comment | |
---|---|---|---|---|---|
DES | High | Low | Medium High | Medium | |
AES | High | High | High | Low | Replacement of DES |
RSA | High | High | Low | High | plaint text can not longger than key |
DSA | High | High | Low | Only for digital signature. | |
ECC | Low | High | High | Low |
Above all, we better choose Symmetric encryption AES. And AES is faster and lower load compares to RSA.
The database server and application server are behind the firewall. And they are in private network. This ensures the architecture level security.
Stores in OSS or shared NFS with authorization. Read when application started (only in memory).
Encrypt it before saving. Decrypt it after loading.
Encrypt it before saving. Decrypt it after loading.
]]>注意请先断电
钟表手机维修用的十字起子 锥头型号 PH000 用来开外壳以及绝大部分螺丝.
网上有些文章说PH00,PH0甚至一般十字起子,这些都不对,大了容易伤螺丝。
另外如果要把SSD固态硬盘放到HDD机械硬盘位,那么需要拆掉机械硬盘,这个时候会用到。
网上说的一般是T5,这个应该可以,但我用的是T6,也合适。
市面上一般有两种厚度,9.5mm 和 12.5mm (也有相差零点几个毫米的),要选择薄的9.5mm这种。
接口要选择SATA 3.0,这款2012年中13寸的MacBook Pro支持SATA 3.0。
最好选择专门为MacBook Pro设计的,我在挑选的时候发现这种好像比普通的在外延多两个螺丝孔,
后面安装的时候会发现这个是必须的固定位。
商家有些会送螺丝,或者固定胶条和胶钉,视情况选择,我感觉胶条和胶钉比较好。
该款机型内置的是2条1600海士力DDR3内存,电压为标准压1.5v,所以不能买1.25v低电压内存。
因此我选购了金士顿的标准压8G-1600单条,毋需买同品牌同大小的内存,频率相同即可,可以节省一条。
频率选择不同的应该也可以,但应就高不就低,也就是说高于1600应该是可以的。
装好后配置为10G,使用中没发现什么问题。
安装也很简单,两边的卡子轻推就会自动弹出,插好新的后下压可卡住,网上很多教程。
选择很多,比如三星Samsung EVO860等等,我选择了东芝Toshiba TR200。
无他,因为之前用过,还便宜。几个月之前买是380RMB,前两天双11买是236.
支持SATA3,SSD固态硬盘可以达到6G速度。
安装之前要想好是装在光驱位还是机械硬盘位。我建议放到光驱位,原因如下:
具体安装过程网上很多教程,我发现有两篇英文的最准确,每个步骤都有,而其他的教程基本上都省略了很多步骤,
拆喇叭,摄像头等线的基本都没介绍,这几个步骤很关键。具体步骤不细说,先拆电源接线,小心即可。
首先做好备份, 方法很多,time machine, 移动硬盘复制,网盘,等等。需要转移整个系统的就用time machine,
全新安装系统的就备份自己需要的文档和数据。
系统安装有几种方式:
我使用的是最后这种,比较保险,而且可以选择需要等版本。
当时准备了3个版本:Sierra,High Sierra,Mojave。很快就放弃了Sierra,因为High Sierra是其升级且更稳定版本,
估计性能差不多,High Sierra应该更好。Mojave考虑不太敢装,6年前的机器,怕跑不动。
另外还有一个就是Recover的EI Captain,这个还是用的 Macos 文件系统,而上面准备的三种,都升级到了APFS文件系统。
APFS是Apple专门为SSD打造的系统,比较新,只经历了2个版本,不知道稳定性如何。
最终选择的是Mojave,因为全新安装,打算试试,如果性能太差就抹掉再安装High Sierra。
后面使用发现这个选择是正确的,虽然Mojave还是第一个版本,但稳定行还不错,而且经过内存升级和更换SSD后,性能也还能接受。
系统安装好后,自动会使用SSD启动(即使在光驱位),几天运行良好,因此我决定抹掉机械银盘
(HDD使用macos 不区分大小写日志文件系统),将其作为数据盘。
但恢复分区没有抹掉,里面有EI Captain的恢复镜像,保留以备将来有用。
因为使用SSD固态硬盘,系统安装好之后,需要配置一下更适合固态硬盘。
固态硬盘特性是寿命有限制,那么我们需要做这么几件事情来优化
关闭rootless
Rootless 具体是什么网上很多,简单说就是限制root的权限来确保系统目录或文件的安全。
有些文章说开启TRIM可能需要关闭rootless,我在开启TRIM时发现不需要,这个因系统而异。
如果后面要移动一些系统目录(比如HOME),或者做开发,也最好关闭。
步骤 :
* 重启并按住command+r 进入恢复模式* 选择命令行工具,输入`sudo csrutil disable`* 需要重启。
开启Trim。
Trim是一种均衡固态硬盘读写的技术,使得写入不会总在一个地方。非Apple内置SSD不会自动开启Trim,需要自行开启。
使用命令 sudo trimforce enable
, 然后确认即可,可能重启。早期版本比如Yosimate可能需要重置 NVRAM/PRAM,
我是用Mojave没有重置。
移动User Home
为了减少SSD的使用量以及读写消耗,我将个人用户home目录移动到了机械硬盘。
这个目录移动可以在 设置->用户与组->解锁->右键自己用户->高级功能
中修改,然后系统自动移动并重启。
也可以使用命令完成移动整个User目录
$sudo ditto /Users /Volumes/Macintosh\ HD/Users$sudo mv /Users /Users.backup $sudo ln -s /Volumes/Macintosh\ HD/Users Users$sudo rm -rf /Users.backup
移动其他目录
移动临时目录/tmp,因为/tmp是链接到/private/tmp,所以如下:
$ sudo ditto /private/tmp /Volumes/Macintosh\ HD/private/tmp$ sudo rm -rf /private/tmp$ sudo ln -s /Volumes/Macintosh\ HD/private/tmp /private/tmp
修改休眠文件位置 或 关闭休眠
查看休眠配置
$ pmset -g|grep hibernatehibernatefile /var/vm/sleepimagehibernatemode 3
修改休眠文件位置
$ sudo pmset -a hibernatefile /Volumes/Macintosh\ HD/var/vm/sleepimage
关闭休眠
Suspend to RAM ——> 对应的hibernatemode:0;
Suspend to RAM+Disk ——> 对应的hibernatemode:3
Suspend to Disk ——> 对应的hibernatemode:5;
$ sudo pmset -a hibernatemode 0
关闭文件最后访问时间
http://junqiu.lofter.com/post/1d084679_5ef95d0
$ sudo vi /Library/LaunchDaemons/com.nullvision.noatime.plist
编辑为如下内容
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"> <dict> <key>Label</key> <string>com.noatime</string> <key>ProgramArguments</key> <array> <string>mount</string> <string>-vuwo</string> <string>noatime</string> <string>/</string> </array> <key>RunAtLoad</key><true/> </dict></plist>
然后设置权限
$ sudo chown root:wheel /Library/LaunchDaemons/com.noatime.plist$ sudo chmod 644 /Library/LaunchDaemons/com.noatime.plist
重启后,使用命令 mount | grep /
查看,可以看到多了一个noatime
属性
使用前
/dev/disk2s1 on / (apfs, local, journaled)
使用后
/dev/disk2s1 on / (apfs, local, journaled, noatime)
Check Service Discover by Consul for installation of Consul
Fabio is a single file app. You just download the executable for your OS from its release page (https://github.com/fabiolb/fabio/releases) or use brew install fabio
(MacOS) or go get github.com/fabiolb/fabio
(Golang) to download to local. Rename it to fabio
and add executing privilege.
Fabio is zero-conf app. Which means you need almost no configuration. If you deploy it on the machine where you Consul deployed, it will automatically find service and register health check on it (Consul default localhost:8500)
Check the Fabio Wiki: https://github.com/fabiolb/fabio/wiki/Quickstart
Use a tag to identify a service in Consul. It will be recognized as a router.
e.g. the following is a service registry config file.
1 | { |
Note that “tags”: [“propel-/jekins”]
. It means this is a service for Fabio. propel-
is the prefix of tag to identify (which default is urlprefix-
. You can change it by -registry.consul.tagprefix “propel-”
.) /jekins
means the endpoint to the service.
Visit http://myconsul:8500/ and check “service” tab, you will see registered service and the tags.
Visit http://myfabio:9998/, you will see the routers (with red rectangle marked)
At last, visit http://myfabio:9999/jenkins (/${tag}). You will be routed to http://ec4t01624.itcs.entsvcs.net:8080/jenkins .
e.g. my tomcat server at http://ec4t01624.itcs.entsvcs.net:8080/
You need to set the tag with an option strip=/tomcat
. It means the router will strip /tomcat
from url path when routing. See the blue rectangle mark in the above 2nd screenshot (option
column of tomcat). You will see it in Consul
dashboard as below.
Visit http://myfabio:9999/tomcat/. It will route to http://ec4t01624.itcs.entsvcs.net:8080/ . The /tomcat
in url path is removed. (note the last /
is required. Check the source
column in above 2nd screenshot.)
The service registry config file in Consul is:
1 | { |
Just run $ fabio
in terminal.
You may use –help to check the arguments. Or use a fabio.properties
file as configuration.
To run with prefix, $ fabio -registry.consul.tagprefix propel-
TODO
socket too many open files
error. You need to use ulimited -n 65535
to fix it.– END –
]]>重要关键词:Supervised, Unsupervised, Regression, Classfication, Features
机器学习主要分为有监管的(supervised)和无监管(两类).
有监管的基本上分为回归的(regression)和聚类(classfication)两种。
无监管的主要是用来分类。
假如有一件事情来了,如何来区分它适用哪一种方式?我总结了一点。
Feature 是指特征,表现为坐标轴,例如 判断肿瘤一例中的年龄和肿瘤大小就是两个特征。特征数量足够以及合适(并不是多)才能更准确的学习。
– END
]]>It’s a very simple console that only suit for learning Kafka purpose.
Install Play Framework.
Install Kafka-web-console.
Run the server
Configuration
register zookeeper
Check status to see if connected
– DONE
]]>1 | 在后来的实际应用中,了解了更多的方法,这种方法并不是一个比较好的方法,但仍不失为一个简单有效的方法。 |
复制的虚机Mac 地址都是相同的,组网会有问题,所以需要改过来。
首先是修改VM Setting,可以生成一个新的Mac地址,把它记录下来,假设是00:AA:BB:CC:DD:EE
。
网上的方法主要是
sudo ifconfig eth0 down #停掉网卡
sudo ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE #改mac
sudo ifconfig eth0 up #起网卡
sudo /etc/init.d/networking restart #重启网络
/etc/network/if-pre-up.d/
中添加ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE
,但我试过了是不行的。/etc/rc.local
每次启动修改,但这种方法不太爽。复制以后的机器,名字都是一样,打算取名为vm-ubuntu1, vm-ubuntu2, vm-ubuntu3… 所以得逐个修改。
首先 hostname vm-ubuntu2
是不能保存的,重启后又还原,所以得修改/etc/hostname
,内容就一行,vm-ubuntu2
其次,光改了名字,从其他的机器是ping不到的,所以我们需要修改 /etc/hosts
来把所有的机器都列出来。
127.0.0.1 localhost
192.168.48.142 vm-ubuntu1
192.168.48.156 vm-ubuntu2
192.168.48.148 vm-ubuntu3
上面这样做了之后,会有一个问题,就是DHCP重启之后IP会变,名字就失效了,所以需要改成静态IP。
很简单,先 ifconfig 查看一下 当前的 网关和掩码,
Link encap:Ethernet HWaddr 00:0c:29:1f:2a:fc
inet addr:192.168.48.142 Bcast:192.168.48.255 Mask:255.255.255.0
192.168.48.255
, 掩码是 255.255.255.0
,同时可以看到Mac已经变了(HWaddr就是)然后修改 /etc/network/interfaces
就可以了,
auto eth0
iface eth0 inet dhcp
auto eth0
iface eth0 inet static
address 192.168.48.100
netmask 255.255.255.0
gateway 192.168.48.255
auto eth0
iface eth0 inet static
address 192.168.48.101
netmask 255.255.255.0
gateway 192.168.48.2
上面设好了后,内网基本没问题,但是连外网可能会碰到问题,域名解析不了(我碰到了),所以需要设置DNS。
网上的方法,有一种是修改 /etc/network/interfaces
加上 nameserver
auto eth0
iface eth0 inet static
address 192.168.48.101
netmask 255.255.255.0
gateway 192.168.48.2
nameserver 8.8.8.8
/etc/resolveconf/resolve.conf.d/base
,加上 nameserver 就可以了nameserver 192.168.48.2
nameserver 8.8.8.8
nameserver 8.8.4.4
今天,互联网和移动终端,我们都知道,正在改变这个行业,大家或多或少,或清晰或朦胧的感受到、预见到那些正在以及可能产生的变化,也一直在寻找,我也一直在思考,到底会是怎样。也许有一天,只是一只手指,轻轻的触碰到了那一点,刷的一下,就豁然开朗。
一直在思考,究竟我们能改变什么?上面那些变化,都是大的公司,在强有力的支持下做出的(除了facebook),也许一个小公司小团队很难做到,但谁知道呢。
云和端,云很重要,但它实际上是一个载体,就好比互联网,再怎么发展,也是一个工具。而云就是各种业务,应用的一个载体,或许会有一天有天翻地覆的变化,但现在,我能看到的,云是一个很重要的基础设施,要想从这上面想象变化,暂时还没有突破口。
而端,或者说客户端、消费端,由其表现形式,已经能呈现出非常丰富的变化。而最有可能重新定义的就是软件/应用的消费方式。比如,可能是一个冰箱同步你的菜谱并自动调温,可能是一个闹钟同步你的日程还报出内容。手机端,是一种设备,由于各家巨头都看到了,它也是表现能力非常强的一种设备,正在改变人们消费数字产品的方式,从桌面带到了街头。
由于其他的设备的发展还不很明朗,所以我想谈谈手机(平板,智能手持设备)可能的带来的改变。
那么手机有哪些特点?
所以我想说,最重要的是方式的改变。借着手机这么丰富的传感功能,也许我们能探索到一些改变某件事情的方法,将互联网和传统结合,走出点新路。
就拿阅读这件事情来说,什么是阅读?阅读什么?为什么阅读?什么时间阅读?什么位置阅读?什么天气阅读?文字、图片、视频可以阅读大家都知道,但声音能阅读吗?关系能阅读吗?知识能阅读,能力能阅读吗?善恶能阅读吗?阅读能变成游戏吗?阅读能传递吗?无数个想法。Kindle正在改变阅读的载体,阅读的方法呢,也许将来是直接注射的,就好似嫁衣神功一般。
思想风暴,想想看阅读和手机传感结合能有什么方式?
其他的,比如内容的存储,存的越多,手机抖的越厉害。比如有CMS和CRM,为什么不能有RMS,好过现在通讯录。再有,有游戏,有SNS游戏,有MUD,为什么不能有社交关系地理位置的轻游戏或者RMS,比如根据高度差,根据甩手机的重力程度,来攻击,或者不叫攻击叫骚扰,你的朋友(一个同事介绍的LBS游戏给的灵感)。根据通话、短信频率确定关系远近,等等等等。
– 随想。
]]>云端现在是Amazon, Google暂时领先于基础架构领域,MS, Apple 处于追赶之中,Facebook/Twitter则领先于SNS(此SNS含义相当广,包括身份,信用,关系,服务,应用等等)方面。传统厂商如IBM, HP基于其固有的优势,大力推广所谓私有云,实质是企业cluster,在下一代互联网中已经落后一步。
而终端则是Apple,Google 和 MS 三足鼎立。iOS和Android,已经成为了移动领域事实上的领头羊,MS在桌面的固有优势以及家庭媒体中的发力,使其保持在第一梯队中。而HP,虽然购买了3Par, Palm/webos,但依然未能表现出足够的进取。其他厂商,目前看来,只是陪太子读书的角色。
]]>基于python 2.7
sys.setdefaultencoding('utf-8')
(记得需要reload(sys)
) 简单按照这个原则,编码基本上就不会错了。
举个例子,有个GBK编码的文件 name.txt,每行一个人名,现在要处理
for line in open('name.txt').readlines(): print line # 这时候 line 都是 gbk 的 str x = line.decode('gbk') # 转成 unicode #(建议这么做,原则:但凡输入的,一律转换成unicode后处理) print x # 输出 unicode (不建议这么做) print x.encode('utf-8') # 输出 str (建议这么做,原则:但凡输出,一定编码成str) store_to_db(x) # 这时候存的都是unicode my_str = x.encode('big5') # 转成 big5了 print m_str # 输出的是 big5 的 str
此外,encode 的时候不一定会成功,这时候会raise一个exception,这是因为 encode 还有一个参数用来控制encode失败后的处理,default是strict,也就是抛异常。
你可以用 encode(src, 'replace')
来处理,replace就表示碰到转不了的,用问号'?'
来代替,而不是抛异常。
具体用法查文档。
同样,输出的时候,输出流也需要有编码。比如stdout默认是ascii的,而你要输出unicode,就需要得到一个基于unicode的输出流,output = codecs.getwriter('utf-8')(sys.stdout)
– END
]]>
try:web.py code
urls = …
…
app.run()
except Exception, e:
f = None
if os.name == ‘posix’:
f = open(‘/tmp/yule_unhandled_error.log’, ‘w’)
else:
f = open(‘%s/yule_unhandled_error.log’ % os.environ[‘temp’], ‘w’)
traceback.print_exc( file=f )
traceback.print_exc( file=f )
f.close()
import os, sys
python_path = “/you/python/lib/path:/you/python/lib/path2”.split(‘:’)
for path in python_path:sys.path.insert(0, path)
修改 ifmodule 这一节,注意蓝色行
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/icons
RewriteCond %{REQUEST_URI} !^/favicon.ico$
RewriteCond %{REQUEST_URI} !^/static/ ### 注意这一行
RewriteCond %{REQUEST_URI} !^(/.)+code.py/
RewriteRule ^(.)$ code.py/$1 [PT]
是取不到值的。 那么怎么才能在模板中使用呢? 难道非得在每个view中添加到context中吗?答案是否定的。 根据Django文档中所描述, 我们至少有两种方法可以直接使用。 http://docs.djangoproject.com/en/dev/howto/static-files/#referring-to-static-files-in-templates
方法1:
使用 { % load static %}
载入 static 模块,然后使用 { % get_static_prefix %}
就可以了。
{ % load static %}
<img src=”{ % get_static_prefix %}images/hi.jpg” />
当然也可以将其定义为变量以多次使用
{ % load static %}
{ % get_static_prefix as STATIC_PREFIX %}
<img src=”images/hi.jpg” />
<img src=”images/hi2.jpg” />
这个方法是推荐的方法, 直接使用 RequestContext 来传递。 其原因就是因为settings中定义的变量都会在request中传递, 但是response的时候是没有这些context的, 所以Django专门定义了RequestContext来帮你组合 (其实你自己也可以做这件事)。
#注意这里是django.template,由此可见是专门为template设计的
from django.template import RequestContext
def some_view(request):
# ... return render_to_response('my_template.html', my_data_dictionary, context_instance=RequestContext(request))</pre>
这个实际作用就是将request中的context全部都加到response的context中去。
这样,你就可以直接在模板中使用 来使用了,当然其他的变量也是可以的,不需要每个都单独去load了。
这是怎么回事?其原因就是 Django 不处理静态文件,其静态文件管理需要通过配置,让服务器直接访问。同时,在开发环境中,如果你是用manage.py runserver 的方式运行调试,更是麻烦。在网上找了很久,始终也没有一个很全面的解决方案。
自动动手,丰衣足食,参考 Django 官网的介绍,终于解决了。废话不多说,解决方案如下:
开发环境(manage.py)
参考 http://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-development.
网上有很多介绍改这个 MEDIA_ROOT, MEDIA_URL 改那个 STATIC_ROOT, STATIC_URL 的,注意,完全没有必要,开发时,这些都不需要改就可以运行。
MEDIA 是指你上传的文件存放,比如图像,视频,压缩包之类的,而STATIC是你网站运行需要依赖的一些静态文件,比如css, js, template 等等。开发时先不管它们。
然后,打开你网站的 c:/mysite/settings.py ,修改 STATICFILES_DIRS 段
STATICFILES_DIRS = ( 'c:/mysite/static/',)
最好,修改 c:/mysite/urls.py,在 urlpatterns 下面增加一行
urlpatterns += staticfiles_urlpatterns()
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
部署环境
以后试过了再写。
]]>