2015年11月17日 星期二

Paypal say "Data does not match input character set or default encoding" when WooCommerce Wordpress Checkout with Chinese words

Recently I am playing with Wordpress and WooCommerce shopping Cart plugin for wordpress to setup a simple E-commerce website, while I am using a plugin to add some extra info to my product ( WooCommerce Extra Fields ) with some chinese character, it randomly give me "Data does not match input character set or default encoding" during checkout.

After some digging on the network call, I found that the product name is in the Paypal link, and the chinese word is trimmed and become weird character.

I found the trim function wc_trim_string is the one to be blamed, and it is using php substr function.

The original wc_trim_string function in "woocommerce/include/wc-formatting-functions.php" contains the line:

 $string = substr( $string, 0, ( $chars - strlen( $suffix ) ) ) . $suffix;


i just replaced it with mb_substr and everything works like charm again. End result will look like:

 $string = mb_substr( $string, 0, ( $chars - strlen( $suffix ) ) ) . $suffix;


The reason is that substr function just trim without handling multiple-byte unicode character, and mb_substr is multi-byte safe.

This workaround should works on other multibyte/unicode character.

Note: Version of my WooCommerce is v2.4.8

2013年3月17日 星期日

[Android] AsyncTask blocking

In different Android version, there is different handling on AsyncTask, some are in single thread, processed one by one, some are multi-threaded and processed at the same time.

1.0-1.5(API 1-3) single thread.
1.6-2.3.3 (API4-10) multi thread.
3.0+ (API 11 or up) single thread.

but if you want to have AsyncTask run on seperate thread, you can call
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
instead of
    task.execute(params);

then the task will run on seperate thread, and not blocked by other threads.

2012年11月16日 星期五

[WPF]Background dynamic fill with one direction

I have a very long and thin image, and I want to use it as a background image in WPF application, which the image should repeat horizontally.
My first code insight is from
WPF: How do i create a background that repeats horizontally without scalling?
But, it fails to repeats properly, the reason is that ViewportUnits="Absolute", so it actually stretch my image to very large. Which is kind of hardcode.

Then I saw this reference TileBrush.Viewport Property
So I use this this code to create the background brush instead
  <imagebrush imagesource="/Resources/Image/pattern.png" 
            tilemode="FlipY" viewport="0,0,0.033,1" 
            viewportunits="RelativeToBoundingBox"
            x:key="BackGroundBrush">
Which 0.033:1 is the width:height ratio of my background. With this brush, the image will be stretch to suitable height.

For repeat horizontally, just change tilemode to FlipX and viewport to "0,0,1,x" where 1:x is the ratio.

p.s. this method is a improved version of the stackoverflow solution on the way that it can show the whole image, but the drawback is the image might be stretched for a little. And seems there is no simple way to do this without binding.

2012年10月21日 星期日

Why Weibo SSO sdk don't jump back to my iOS app

This question is for those didn't watch the documentation of the SSO-sdk(me as an example).

The callback url is not set in the web. It should be placed when you initiate the SinaWeibo instance. It is provided 2 init method and they are:
-(id) initWithAppKey:(NSString*)_appKey 
           appSecret:(NSString *)_appSecrect 
      appRedirectURI:(NSString *) _appRedirectURI
         andDelegate:(id)_delegate 
and
- (id)initWithAppKey:(NSString *)_appKey 
           appSecret:(NSString *)_appSecrect 
      appRedirectURI:(NSString *) _appRedirectURI
   ssoCallbackScheme:(NSString *)_ssoCallbackScheme
         andDelegate:(id)_delegate
We should use the latter one and put the callback Uri as ssoCallbackScheme, then everything will be work fine.

2012年10月18日 星期四

Time to String? Date Format Patterns?

To convert time to string, we always use formats like "yyyy-MM-dd HH:mm:ss", but sometimes we want something more like "18 Oct 2012" or "Wed 12:34:56", then the reference page can help you.
Date Format Patterns

With the table in the page, you should be good enough to do more tricks on date formats.

2012年10月15日 星期一

[iOS] Why no privacy alerts in simulator?

This is not a bug. This is the restriction on simulator.
From the iOS6.0 release note, we seen that apple doesn't the privacy alerts in simulator.

Simulator

  • No privacy alerts are displayed in iOS Simulator for apps that access Photos, Contacts, Calendar, and Reminders.
  • For this release, iOS Simulator does not support testing In-App Purchase. Please use a device to test your apps that use this feature.
  • When attempting to play an MP3 sound in Simulator, you will hear a popping sound instead.
Source:iOS6.0 release note

Reset iPhone Privacy

To clear/reset iPhone Privacy Settings like contacts and location services, you can go to Settings and follow the routine:
Settings -> General -> Reset -> Reset Privacy and Location

Which is useful for developer, as the privacy prompt only prompt once if you never reset.