This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# PHP CodeSniffer pre-receive hook for git | |
#exit 0 #if you want to skip all validation | |
PHPCS_BIN="phpcs" | |
PHPCS_CODING_STANDARD="PSR2" | |
TMP_DIR=$(mktemp -d phpcs-pre-receive-hook.XXXXXXXX) | |
mkdir "$TMP_DIR/source" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function longestCommonSubstring($str_a, $str_b, $case_sensitive = false) | |
{ | |
$len_a = mb_strlen($str_a); | |
$len_b = mb_strlen($str_b); | |
if (! $len_a || ! $len_b) { | |
return false; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function maxDivisor($a, $b) | |
{ | |
if (! $a || !$b) { | |
return false; | |
} | |
if ($b > $a) { | |
list($a, $b) = array($b, $a); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function longest_common_substring($words) | |
{ | |
$words = array_map('strtolower', array_map('trim', $words)); | |
$sort_by_strlen = create_function('$a, $b', 'if (strlen($a) == strlen($b)) { return strcmp($a, $b); } return (strlen($a) < strlen($b)) ? -1 : 1;'); | |
usort($words, $sort_by_strlen); | |
// We have to assume that each string has something in common with the first | |
// string (post sort), we just need to figure out what the longest common | |
// string is. If any string DOES NOT have something in common with the first | |
// string, return false. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function isPrime($num) | |
{ | |
//1 is not prime. See: http://en.wikipedia.org/wiki/Prime_number#Primality_of_one | |
if($num == 1) | |
return false; | |
//2 is prime (the only even number that is prime) | |
if($num == 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function longestCommonSequence($str_a, $str_b) | |
{ | |
assert("is_string('$str_a')"); | |
assert("is_string('$str_b')"); | |
$str_a_len = strlen($str_a); | |
$str_b_len = strlen($str_b); | |
$opt = array_fill(0, $str_a_len + 1, array_fill(0, $str_b_len + 1, 0)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 二分查找 | |
* | |
* @param $a array | |
* @param $v 查找的值 | |
* | |
* @return int | |
*/ | |
function binarySearch($a, $v) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Flexihash - A simple consistent hashing implementation for PHP. | |
* | |
* The MIT License | |
* | |
* Copyright (c) 2008 Paul Annesley | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 普通匹配,遵循最长匹配规则,假设一个请求匹配到了两个普通规则,则选择匹配长度大的那个 | |
例如: | |
location /{ | |
[matches] | |
} | |
location /test{ | |
[matches] | |
} | |
2 精确匹配 | |
location = /{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function my_mb_strlen($value) | |
{ | |
// 计算单字节. | |
preg_match_all('/[a-zA-Z0-9_]/', $value, $single); | |
$single = count($single[0]) / 2; | |
// 多子节长度. | |
$double = str_word_count(preg_replace('([a-zA-Z0-9_])', '', $value)); |
OlderNewer