Categories
木有技术

PhpStorm 中文字体设置方法

以前一直不会弄中文字体,默认的宋体看着怪怪的..今天仔细看了下,发现是可以设置的…
首先要修改字体,必须拷贝一份主题,因为默认的主题无法修改
在File => Settings底下:
QQ截图20150507141746里面的Editor->Colors & Fonts ,右边有个Save As…按钮
然后就可以更改了:
QQ截图20150507141538
首先把Show only monospaced fonts的勾去掉
然后把Secondary font的勾√了,这个选项是在第一个字体里面找不到字的时候的fallback
里面选择自己想要的中文字即可。这样就不用安装那种混合字体啦~诸如Consolas Yahei Hybrid那个
 

Categories
木有技术

CodeIgniter 在Linux(Ubuntu等)服务器上的大小写问题,开启rewrite(.htaccess)

貌似会碰到大小写问题,目前用的CodeIgniter 3.0版,载入的时候发现Controller不显示
首先需要开启mode_rewrite,就是对.htaccess的支持(如果不是root账户记得sudo)

a2enmod rewrite

然后再配置文件中对站点启用rewrite
可以更改sites-available目录下各个虚拟主机的配置文件,默认的应是default那个,差不多有这么一段

<Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
</Directory>

里面那个AllowOverride 原来是None的,改成All
然后保存文件
另外也有说可以在apache2的默认配置文件下改的,对应到ubuntu下是/etc/apache2/apache.conf。不过这个没试过
然后这一步是开启了mode_rewrite
接下来是要启动那个大小写自动修正的模块,叫mode_speling

a2enmod speling

然后重启apache应用配置

service apache2 restart

接着找到要应用的网站目录,我是直接放在根目录下的,新建一个叫.htaccess的文件,里头是这些

<IfModule mod_speling.c>    
CheckCaseOnly on
    CheckSpelling on
</IfModule>

然后就搞定了。
另外,需要删掉CodeIgniter那个烦人的index.php前缀的话,可以参考文档:http://www.codeigniter.com/user_guide/general/urls.html?highlight=url
Ref: https://www.a2hosting.com/kb/developer-corner/apache-web-server/using-the-mod-speling-apache-module

Categories
不学无术 木有技术

MYSQL获取自增ID

参考:
http://flandycheng.blog.51cto.com/855176/280224
http://www.cnblogs.com/badtree/articles/2143103.html
http://my.oschina.net/fz04003/blog/63327
比较简单的方法是:
insert/select…等操作
然后直接下一条语句:

SELECT LAST_INSERT_ID()

LAST_INSERT_ID 是与table无关的,如果向表a插入数据后,再向表b插入数据,LAST_INSERT_ID会改变。
看参考文献中说,多用户的情况下这个方法不能用。不过在php环境下,单用户用足够的。
 

Categories
不学无术 木有技术

MySQL 引擎选择 MyISAM 还是 InnoDB?

建表的时候会选择数据库引擎,常用的有MyISAM和InnoDB,到底选哪个呢?
参考文献:

什么是MyISAM?
MyISAM是MySQL关系数据库管理系统的默认储存引擎。这种MySQL表存储结构从旧的ISAM代码扩展出许多有用的功能。在新版本的MySQL中,InnoDB引擎由于其对事务,参照完整性,以及更高的并发性等优点开始广泛的取代MyISAM。
每一个MyISAM表都对应于硬盘上的三个文件。这三个文件有一样的文件名,但是有不同的扩展名以指示其类型用途:.frm文件保存表的定义,但是这个文件并不是MyISAM引擎的一部,而是服务器的一部分;.MYD保存表的数据;.MYI是表的索引文件。
什么是InnoDB?
InnoDB是MySQL的另一个存储引擎,正成为目前MySQL AB所发行新版的标准,被包含在所有二进制安装包里。较之于其它的存储引擎它的优点是它支持兼容ACID的事务(类似于PostgreSQL),以及参数完整性(即对外键的支持)。
Oracle公司与2005年10月收购了Innobase。Innobase采用双认证授权。它使用GNU发行,也允许其它想将InnoDB结合到商业软件的团体获得授权。

MyISAM vs Innodb – Quick comparison Table | 快速比较表:

MyISAM Innodb
Not *ACID compliant and non-transactional *ACID compliant and hence fully transactional with ROLLBACK and COMMIT and support for Foreign Keys
MySQL 5.0 Default Engine Rackspace Cloud Default Engine
Offers Compression Offers Compression
Requires full repair/rebuild of indexes/tables Auto recovery from crash via replay of logs
Changed Db pages written to disk instantly Dirty pages converted from random to sequential before commit and flush to disk
No ordering in storage of data Row data stored in pages in PK order
Table level locking Row level locking

