易栈网-膘叔

浏览模式: 标准 | 列表 | 图文
快速将googleapis的链接换为useso的国内镜像

快速将googleapis的链接换为useso的国内镜像

在使用第三方的程序时,特别是国外的项目,总是会碰到引用googleapis的问题,比如字体之类的,对于国外用户来说这玩意真方便,google也会帮你做CDN,多好啊,但在国内,你遇到的卡顿就不是一点两点了,有时候甚至会拖慢得页面打不开

所以,Wordpress、drupal 之类的程序在拿到手的第一时间就应该将里面的地址换掉,当然Wordpress还有插件,但drupal就不一定有了!

那怎么办?偷懒的办法是用PHP程序,递归查找并替换,如果是在本地,找个工具替换一下即可,现在的IDE都有这功能,如果已经部署到线上,那么只要你有ssh,你就可以尝试:sed -i s/googleapis/useso/g `grep -rl googleapis ./` ,该命令是将当前目录下含有googleapis的文件列出来,然后用sed进行全文替换。

如果做国外站的用户,我想他们一定是很痛苦的,如果用googleapis的数据吧,国内打开就卡死,用国内的cdn吧,国外又卡。当然 有解决方案~~

How to set up a clean UTF-8 environment in Linux

How to set up a clean UTF-8 environment in Linux

本来不想转,但真心是有用,以前的方法也有点过时,而且主要是不方便,所以就来贴个更全的。这种问题非常容易 遇到,用ubuntu、debian在阿里云上,原来都正常的,你只要一apt-get update一下,原来的LC环境就全没了。

原文地址在:http://perlgeek.de/en/article/set-up-a-clean-utf8-environment , 我上一次写关于这个的问题是在2012年了,那篇的标题是:perl: warning: Setting locale failed. 也可以看一下

How to set up a clean UTF-8 environment in Linux

Many people have problems with handling non-ASCII characters in their programs, or even getting their IRC client or text editor to display them correctly.

To efficiently work with text data, your environment has to be set up properly - it is so much easier to debug a problem which has encoding issues if you can trust your terminal to correctly display correct UTF-8.

I will show you how to set up such a clean environment on Debian Lenny, but most things work independently of the distribution, and parts of it even work on other Unix-flavored operating systems like MacOS X.

Choosing an encoding

In the end the used character encoding doesn't matter much, as long as it's a Unicode encoding, i.e. one which can be used to encode all Unicode characters.

UTF-8 is usually a good choice because it efficiently encodes ASCII data too, and the character data I typically deal with still has a high percentage of ASCII chars. It is also used in many places, and thus one can often avoid conversions.

Whatever you do, chose one encoding and stick to it, for your whole system. On Linux that means text files, file names, locales and all text based applications (mutt, slrn, vim, irssi, ...).

For the rest of this article I assume UTF-8, but it should work very similarly for other character encodings.

Locales: installing

Check that you have the locales package installed. On Debian you can do that with.

$ dpkg -l locales Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad) ||/ Name           Version        Description +++-==============-==============-============================================ ii  locales        2.7-18         GNU C Library: National Language (locale) da

The last line is the important one: if it starts with ii, the package is installed, and everything is fine. If not, install it. As root, type

$ aptitude install locales

If you get a dialog asking for details, read on to the next section.

Locales: generation

make sure that on your system an UTF-8 locale is generated. As root, type

$ dpkg-reconfigure locales

You'll see a long list of locales, and you can navigate that list with the up/down arrow keys. Pressing the space bar toggles the locale under the cursor. Make sure to select at least one UTF-8 locale, for example en_US-UTF-8 is usually supported very well. (The first part of the locale name stands for the language, the second for the country or dialect, and the third for the character encoding).

In the next step you have the option to make one of the previously selected locales the default. Picking a default UTF-8 locale as default is usually a good idea, though it might change how some programs work, and thus shouldn't be done servers hosting sensitive applications.

Locales: configuration

If you chose a default locale in the previous step, log out completely and then log in again. In any case you can configure your per-user environment with environment variables.

The following variables can effect programs: LANG, LANGUAGE, LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES, LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE, LC_MEASUREMENT, LC_IDENTIFICATION.

