mkdir1 / blog Goto Github PK
View Code? Open in Web Editor NEWissue blog
issue blog
当url地址含有中文,或者参数有中文的时候,这个算是很正常了,但是把这样的url作为参数传递的时候(最常见的callback),需要把一些中文甚至'/'做一下编码转换。
urllib库里面有个urlencode函数,可以把key-value这样的键值对转换成我们想要的格式,返回的是a=1&b=2这样的字符串,比如:
>>> from urllib import urlencode
>>> data = {
... 'a': 'test',
... 'name': '魔兽'
... }
>>> print urlencode(data)
a=test&name=%C4%A7%CA%DE
如果只想对一个字符串进行urlencode转换,怎么办?urllib提供另外一个函数:quote()
>>> from urllib import quote
>>> quote('魔兽')
'%C4%A7%CA%DE'
当urlencode之后的字符串传递过来之后,接受完毕就要解码了——urldecode。urllib提供了unquote()这个函数,可没有urldecode()!
>>> from urllib import unquote
>>> unquote('%C4%A7%CA%DE')
'\xc4\xa7\xca\xde'
>>> print unquote('%C4%A7%CA%DE')
魔兽
在做urldecode的时候,看unquote()这个函数的输出,是对应中文在gbk下的编码,在对比一下quote()的结果不难发现,所谓的urlencode就是把字符串转车gbk编码,然后把\x替换成%。如果你的终端是utf8编码的,那么要把结果再转成utf8输出,否则就乱码。
可以根据实际情况,自定义或者重写urlencode()、urldecode()等函数。
转自大牛
好久没用svn了,今天出现这个问题,svn:remains in conflict,真是无法解决
其实我原因还是没找到
svn remove --force yourfilename
svn resolve --accept=working yourfilename
svn commit -m ""
再svn up
javacript
中有一个var av = navigator.appVersion.toLowerCase() || '';
这里可以判断对应的平台
每个id对应的元素,用下面的方法:
var id = document.getElementById('id');
var href = id.href;
var text = id.innerHTML;
如果还有其它元素,也一样
<html>
<body>
<div id="an">
<a id="desktopClient" target="_blank" hidefocus="true" href="http://githbu.com" title="test">desktop</a>
</div>
<script >
(function (){
var av = navigator.appVersion.toLowerCase() || '';
var is = {};
var dictClientEle = document.getElementById('desktopClient');
var href = dictClientEle.href;
var text = dictClientEle.innerHTML;
is.mac = /mac/i.test(av);
is.win = /win/i.test(av);
is.ipad = /ipad/i.test(av);
is.linux = /linux/i.test(av);
is.iphone = /iphone/i.test(av);
is.android = /android/i.test(av);
if (is.win) {
href = "http://163.com";
text = "windows"
} else if (is.mac) {
if (is.iphone) {
href = "http://163.com";
text = "iphone"
} else if (is.ipad) {
href = "http://163.com";
text = "ipad"
} else {
href = "http://163.com";
text = "Mac"
}
} else if (is.linux) {
href = "http://163.com";
text = "Linux"
} else if (is.android) {
href = "http://163.com";
text = "Android"
}
dictClientEle.href = href;
dictClientEle.innerHTML = text;
})();
</script>
</body>
</html>
用的是centos,这个系统不是很熟悉
本来是想把svn项目转化成git,但.svn目录删除有点麻烦
后来才发现,一句shell语句的事
find . -type d -name ".svn"|xargs rm -rf
之前处理mysql没有涉及到中文,故对此无所用心.今于此耗时逾一日,算是小有收获
mysql上字段存储中文
-1. 在`python源文件头添加
reload(sys)
sys.setdefaultencoding('utf8')
或听信网上一种方法:
File "getAnswer.py", line 12, in <module>
sys.setdefaultencoding('gb2313')
LookupError: unknown encoding: gb2313
以上前徒劳,最后解决方案:
self.cursor.execute("DROP TABLE IF EXISTS answer")
create_answer_sql = '''CREATE TABLE answer(
question_id varchar(30) NOT NULL,
question text(300) NOT NULL,
answer_id varchar(30) NOT NULL,
answer text(3000) NOT NULL
)DEFAULT CHARSET=utf8'''
即在创建数据表时,设置为utf8
因为mysql默认的编码是latin1,所以,当是ascii码时,是没问题的,当字符是utf8时,在mysql中无论如何是无法正确显示成中文的,只能是把table的编码也设置成utf8
还有就是,当python文件首项设置成'utf8'时,得到的就是这个编码,就可以直接存储到mysql中
show create table answer
niwenxian.xyz
已将该虚拟机配置为使用 64 位客户机操作系统。但是,无法执行 64 位操作。
此主机支持 Intel VT-x,但 Intel VT-x 处于禁用状态。
如果已在 BIOS/固件设置中禁用 Intel VT-x,或主机自更改此设置后从未重新启动,则 Intel VT-x 可能被禁用。
(1) 确认 BIOS/固件设置中启用了 Intel VT-x 并禁用了“可信执行”。
(2) 如果这两项 BIOS/固件设置有一项已更改,请重新启动主机。
(3) 如果您在安装 VMware Workstation
之后从未重新启动主机,请重新启动。
(4) 将主机的BIOS
固件更新至最新版本。
解决办法:
bios
中将虚拟化设置为可用。Intel Virtualization Technology
设置为enable
解决
如何取一文本文件中随机行
shuf -n5 main.txt
shuf
命令sort -R main.txt | head -5
awk -vN=5 -vC="`wc -l file`" 'BEGIN{srand();while(n<N){i=int(rand()*C+1);if(!(i in a)){a[i]++;n++}}}NR in a' file
while read line;do echo "$line $RANDOM";done < main.txt | sort -k2,2n| awk 'NR<=5{print $1}'
每个bean都有一个或多个id(或称之为标识符或名称,在术语上可以理解成一回事),这些id在当前IoC容器中必须唯一。
当然也可以为每个bean定义一个name,但是并不是必须的,如果没有指定,那么容器将为其生成一个惟一的name。对于不指定name属性的原因我们会在后面介绍(比如内部bean就不需要)。
bean的命名采用标准的Java命名约定,即小写字母开头,首字母大写间隔的命名方式。如accountManager、 accountService等等。
对bean采用统一的命名约定将会使配置更加简单易懂。而且在使用Spring AOP,这种简单的命名方式将会令你受益匪浅。
一个Bean要提供多个名称,可以通过alias属性来加以指定 ,示例如下:
<alias name="fromName" alias="toName"/>
当采用XML描述配置元数据时,将通过元素的class属性来指定实例化对象的类型。class属性主要有两种用途:在大多数情况下,容器将直接通过 反射调 用指定类的构造器来创建bean(这有点等类似于在Java代码中使用new操作符);在极少数情况下,容器将调用类的静态工厂方法来创建bean实例,class属性将用来指定实际具有静态工厂方法的类(至于调用静态工厂方法创建的对象类型是当前class还是其他的class则无关紧要)。
用构造器来实例化Bean ,前面的实例就是
采用静态工厂方法创建bean时,除了需要指定class属性外,还需要通过factory-method属性来指定创建bean实例的工厂方法,示例如下:
<bean id="exampleBean"
class="examples.ExampleBean2"
factory-method="createInstance"/>
使用此机制,class属性必须为空,而factory-bean属性必须指定为当前(或其祖先)容器中包含工厂方法的bean的名称,而该工厂bean的工厂方法本身必须通过factory-method属性来设定,并且这个方法不能是静态的,示例如下:
<bean id="exampleBean" factory-bean="myFactoryBean" factory-method="createInstance"/>
mysql-5.7.11-winx64
这个版本下面解压后没有data
文件夹,安装时会找不到
即:
mysqld -nt remove
mysqld -nt install
需要copy其它版本mysql-advanced-5.6.27-winx64
下面的data文件夹
安装如果不出问题,就提示成功了.
启动:
net start mysql
即可,这里需要管理员运行cmd下进行
或者在service
下面图形化操作,配置文件.cnf
也在这里
第一次登录不需要密码,直接enter
mysql -uroot
进入之后
mysql -u rootmysql> use mysql; mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root'; mysql> FLUSH PRIVILEGES;
ok
package spring;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class HelloController{
public static void main(String[] args) {
//ApplicationContext context = new ClassPathXmlApplicationContext( new String[] {"spring-config.xml"});
ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
HelloApi api = (HelloApi)context.getBean("helloBean");
String s = api.helloSpring(3);
System.out.println("the s="+s);
}
}
这里注意几点:
BeanFactory和ApplicationContext
org.springframework.beans及org.springframework.context包是Spring IoC容器的基础。BeanFactory提供的高级配置机制,使得管理任何性质的对象成为可能。 ApplicationContext是BeanFactory的扩展,功能得到了进一步增强,比如更易与Spring AOP集成、消息资源处理(国际化处理)、事件传递及各种不同应用层的context实现(如针对web应用的WebApplicationContext)。
Resource resource = new FileSystemResource("beans.xml");
BeanFactory factory = new XmlBeanFactory(resource);
2
ClassPathResource resource = new ClassPathResource("beans.xml");
BeanFactory factory = new XmlBeanFactory(resource);
ApplicationContext context = new ClassPathXmlApplicationContext(
new String[] {"applicationContext.xml", "applicationContext-part2.xml"});
// of course, an ApplicationContext is just a BeanFactory
BeanFactory factory = (BeanFactory) context;
fisrt blog
just for test....
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.