在StackOverflow上的小总结:

Frequent reading, almost no writing 常有读取操作,几乎没有写操作=> MyISAM
Full-text search in MySQL <= 5.5      => MyISAM

InnoDB的设计目标是处理大容量数据库系统,它的CPU利用率是其它基于磁盘的关系数据库引擎所不能比的。

Categories
木有技术 生活琐碎

StartSSL被拒申诉感慨…HTTPS证书不好搞

之前一周都在申请startSSL证书,原因不言而喻,当然是因为它免费。
之前看过好多教程:https://www.google.com.hk/search?client=aff-6655&forid=1&ie=utf-8&oe=utf-8&hl=zh-cn&q=startssl%E6%95%99%E7%A8%8B&gws_rd=ssl
务必注意,如果开VPN之类的代理的,请把代理关掉再刷新网页,申请页面会判断IP地址的,根据你IP地址识别的国家地区会自动帮你填写好
然后就按部就班申请,填写个人信息。可是始终收到拒信,尼玛我真的是填了所有的个人信息啊!换了邮箱也不行:

Thank you for registering with StartSSL™ (www.startssl.com).
Unfortunately we could not validate the personal information you provided during the registration process. This means, that the details you submitted are most likely not correct or incomplete. Please note, that you must provide your complete and correct *personal, private* details during registration for an account. You may try it again by following our terms and conditions.
Attention: If you represent a business, company or other organization, you may provide those details at the StartSSL™ Control Panel after successful enrollment. See also http://www.startssl.com/?app=25#1 and following FAQ items for more information.
Thank you!
StartCom Ltd.
StartSSL™ Certification Authority

然后实在没办法,我就写邮件申诉。直接回复它发来的邮件即可(个人信息已隐去):

Dear CertMaster,

    I have recently tried to register your SSL account for several times, with both my office address at XXXXX University in China and my personal home address. I guarantee that the information I provided is detailed and correct. How ever I still received your rejection over and over again.
    The SSL certificate will be used to maintain my personal web page, for the purpose of satisfying the mandatory requirement of HTTPS protocol in Amazon Mechanical Turk. The website will be gathering data from crowds in order to support further data analysis of my current project. I sincerely hope that you could read again my application and approve it.
E-mail accounts used for application: XXXXXX
Honestly and respectfully,
XXXXXX He

没办法,按照实情来写,确实是要做MTurk没办法。
过不久就有回复了:

Please register once again with your complete personal details!

然后我重新注册了一遍,填写的自己家的地址,精确到门牌号,单元,房间了!注册完之后果然有人工审核的给我回复:

To XXXXX He,
This electronic mail message was created by StartCom’s Administration Personnel:
Thank you for registering with StartSSL. Please provide us with your legal full name.
Best Regards
XXXXX
StartCom Ltd.
StartSSL™ Certification Authority

意思是:我的名字不合法?我突然想到了我的姓氏…尼玛真是悲剧,估计就是这个让管理员误解了吧..于是乎澄清:

To XXX,

   “XXXHe” is my legal full name, the family name is “He”. Reference link: XXXXXX.
   Thank you for your patience! Sorry for the trouble brought by Chinese Pinyin, I can provide photo of my passport if you would like.
Best Regards,
Bowei

然后过不久就申请通过了。事实证明果然是姓氏的拼音He导致的误解。

Thank you for the clarification! Your account has been approved.

论威妥玛拼音的重要性!!!!!

Categories
木有技术

PHP Style Guide | PHP代码风格

来自http://www.codeigniter.com/user_guide/general/styleguide.html,感觉还挺有用的。


The following page describes the coding styles adhered to when contributing to the development of CodeIgniter. There is no requirement to use these styles in your own CodeIgniter application, though they are recommended.

File Format

Files should be saved with Unicode (UTF-8) encoding. The BOM should not be used. Unlike UTF-16 and UTF-32, there’s no byte order to indicate in a UTF-8 encoded file, and the BOM can have a negative side effect in PHP of sending output, preventing the application from being able to set its own headers. Unix line endings should be used (LF).
Here is how to apply these settings in some of the more common text editors. Instructions for your text editor may vary; check your text editor’s documentation.

TextMate

  1. Open the Application Preferences
  2. Click Advanced, and then the “Saving” tab
  3. In “File Encoding”, select “UTF-8 (recommended)”
  4. In “Line Endings”, select “LF (recommended)”
  5. Optional: Check “Use for existing files as well” if you wish to modify the line endings of files you open to your new preference.

BBEdit

  1. Open the Application Preferences
  2. Select “Text Encodings” on the left.
  3. In “Default text encoding for new documents”, select “Unicode (UTF-8, no BOM)”
  4. Optional: In “If file’s encoding can’t be guessed, use”, select “Unicode (UTF-8, no BOM)”
  5. Select “Text Files” on the left.
  6. In “Default line breaks”, select “Mac OS X and Unix (LF)”