Most of the time it works to set all of these to the same value. Instead of setting all LC_ variables separately, you can set theLC_ALL. If you use bash as your shell, you can put these lines in your ~/.bashrc and ~/.profile files:

export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 export LANGUAGE=en_US.UTF-8

To make these changes active in the current shell, source the .bashrc:

$ source ~/.bashrc

All newly started interactive bash processes will respect these settings.

A Warning about Non-Interactive Processes

There are certain processes that don't get those environment variables, typically because they are started by some sort of daemon in the background.

Those include processes started from cron, at, init scripts, or indirectly spawned from init scripts, like through a web server.

You might need to take additional steps to ensure that those programs get the proper environment variables.

Locales: check

Run the locale program. The output should be similar to this:

LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=en_US.UTF-8

If not you've made a mistake in one of the previous steps, and need to recheck what you did.

Setting up the terminal emulator

Setting up the terminal emulator for your terminal emulator strongly depends on what you actually use. If you use xterm, you can start it as xterm -en utf-8, konsole and the Gnome Terminal can be configured in their respective configuration menus.

Testing the terminal emulator

To test if you terminal emulator works, copy and paste this line in your shell:

perl -Mcharnames=:full -CS -wle 'print "\N{EURO SIGN}"'

This should print a Euro sign € on the console. If it prints a single question mark instead, your fonts might not contain it. Try installing additional fonts. If multiple different (nonsensical) characters are shown, the wrong character encoding is configured. Keep trying :-).

SSH

If you use SSH to log in into another machine, repeat the previous steps, making sure that the locale is set correctly, and that you can view a non-ASCII character like the Euro sign.

Screen

The screen program can work with UTF-8 if you tell it to.

The easiest (and sometimes the only) way is to start it with the -U option:

$ screen -U

and also when detaching (screen -Urd or so).

Inside a running screen you can try Ctrl+a :utf8 on<return>. If that doesn't work, exit your screen and start a new one with -U

Irssi

There's a complete guide for setting up irssi to use UTF-8, which partially overlaps with this one. The gist is:

/set term_charset utf-8 /set recode_autodetect_utf8 ON /set recode_fallback ISO-8859-15 /set recode ON
gogs 如何不使用端口进行访问

gogs 如何不使用端口进行访问

gogos 默认是 3000端口,如果你本身已经有了其他WEB服务,比如apache,当然不可能同时占用80端口,这时候就可以利用apapche的proxy功能。如果你是apt-get 安装 的apache,就方便了,debian/ubuntu 都支持a2ensiate,a2enmod这样的小脚本。你只要打开a2enmod proxy proxy_http就行了,然后新建一个site加入以下配置

<VirtualHost *:80>
ServerAdmin test@test.com
ServerName yoursitename
ProxyRequests off
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000
<Proxy *>
Order Deny,Allow
Allow from all
</Proxy>
ErrorLog ${APACHE_LOG_DIR}/yoursitename.log
LogLevel warn
</VirtualHost>
是不是很简单,这时候你用supervisor启动后就可以通过WEB访问了.不过这时候有具小缺点,那就是如果你killall gogs进程的话,你会发现再也启动不了了.看启动的LOG会告诉你3000端口被占用,用netstat -an|grep 3000,发现有N个进程都是在CLOSE_WAIT的情况,这时候用: echo $(netstat -anp|grep 127.0.0.1:3000 |awk '{print $7}') 发现,全是apache2占着这些进程.

怀疑刚才在强杀gogs进程的时候,apache因为开着proxy导致刚刚向3000端口发起请求就挂起,导致异常关闭所以一直卡住(以前用nginx的做反代的时候也有类似问题,只要客户机挂了,nginx必须 重启),所以我重启了一下apache,立刻发现gogs启动成功.

至此,如果要 重启gogs最好是/etc/init.d/supervisor restart ,如果不正常就再重启一下apache...

OK,问题全部解决

gogs 0.6.1版二进制打包文件缺少start.sh

gogs 0.6.1版二进制打包文件缺少start.sh

在gogs的release包中,linux_amd64.zip这个包里,scripts目录下没有start.sh这个文件,因此在 执行./scripts/gogs_supvisor.sh文件的时候会直接后/usr/local/bin/gogs_start文件不存在

