2013年7月29日星期一

[转] password strength

password strength


/**
 *
 * @param String $string
 * @return float
 *
 * Returns a float between 0 and 100. The closer the number is to 100 the
 * the stronger password is; further from 100 the weaker the password is.
 */ 
function password_strength($string){
    
$h    0;
    
$size strlen($string);
    foreach(
count_chars($string1) as $v){
        
$p $v $size;
        
$h -= $p log($p) / log(2);
    }
    
$strength = ($h 4) * 100;
    if(
$strength 100){
        
$strength 100;
    }
    return 
$strength;
}
var_dump(password_strength("Correct Horse Battery Staple"));
echo 
"
"
var_dump(password_strength("Super Monkey Ball"));
echo 
"
"
var_dump(password_strength("Tr0ub4dor&3"));
echo 
"
"
var_dump(password_strength("abc123"));
echo 
"
"
var_dump(password_strength("sweet"));

2013年7月26日星期五

[总结] Library not loaded: /opt/local/lib/libiconv.2.dylib 错误解决之法

1. 背景
工作中需要用到 php 的一个图形库的扩展模块 gmagick.
而目前使用的 php 在编译时并没有将 gmagick 静态编译进去,于是通过编译扩展模块来实现.
扩展模块的编译很顺利,但挂在 php 上后发现没有生效.写的简单的脚本测试发现 php error.log 中报如下的错

PHP Warning:  PHP Startup: Unable to load dynamic library '/Users/hy0kl/php/ext/gmagick.so' - dlopen(/Users/hy0kl/php/ext/gmagick.so, 9): Library not loaded: /opt/local/lib/libiconv.2.dylib
  Referenced from: /Users/hy0kl/php/ext/gmagick.so
  Reason: Incompatible library version: gmagick.so requires version 8.0.0 or later, but libiconv.2.dylib provides version 7.0.0 in Unknown on line 0

谷歌后发现,我的机器中有两个版的 libiconv:
$ otool -LD /usr/lib/libiconv.2.dylib
/usr/lib/libiconv.2.dylib:
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.0.0)