PHP Closing Tag

The PHP closing tag on a PHP document ?> is optional to the PHP parser. However, if used, any whitespace following the closing tag, whether introduced by the developer, user, or an FTP application, can cause unwanted output, PHP errors, or if the latter are suppressed, blank pages. For this reason, all PHP files MUST OMIT the PHP closing tag and end with a single empty line instead.

File Naming

Class files must be named in a Ucfirst-like manner, while any other file name (configurations, views, generic scripts, etc.) should be in all lowercase.
INCORRECT:

somelibrary.php
someLibrary.php
SOMELIBRARY.php
Some_Library.php
Application_config.php
Application_Config.php
applicationConfig.php

CORRECT:

Somelibrary.php
Some_library.php
applicationconfig.php
application_config.php

Furthermore, class file names should match the name of the class itself. For example, if you have a class named Myclass, then its filename must be Myclass.php.

Class and Method Naming

Class names should always start with an uppercase letter. Multiple words should be separated with an underscore, and not CamelCased.
INCORRECT:

class superclass
class SuperClass

CORRECT:

class Super_class
class Super_class {
        public function __construct()
        {
        }
}

Class methods should be entirely lowercased and named to clearly indicate their function, preferably including a verb. Try to avoid overly long and verbose names. Multiple words should be separated with an underscore.
INCORRECT:

function fileproperties()               // not descriptive and needs underscore separator
function fileProperties()               // not descriptive and uses CamelCase
function getfileproperties()            // Better!  But still missing underscore separator
function getFileProperties()            // uses CamelCase
function get_the_file_properties_from_the_file()        // wordy

CORRECT:

function get_file_properties()  // descriptive, underscore separator, and all lowercase letters

Variable Names

The guidelines for variable naming are very similar to those used for class methods. Variables should contain only lowercase letters, use underscore separators, and be reasonably named to indicate their purpose and contents. Very short, non-word variables should only be used as iterators in for() loops.
INCORRECT:

$j = 'foo';             // single letter variables should only be used in for() loops
$Str                    // contains uppercase letters
$bufferedText           // uses CamelCasing, and could be shortened without losing semantic meaning
$groupid                // multiple words, needs underscore separator
$name_of_last_city_used // too long

CORRECT:

for ($j = 0; $j < 10; $j++)
$str
$buffer
$group_id
$last_city

Commenting

In general, code should be commented prolifically. It not only helps describe the flow and intent of the code for less experienced programmers, but can prove invaluable when returning to your own code months down the line. There is not a required format for comments, but the following are recommended.
DocBlock style comments preceding class, method, and property declarations so they can be picked up by IDEs:

/**
 * Super Class
 *
 * @package     Package Name
 * @subpackage  Subpackage
 * @category    Category
 * @author      Author Name
 * @link        http://example.com
 */