打开这个gogs_supvisor.sh文件后,发现他会判断/usr/local/bin/gogs_start文件是否存在,如果不存在就将./scripts/start.sh文件复制 过去并改为为gogs_start

然而,scripts目录下并没有这个start.sh文件,这个问题在官方的issue中已经提出并有解决方案:https://github.com/gogits/gogs/issues/1198

解决方案就是:

oh man sorry for that.

I would suggest install supervisor as init.d somehow doesn't worked for me after trying lot of diffrent combinations. to do that,

sudo apt-get -y install supervisor

and edit its file via

sudo nano /etc/supervisor/supervisord.conf

[program:gogs]
directory=/home/git/go/src/github.com/gogits/gogs/
command=/home/git/go/src/github.com/gogits/gogs/gogs web
autostart=true
autorestart=true
startsecs=10
stdout_logfile=/var/log/gogs/stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/var/log/gogs/stderr.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
environment = HOME="/home/git", USER="git"

change directory's to match your installation and user to your git user. and restart the supervisor via,
sudo service supervisor restart

that's all you need to make gogs start automatically on boot.

看上述内容,修改一下supervisor的配置,加入gogs的配置,注意修改成你自己的路径即可

Linux 系统挂载数据盘

Linux 系统挂载数据盘

下面的文字来自于aliyun的帮助文件,原文地址:http://help.aliyun.com/knowledge_detail.htm?spm=5176.7114037.1996646101.3.7IHA8N&categoryId=8314844&knowledgeId=5974196&pos=2。

步骤很简单
1、fdisk -l ,看一下有哪些磁盘没有挂载,如果是阿里云的第一块磁盘,默认就是/dev/xvdb
2、fdisk -S 56 /dev/xvdb ,按顺序输入:n , p , 1 ,后面就直接回车两次就行了,这时候再fdisk -l,会看到有一块硬盘是/dev/xvdb1
3、mkfs.ext3 /dev/xvdb1 ,对分区进行格式化,你可以选择ext3或者4
4、将分区信息写到/etc/fstab里,echo '/dev/xvdb1 /datas ext3 defaults 0 0 ' >> /etc/fstab
5、mkdir /datas
6、mount /dev/xvdb1 /datas
就是这样简单。如果需要图文并茂,还是看上面的网址吧
/etc/apt/sources.list won't accept URLs with https connection

/etc/apt/sources.list won't accept URLs with https connection

因为安装gogs遇到了一些奇怪的问题,所以我不得不尝试换个方式,于是我想,我是不是可以用apt来安装 ,毕竟官方在这一页有说明:http://gogs.io/docs/installation/install_from_packages.html,于是我到 https://packager.io/gh/pkgr/gogs/install?bid=190#debian-7-gogs 进行了查看,按照上面写的进行操作:

wget -qO - https://deb.packager.io/key | sudo apt-key add -
echo "deb https://deb.packager.io/gh/pkgr/gogs wheezy pkgr" | sudo tee /etc/apt/sources.list.d/gogs.list
sudo apt-get update
sudo apt-get install gogs

执行到第三步就报错了:

E: The method driver /usr/lib/apt/methods/https could not be found.

这,这搞什么?google了一下,原来有这个问题的人很多,但也很好解决,先把刚才的gogs.list中的内容注释掉,运行一下:

apt-get install apt-transport-https

然后就OK了。上面的帮助内容来自:http://unix.stackexchange.com/questions/166917/etc-apt-sources-list-wont-accept-urls-with-https-connection,我还以为是stackfollow呢。结果居然不是。。。

PHP Warning: Module 'modulename' already loaded in Unknown on line 0

PHP Warning: Module 'modulename' already loaded in Unknown on line 0

出现标题这样的错误大概是:

1、模块加载了两次,所以php -i|grep Configure,看一下配置文件和配置include的目录,对于这些文件中是否有同名的module

2、动态加载模块时,模块的目录下与php.ini中都有一个同名so

知道上述的问题就好办了,先看php配置文件和include目录下的文件,先整理内容。然后查看extension_dir,看看这个目录下的文件与include中的文件引用路径是否一致。

mac下MAMP 数据库偶尔连接不上的处理

mac下MAMP 数据库偶尔连接不上的处理