$ otool -LD /opt/local/lib/libiconv.2.dylib
/opt/local/lib/libiconv.2.dylib:
/opt/local/lib/libiconv.2.dylib (compatibility version 8.0.0, current version 8.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
初步确认是动态的加载顺序没有搞对.
多次尝试 + 不断的 google,终于发现了下面的有用帮助:
https://code.google.com/p/git-osx-installer/issues/detail?id=18

Found out that it wasn't a problem running git as root.

I had this in my personal .profile:
export DYLD_LIBRARY_PATH=/usr/lib
export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib:/sw/lib

Hashed it out and everything was fine..
Don't remember why I put it in there in the first place.. :-/


大家千万不要移除或重命名系统 /usr/lib 下的 libiconv,否则系统报各种问题,生不如死.

2. 解决方法:
$ vi ~/.bashrc

DYLD_LIBRARY_PATH=$HOME/local/lib:/usr/local/lib:/usr/local/mysql/lib
export DYLD_LIBRARY_PATH

DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib:/usr/lib
export DYLD_FALLBACK_LIBRARY_PATH

加入以后内容,通过小改变一下动态库的扫描路径的先后顺序,即可解决了

2013年7月25日星期四

[转] mac port warning

https://gist.github.com/romanr/3192047

Warning: Your developer_dir setting in macports.conf points to a non-existing directory. Since this is known to cause problems, please correct the setting or comment it and let macports auto-discover the correct path.

xcode-select --print-path

sudo nano /opt/local/etc/macports/macports.conf

[转] Building ImageMagick on OSX Lion and can't link libpng

Building ImageMagick on OSX Lion and can't link libpng

Q:
I am trying to build ImageMagick 6.8.0-5 on OSX Lion with support for libpng. I am just using the standard ./configure make make install procedure.
I succeed in compiling when I do not reference libpng.
./configure --with-png=no
make
However, I get an error in make when I try to add libpng support. (libpng-1.5.13)
./configure --with-png=yes
make
The error seems to be a linker error.
/usr/bin/nm: no name list
ld: warning: cannot export hidden symbol _SyncImagePixelCache from magick/.libs/magick_libMagickCore_la-cache.o
ld: warning: cannot export hidden symbol _ResetQuantumState from magick/.libs/magick_libMagickCore_la-quantum.o
Undefined symbols for architecture x86_64:
  "_png_set_check_for_invalid_index", referenced from:
      _WriteOnePNGImage in magick_libMagickCore_la-png.o
      _ReadOnePNGImage in magick_libMagickCore_la-png.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[1]: *** [magick/libMagickCore.la] Error 1
make: *** [all] Error 2
I have not changed any other options to configure.
How can I fix this to add libpng support?

A:
You'll need to tell ImageMagick where to locate libpng. Luckily, libpng ships with a configuration script entitled "libpng-config".
You can get the link-library option form your local libpng install with the --L_opts flag.
libpng-config --L_opts
This will return something like -L/usr/local/lib. Set ImageMagick's LDFLAGS configuration to match your libpng library.
# Use the returned value for the LDFLAGS
./configure LDFLAGS='-L/usr/local/lib'
If libpng-config returns with a message 'command not found', you'll need to ensure your libpng is installed correctly, and can be located in your shell environment. Often, this can be as simple as adding a custom path to your PATH variable.
export PATH="$PATH:/usr/local/bin"

2013年7月23日星期二

git 如何取消跟踪某个文件呢?

$ git rm --cached FILENAME

就可以了.
该操作不会删除原来的文件,同时取消对文件的版本变化跟踪.

2013年7月21日星期日

[转] 解决 ios 使用AdMob遇到 -[GADObjectPrivate changeState:]: unrecognized selector sent to instance 问题

解决 ios 使用AdMob遇到 -[GADObjectPrivate changeState:]: unrecognized selector sent to instance 问题

iso使用AdMob时如遇到-[GADObjectPrivate changeState:]: unrecognized selector sent to instance 0x968c980情况,请在编译选项里linking中的other link flag加上-ObjC,否则蛋碎都找不到原因。

2013年7月16日星期二

[转] add Admob with Cocos2d-x on iOS

add Admob with Cocos2d-x on iOS

1. download admob, setup your account


2. add admob to xcode project. You need:
    - add libGoogleAdmobAds.a to bundle libraries
    - create a group and add admob header file

3.  in AppController.h, add member:     
@interface AppController : NSObject <
UIAccelerometerDelegate, UIAlertViewDelegate, UITextFieldDelegate,UIApplicationDelegate, GADBannerViewDelegate> {
    UIWindow *window;
    RootViewController    *viewController;
    GADBannerView* bannerView_;
}

4. in AppController.mm
    // setup admob
    
    // Create a view of the standard size at the bottom of the screen.
    // Available AdSize constants are explained in GADAdSize.h.
    bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
    bannerView_.delegate = self;
    // Specify the ad's "unit identifier." This is your AdMob Publisher ID.
    bannerView_.adUnitID = @"YOUR_ID";
    
    // Let the runtime know which UIViewController to restore after taking
    // the user wherever the ad goes and add it to the view hierarchy.
    bannerView_.rootViewController = viewController;
    [viewController.view addSubview:bannerView_];
    
    
    // Initiate a generic request to load it with an ad.
    GADRequest* adRequest = [GADRequest request];
    [bannerView_ loadRequest:adRequest];

    // start game
    cocos2d::CCApplication::sharedApplication()->run();

5. we are not over Yet!!!
    You'll have exceptions if running the app now. You must do this:
(http://stackoverflow.com/questions/12635283/admob-crashes-with-gadobjectprivate-changestate-unrecognized-selector)
You need to add -ObjC to the Other Linker Flags of your application target's build setting:

Click the blue top-level project icon in XCode
Choose your target and go to Build Settings
Under Other Linker Flags add -ObjC for both Release and Debug

Done!!!
Let's make money and go IPO :)