class Super_class {
/**
 * Encodes string for use in XML
 *
 * @param       string  $str    Input string
 * @return      string
 */
function xml_encode($str)
/**
 * Data for class manipulation
 *
 * @var array
 */
public $data = array();

Use single line comments within code, leaving a blank line between large comment blocks and code.

// break up the string by newlines
$parts = explode("\n", $str);
// A longer comment that needs to give greater detail on what is
// occurring and why can use multiple single-line comments.  Try to
// keep the width reasonable, around 70 characters is the easiest to
// read.  Don't hesitate to link to permanent external resources
// that may provide greater detail:
//
// http://example.com/information_about_something/in_particular/
$parts = $this->foo($parts);

Constants

Constants follow the same guidelines as do variables, except constants should always be fully uppercase. Always use CodeIgniter constants when appropriate, i.e. SLASH, LD, RD, PATH_CACHE, etc.
INCORRECT:

myConstant      // missing underscore separator and not fully uppercase
N               // no single-letter constants
S_C_VER         // not descriptive
$str = str_replace('{foo}', 'bar', $str);       // should use LD and RD constants

CORRECT:

MY_CONSTANT
NEWLINE
SUPER_CLASS_VERSION
$str = str_replace(LD.'foo'.RD, 'bar', $str);

TRUE, FALSE, and NULL

TRUE, FALSE, and NULL keywords should always be fully uppercase.
INCORRECT:

if ($foo == true)
$bar = false;
function foo($bar = null)

CORRECT:

if ($foo == TRUE)
$bar = FALSE;
function foo($bar = NULL)

Logical Operators

Use of the || “or” comparison operator is discouraged, as its clarity on some output devices is low (looking like the number 11, for instance). && is preferred over AND but either are acceptable, and a space should always precede and follow !.
INCORRECT:

if ($foo || $bar)
if ($foo AND $bar)  // okay but not recommended for common syntax highlighting applications
if (!$foo)
if (! is_array($foo))

CORRECT:

if ($foo OR $bar)
if ($foo && $bar) // recommended
if ( ! $foo)
if ( ! is_array($foo))

Comparing Return Values and Typecasting

Some PHP functions return FALSE on failure, but may also have a valid return value of “” or 0, which would evaluate to FALSE in loose comparisons. Be explicit by comparing the variable type when using these return values in conditionals to ensure the return value is indeed what you expect, and not a value that has an equivalent loose-type evaluation.
Use the same stringency in returning and checking your own variables. Use === and !== as necessary.
INCORRECT:

// If 'foo' is at the beginning of the string, strpos will return a 0,
// resulting in this conditional evaluating as TRUE
if (strpos($str, 'foo') == FALSE)

CORRECT:

if (strpos($str, 'foo') === FALSE)

INCORRECT:

function build_string($str = "")
{
        if ($str == "") // uh-oh!  What if FALSE or the integer 0 is passed as an argument?
        {
        }
}

CORRECT:

function build_string($str = "")
{
        if ($str === "")
        {
        }
}

See also information regarding typecasting, which can be quite useful. Typecasting has a slightly different effect which may be desirable. When casting a variable as a string, for instance, NULL and boolean FALSE variables become empty strings, 0 (and other numbers) become strings of digits, and boolean TRUE becomes “1”:

$str = (string) $str; // cast $str as a string

Debugging Code

Do not leave debugging code in your submissions, even when commented out. Things such as var_dump(), print_r(), die()/exit() should not be included in your code unless it serves a specific purpose other than debugging.

Whitespace in Files

No whitespace can precede the opening PHP tag or follow the closing PHP tag. Output is buffered, so whitespace in your files can cause output to begin before CodeIgniter outputs its content, leading to errors and an inability for CodeIgniter to send proper headers.

Compatibility

CodeIgniter recommends PHP 5.4 or newer to be used, but it should be compatible with PHP 5.2.4. Your code must either be compatible with this requirement, provide a suitable fallback, or be an optional feature that dies quietly without affecting a user’s application.
Additionally, do not use PHP functions that require non-default libraries to be installed unless your code contains an alternative method when the function is not available.

One File per Class

Use separate files for each class, unless the classes are closely related. An example of a CodeIgniter file that contains multiple classes is the Xmlrpc library file.

Whitespace

Use tabs for whitespace in your code, not spaces. This may seem like a small thing, but using tabs instead of whitespace allows the developer looking at your code to have indentation at levels that they prefer and customize in whatever application they use. And as a side benefit, it results in (slightly) more compact files, storing one tab character versus, say, four space characters.

Line Breaks

Files must be saved with Unix line breaks. This is more of an issue for developers who work in Windows, but in any case ensure that your text editor is setup to save files with Unix line breaks.

Code Indenting

Use Allman style indenting. With the exception of Class declarations, braces are always placed on a line by themselves, and indented at the same level as the control statement that “owns” them.
INCORRECT:

function foo($bar) {
        // ...
}
foreach ($arr as $key => $val) {
        // ...
}
if ($foo == $bar) {
        // ...
} else {
        // ...
}
for ($i = 0; $i < 10; $i++)
        {
        for ($j = 0; $j < 10; $j++)
                {
                // ...
                }
        }
try {
        // ...
}
catch() {
        // ...
}

CORRECT:

function foo($bar)
{
        // ...
}
foreach ($arr as $key => $val)
{
        // ...
}
if ($foo == $bar)
{
        // ...
}
else
{
        // ...
}
for ($i = 0; $i < 10; $i++)
{
        for ($j = 0; $j < 10; $j++)
        {
                // ...
        }
}
try
{
        // ...
}
catch()
{
        // ...
}

Bracket and Parenthetic Spacing

In general, parenthesis and brackets should not use any additional spaces. The exception is that a space should always follow PHP control structures that accept arguments with parenthesis (declare, do-while, elseif, for, foreach, if, switch, while), to help distinguish them from functions and increase readability.
INCORRECT:

$arr[ $foo ] = 'foo';

CORRECT:

$arr[$foo] = 'foo'; // no spaces around array keys

INCORRECT:

function foo ( $bar )
{
}

CORRECT:

function foo($bar) // no spaces around parenthesis in function declarations
{
}

INCORRECT:

foreach( $query->result() as $row )

CORRECT:

foreach ($query->result() as $row) // single space following PHP control structures, but not in interior parenthesis

Localized Text

CodeIgniter libraries should take advantage of corresponding language files whenever possible.
INCORRECT:

return "Invalid Selection";

CORRECT:

return $this->lang->line('invalid_selection');

Private Methods and Variables

Methods and variables that are only accessed internally, such as utility and helper functions that your public methods use for code abstraction, should be prefixed with an underscore.

public function convert_text()
private function _convert_text()

PHP Errors

Code must run error free and not rely on warnings and notices to be hidden to meet this requirement. For instance, never access a variable that you did not set yourself (such as $_POST array keys) without first checking to see that it isset().
Make sure that your dev environment has error reporting enabled for ALL users, and that display_errors is enabled in the PHP environment. You can check this setting with:

if (ini_get('display_errors') == 1)
{
        exit "Enabled";
}

On some servers where display_errors is disabled, and you do not have the ability to change this in the php.ini, you can often enable it with:

ini_set('display_errors', 1);

Note

Setting the display_errors setting with ini_set() at runtime is not identical to having it enabled in the PHP environment. Namely, it will not have any effect if the script has fatal errors.

Short Open Tags

Always use full PHP opening tags, in case a server does not have short_open_tag enabled.
INCORRECT:

<? echo $foo; ?>
<?=$foo?>

CORRECT:

<?php echo $foo; ?>

Note

PHP 5.4 will always have the <?= tag available.

One Statement Per Line

Never combine statements on one line.
INCORRECT:

$foo = 'this'; $bar = 'that'; $bat = str_replace($foo, $bar, $bag);

CORRECT:

$foo = 'this';
$bar = 'that';
$bat = str_replace($foo, $bar, $bag);

Strings

Always use single quoted strings unless you need variables parsed, and in cases where you do need variables parsed, use braces to prevent greedy token parsing. You may also use double-quoted strings if the string contains single quotes, so you do not have to use escape characters.
INCORRECT:

"My String"                                     // no variable parsing, so no use for double quotes
"My string $foo"                                // needs braces
'SELECT foo FROM bar WHERE baz = \'bag\''       // ugly

CORRECT:

'My String'
"My string {$foo}"
"SELECT foo FROM bar WHERE baz = 'bag'"

SQL Queries

SQL keywords are always capitalized: SELECT, INSERT, UPDATE, WHERE, AS, JOIN, ON, IN, etc.
Break up long queries into multiple lines for legibility, preferably breaking for each clause.
INCORRECT:

// keywords are lowercase and query is too long for
// a single line (... indicates continuation of line)
$query = $this->db->query("select foo, bar, baz, foofoo, foobar as raboof, foobaz from exp_pre_email_addresses
...where foo != 'oof' and baz != 'zab' order by foobaz limit 5, 100");

CORRECT:

$query = $this->db->query("SELECT foo, bar, baz, foofoo, foobar AS raboof, foobaz
                                FROM exp_pre_email_addresses
                                WHERE foo != 'oof'
                                AND baz != 'zab'
                                ORDER BY foobaz
                                LIMIT 5, 100");

Default Function Arguments

Whenever appropriate, provide function argument defaults, which helps prevent PHP errors with mistaken calls and provides common fallback values which can save a few lines of code. Example:

function foo($bar = '', $baz = FALSE)
Categories
木有技术

MTurk CLT Java错误解决

参考此文:http://blog.matt.qa/?p=31
这个问题发生在Windows下,估计是自带的JRE和系统内的冲突了。
下述步骤的第9步是可选的。
其中路径的选择根据自己的来,我的路径是:

C:\Program Files (x86)\Java\jre1.8.0_40

 

WINDOWS:

  1. Go to the C: drive in a windows explorer window, and double click on the mech-turk-tools-1.3.1 folder. Delete the folder called jre1.5.0_06, as this is what is causing the problem.
  2. Make sure you do have a working Java Runtime Environment installed. If you don’t, download the latest one from java.com
  3. Next, go to the control panel and double click on “System” (you may need to change the view to icons at the top right). Then click on advanced system settings and click on the advanced tab.
  4. Click the “Environment Variables” button.
  5. Click the “New…” button under System Variables at the bottom.
  6. Set the variable name as: JAVA_HOME
  7. Se the variable value to: C:\Program Files (x86)\Java\jre7 (64-bit systems) or C:\Program Files\Java\jre7(32 bit systems, or a 64-bit system with a 64-bit jre)
    1. If you’re unsure whether you are on a 64-bit or a 32-bit system, Windows XP is 32 bit. On Vista, 7 and 8, the System Properties Window in the Control Panel tells you.
  8. Press OK and OK again.
  9. Now go back into the mech-turk-tools-1.3.1 folder, and double click on the “bin” folder. Open up the mturk.properties file and change the service_url lines to usehttps:// rather than http:// (just edit the first part after the = sign). Save and close.
Categories
木有技术

Shadowsocks相关资料(下载、安装、更新)

1、Shadowsocks 是什么
Shadowsocks 是一种安全的 socks5 代理,可以保护你的上网流量。基于多种加密方式,推荐使用 aes-256-cfb 加密。安装和使用需要本地端和服务端。
本地客户端已经包含了多种版本,包括iOS,Android,Windows,MAC,甚至是路由器 (基于OpenWRT),所以使用方便,各取所需。
远程服务端则一般安装在基于 Linux 的各种发行版操作系统,比如 Debian, CentOS, Fedora, Redhat, Ubuntu, openSUSE等。
2、Shadowsocks 的作者是谁
最初只有 Python 版,由 @clowwindy 开发和维护,后来随着知名度提高,开始出现各种语言的版本,其中比较知名的是 libev , go, nodejs 等版本,需要注意的是,nodejs 的作者也是 @clowwindy,但最近已不再维护该版本。libev 的维护者是 @madeye,长期更新。
3、Shadowsocks 一键安装脚本
虽然作者的安装教程已经很完备了,但还是有不少人不会安装和使用,因此我编写了 Shadowsocks 一键安装脚本,主要基于 CentOS 系统下的一键安装(也有 Debian 系统),分别有 Pythonlibevnodejs 版,个人推荐使用 Python 和 libev 版。
该脚本会自动下载,编译安装最新版的 Shadowsocks,并且可以完全卸载 Shadowsocks ,自动生成配置文件,安装完成即可使用。
4、Shadowsocks 如何升级
安装完 Shadowsocks,一段时间后,作者已经更新了版本(修正 bug 或升级功能),那么如何一键升级到最新版呢?
Python 版,执行命令: pip install -U shadowsocks ,命令执行成功后,重新启动 Shadowsocks ,命令: service shadowsocks restart
libev 版,先卸载旧版本,执行命令:./shadowsocks-libev.sh uninstall ,再安装新版本,执行命令: ./shadowsocks-libev.sh 安装
Debian 下的 libev 版,升级方式同上。
nodejs 版,也是先卸载再重新安装,因为作者已经不更新,所以不推荐用这版本。
5、Shadowsocks 安装失败怎么办
由于 CentOS 5.x 的默认 gcc 版本过低,在编译 libev 版时会出错;同时默认 Python 的版本也过低,所以也无法安装 Python 版的。因此,请确保安装的环境为 CentOS 6.x 或 CentOS 7.x 。
更多其他错误,请根据实际错误提示,自行在 google 上搜索关键字。
6、Shadowsocks 的客户端程序
大多数人都是在 Windows 下使用电脑,因此最好用的 Windows 客户端是 shadowsocks-gui ,下载最新版后解压即可使用。
7、Shadowsocks 本地代理上网
本地电脑启动客户端,连接上远程服务端后,即在本地开启了 socks5 代理,本地端口号默认为 1080,如果提示被占用,也可以改为其他端口号。在浏览器中安装插件,Chrome 下是 SwitchySharp, Firefox 下是 AutoProxy,新建配置文件,SOCKS Host 填 127.0.0.1,Port 填 1080(默认,跟 Shadowsocks 客户端的本地端口号一致即可)
参考链接:
1、http://shadowsocks.org/en/index.html
2、https://github.com/clowwindy/shadowsocks
3、https://github.com/madeye/shadowsocks-libev
 
本文来自:http://teddysun.com/372.html

Categories
不学无术 木有技术

1065. A+B and C (64bit) (20)

http://www.patest.cn/contests/pat-a-practise/1065


 

原题如下

Given three integers A, B and C in [-263, 263], you are supposed to tell whether A+B > C.
Input Specification:
The first line of the input gives the positive number of test cases, T (<=10). Then T test cases follow, each consists of a single line containing three integers A, B and C, separated by single spaces.
Output Specification:
For each test case, output in one line “Case #X: true” if A+B>C, or “Case #X: false” otherwise, where X is the case number (starting from 1).
Sample Input:

3
1 2 3
2 3 4
9223372036854775807 -9223372036854775808 0

Sample Output:

Case #1: false
Case #2: true
Case #3: false

 
分析,其实就是自己做加减法进位的问题,需要考虑正负号的细节。
正负数加减法的规则可以参考百度文库,一大堆小学生教材,哈哈~
大概是这样,比较两个数a和b:

  • 最终结果符号的判定:如果|a|>=|b|那么结果的符号与a相同,反之符号与b相同;
  • 数值计算,不管正负号,用绝对值大的那个做操作数1,绝对值小的做操作数2,如果a,b同号做操作数1+操作数2,异号做操作数1操作数2

 
我的代码(好久没写c++,各种复杂,见谅)
其中isBiggerAbs是判断a与b的绝对值大小的,isBigger是判断实际值大小的,swapss是交换元素。
另外0x30是字符’0’的ASCII码来着~输入的时候是按照字符流看待的,计算的时候转换成了数字,然后比较的时候为了和c比方便又转换回去了。
另外给的Sample Input里面那个一长串的就是上限和下限了,加上符号20位足够放。

#include <iostream>
#include <string.h>
using namespace std;
void swapss(char*a, char* b)
{
	char t[20];
	strcpy(t, a);
	strcpy(a, b);
	strcpy(b, t);
}
bool isBiggerAbs(char* a, char* b)
{
	int len_a, len_b;
	len_a = strlen(a);
	len_b = strlen(b);
	if (len_a > len_b)
		return true;
	else if (len_a < len_b)
		return false;
	//只需比较位数一样的
	for (int i = 0; i < len_a; i++)
	{
		if (a[i] > b[i])
			return true;
		else if (a[i] < b[i])
			return false;
	}
	//完全相等
	return false;
}
bool isBigger(char* a, char* b)
{
	//Judge if a > b
	bool neg_a = (a[0] == '-');
	bool neg_b = (b[0] == '-');
	if (neg_a && !neg_b)
		return false;
	else if (!neg_a && neg_b)
		return true;
	if (!neg_a)
		return isBiggerAbs(a, b);
	else
	{
		a = strtok(a, "-");
		b = strtok(b, "-");
		return !isBiggerAbs(a, b);
	}
}
void bigPlus(char* a, char* b, char* r)
{
	// c = a + b
	int len_a, len_b;
	bool isNeg_a = false;
	bool isNeg_b = false;
	bool isNeg_r = false;
	if (a[0] == '-')
	{
		char* pch = strtok(a, "-");
		a = pch;
		isNeg_a = true;
	}
	if (b[0] == '-')
	{
		char* pch = strtok(b, "-");
		b = pch;
		isNeg_b = true;
	}
	if (!isBiggerAbs(a, b))
	{
		//Swap a and b
		swapss(a, b);
		isNeg_r = isNeg_b;
	}
	else
		isNeg_r = isNeg_a;
	if (isNeg_a)
	{
		bool t = isNeg_a;
		isNeg_a = isNeg_b;
		isNeg_b = t;
	}
	len_a = strlen(a);
	len_b = strlen(b);
	int index_a = len_a - 1;
	int index_b = len_b - 1;
	int remainder = 0;
	int count = 0;
	while (index_a >= 0 || index_b >= 0)
	{
		int op0 = 0;
		if (index_a >=0 )
			op0 = (int)a[index_a] - 0x30;
		if (isNeg_a)
			op0 = -op0;
		int op1 = 0;
		if (index_b >= 0)
			op1 = (int)b[index_b] - 0x30;
		if (isNeg_b)
			op1 = -op1;
		int result = op0 + op1 + remainder;
		if (result < 0)
		{
			remainder = -1; //negative raminder (<'0')
			result += 10;
		}
		else if (result > 9)
		{
			remainder = 1; //positive remainder (>'9')
			result -= 10;
		}
		else
			remainder = 0;
		r[count++] = (char)(result + 0x30);
		index_a--;
		index_b--;
	}
	//Deal with the last remainder
	if (remainder > 0)
	{
		r[count++] = (char)(remainder+0x30);
	}
	else if (remainder < 0)
	{
		r[count++] = (char)(remainder + 0x30);
	}
	if (isNeg_r)
		r[count++] = '-';
	char temp[21];
	int t = 0;
	while ((--count) >= 0)
	{
		temp[t++] = r[count];
	}
	temp[t] = '\0';
	strcpy(r, temp);
}
int main()
{
	//Read huge integer as charset
	int T; //Nubmer of test cases
	cin >> T;
	char a[20];
	char b[20];
	char c[20];
	char result[21];
	for (int i = 0; i < T; i++)
	{
		//Deal with test cases
		cin >> a >> b >> c;
		bigPlus(a, b, result);
		bool is_bigger = isBigger(result, c);
		cout << "Case #" << i + 1 << ": ";
		if (is_bigger)
			cout << "true";
		else
			cout << "false";
		if (i < T - 1)
			cout << endl;
	}
	return 0;
}

 


结果

评测结果

时间 结果 得分 题目 语言 用时(ms) 内存(kB) 用户
2月22日 20:46 答案正确 20 1065 C++ (g++ 4.7.2) 1 360

测试点

测试点 结果 用时(ms) 内存(kB) 得分/满分
0 答案正确 1 360 12/12
1 答案正确 1 360 4/4
2 答案正确 1 360 4/4

 

Categories
木有技术

[Updated on Aug.29] ThinkPad X220/X230 Full HD IPS modification

[CHINESE] Reference of the detail/ Source of this article: http://forum.51nb.com/viewthread.php?tid=1548345&extra=&highlight=&page=1
[CHINESE] Forum page to buy this modification suite: http://forum.51nb.com/viewthread.php?tid=1548947&extra=&highlight=&page=1
[CHINESE] FHD modification for T420/430 series are also available via a customed LVDS to eDP board: http://forum.51nb.com/thread-1552978-1-1.html In plain terms, the EDID information must be coded on the external LVDS to eDP board so that no BIOS modification are needed.
Firstly, I am NOT the inventor of this method, he who achieved this modification did not give details about his modification in some way. I am only a customer who bought his modified adapter.
I’m just trying to guess what he did to my motherboard and some of my descriptions below might be totally wrong and yes I will mark them specially.


 
Here are the main(brief) ideas of the following modification:

  • Renounce the video signals produced by original LVDP lane because it cannot support a screen resolution higher than 1440×900
  • Use the signal output on dock station to transfer data because it supports DisplayPort
  • (I’m not quite sure about this part)’Hijack’ the signal of original LVDS lane (33 PANEL_BKLT_CTRL and 33 BACKLIGHT_ON ) input so as to control the backlight of the new screen panel

An Overview of LVDS/eDP Adapter

x230 edp

Modifications on Motherboard(Video Signals, w/o backlight control)

IMG_0724.jpg.thumb


 

 Yes, there is an applicable solution to modify(replace) the built-in LCD screen to Full HD resolution (1920 * 1080). Yes, it still supports one other external screen either analogical(VGA) or digital(DisplayPort).

Firstly I must declare that I am not the inventor of this solution, and I personally hold no responsibility to any thing that might happen on your laptop.
kingkonglue in forum.51nb.com is the one who invented this solution, I take no credit for the solution introduced below.
IMG_2507

Background Info

As almost everyone knows, the X220/X230 series uses a one-lane(single channel) LVDP lane to transmit video signal to the build-in screen panel, which only supports a screen resolution  lower than 1440*900. This is the main obstacle to install a FHD panel on the laptop.
There are at least 3 solutions available to deal with this problem.
Leokim is the first person to achieve this goal, he successfully modified his X220 with a Full HD panel (which seems to be a touchable screen toke apart from a Dell XPS 12” series, LP125WF1). His solution is not quite clearly explained, what we know till now is the modified BIOS and signal wire and the BIOS modification is hard for X230 series due to the encryption of UEFI BIOS.
The second trial of such modification is done by 东大师(Dong Da-shi). Presumably he used a self-made  LVDS–>EDP adapter to fit the screen panel , and added some signal wires to the original LVDP signal wire in order to support higher resolution. This solution has a chance to encounter signal interference because of the modified analogue signal wire(LVDS).
And I myself heard somehow there is another `shortcut` toward such modification through the interface of  dock. As we know there are two digital video output available through the external dock and hence we can make use of one of them. However, problem remains on the backlight control of the panel.

Screen Panel

In 2014 there are more high resolution panels available for the 12.5″ X series. After Dell XPS, ThinkPad X24o starts to use eDP video lane instead of LVDS for the sake of  FHD support. As is written above, filling the gap between LVDS and eDP is the key to our modification task and there exist at least two main problem on the way of achievement.
BTW the model of screen panel that I used is LP125WF2 SPB1 (I guess that all `LP125WF2` series are compatible).

FHD Signal

WIP

Backlight Control

WIP

Problems Remained

(Updated on Aug 29 2015)
Although we have successfully connected the FHD panel onto the mainboard, small problems still exists in everyday use. The following problems might occur:

  • A Higher Temperature on GPU/CPU, especially when you attach a external screen.  This is because that the original output is still alive, actually the system will recognize TWO screen panels with the original one disabled partially. The same video signal will still be outputted to the original port. When you attach a 2nd screen (like a external monitor) the system will have to maintain the screen output of 3 panels actually.
  • Bugs on the Driver –> 16-bit-like color depth (on X230 series; the X220 series are exempted). I was encountered with this trouble as many other people who holds the x230 laptop.  However, x220 series will not be affected if it uses a modified driver provided by the inventor of the adapter. This bug will cause a 16-bit-like color output on  the screen panel, such that the gradual change of one color will not be so smooth as it was. If anyone remember the 16-bit color depth on the earlier LCD panels, that’s the feel. The root of this bug lies in the display driver, but no solutions has been ever given till now.
  • Black Screen on the First Attach of External  Screen. The earlier version of adapter (like what I owned) will encounter this bug, but it is reported solved by an upgrade to the chip on the adapter (on the hardware I mean).

WORK IN PROGRESS.
THIS ARTICLE WILL BE WRITTEN UP IF I HAVE ANY SPARE TIME.