在MAC上面,为了减少配置PHP的环境所花的时间,所以就偷懒用了MAMP,但是,偶尔也会出现连接不上的情况。这时候怎么解?

1、检查是否装了组件

php -m |grep mysql

如果返回有mysql,证明至少命令行的组件没问题

2、检查数据 库是否正常

ps aux|grep mysql

因为都是默认的MAMP的PHP,所以这一点是没有问题的,只有MYSQL进程,就问题不大了。

3、检查默认的PHP参数配置,看是怎么连接的,是mysql.sock?还是其他?

php -i|grep mysql

看一下默认配置和你自己的配置,比如我就是/tmp/mysql.sock

那就检查 一下/tmp目录下是否有mysql.sock文件。如果没有ln -s一下:cd /tmp && ln -s /Applications/MAMP/tmp/mysql/mysql.sock
于是,一切就全解决了!

array_key_exists 和 isset

array_key_exists 和 isset

看到andot的hprose中有使用array_key_exists,就想问为什么不用isset,再一想哦。isset不能判断$a['xxx'] = null的情况。这时候看了一下评论,有人建议用isset() || array_key_exists来辅助判断,说是性能有大提升。

于是写了点代码测试,果然:

count array: 999900 ; loop :100000
$array['109011'] = 109011;
1. array_key_exists(109011,$array);
bool(true)
0.021718

2. isset($array['109011']);
bool(true)
0.004888

3. isset( $array['109011'] ) || array_key_exists( '109011', $array )
bool(true)
0.005100


count array: 999900 ; loop :100000
$array['109011'] = null;
1. array_key_exists(109011,$array);
bool(true)
0.026091

2. isset($array['109011']);
bool(false) //注意看这里
0.006697

3. isset( $array['109011'] ) || array_key_exists( '109011', $array )
bool(true)
0.026621

基本上,在$a['x'] 不是null的情况下,性能提升4倍左右 ,如果该值是null,这损耗可以接受。

数组长度是999900,循环100000次

所以以后代码还是 isset($a[$key])||array_key_exists($key,$a) 比较好。
当然,如果你平时处理isset($_GET['xxx'])的时候,不需要用array_key_exists的,因为URL中都是string

转:上海车牌拍卖技巧

转:上海车牌拍卖技巧

活在上海的悲哀是车牌是要拍的,而且现在非上海籍的除了有人才引进居住证才能拍之外,其他的不能拍了(港澳台等请别BB,我是指正常的在上海打工的)

因为没拍过,所以先学习一下,从百度上copy了一个小经验来参考一下:http://jingyan.baidu.com/article/fdffd1f805de25f3e88ca140.html

方法/步骤

  1. 首先登陆国拍网,在十点半之前将车牌拍卖的软件下载好,输入账号密码,在十点半的时候在出价栏随便输入一个价格出价,表示你参加了拍卖。

  2. 然后你就可以随便喝杯茶什么的,

    接下来的到11点回来,大家先移动下拍牌界面 确保验证码弹出框不会挡住左边数据窗口。

    然后不断刷验证码熟悉验证码的格式。

  3. 时间到了11点28分 这时请大家高度警惕 关闭所有联网软件

    到十一点29分,最关键的时刻。

    这时主要策略有两种,一个是11点29分00秒在最高价上加600伏击,伏击成功之后马上再加300伏击;另外一个是11点29分20秒最高价加300伏击,伏击成功后马上再加300伏击 。

  4. 举例

    目前最低可成交价为44800,可修改区间为44500-45100,跟最低可成交价比上下300 。 加300伏击意思是在最高价45100基础上加300为45400,出价,输入好验证码,等待系统最高价到达45400的时候点击确定就算成功出价了 。 还有,在伏击阶段,大家是可以出价后把验证码先输好的,到最后点确定就可以了 。

  5. 以上是伏击法,

    拍牌结束后的十分钟后左边会出现拍牌结果的信息 若中标的话 恭喜了 !

希望是美好的,但能不能拍到,还是要看运气的。先备着,虽然这是几年前的东西了。现在都75000左右了!!!可以买辆车了,我晶啊

PS:http://jingyan.baidu.com/article/37bce2be347aee1002f3a294.html,这个网址更详细。