magic fields in wordpress

Custom fields in wordpress is a surprise, with custom post type wordpress suddenly become the first choice for out-of-box CMS system.

There are many plugin around, the most of them require some medium level PHP skill to change template or theme.

Some cool plugins like Custom Post type UI, just custom post type and advanced custom type. But those plugin still have one problem to solve, how to make the input UI easier to use. One common problem is in the input screen, custom field displayed twice, and still give user flexibility to add other custom fields.

Custom field template suppose fix it, but it seems still need PHP code change somewhere.

Magic fields 2 solved this problem eventual, by introducing some style middle tables at backend, the admin UI looks much cleaner. And data storage is still in post_metadata.

 

 

 

About these ads

Sharing internet connection with VMWare guest

  1. Network adapter must set to host only (NAT/Bridge won’t work).
  2. On host, control panel->network and sharing center ->change adapter settings, pick the regular ‘Local Area Connection’, rename the other ‘Local Area Connection 2′ used by VMWare hosting to ‘VMWare Host Network’ for clarification. Right click on Local Area Connection, select sharing tab, allow sharing internet connection with ‘VMWare Host Network’. Note: ip address on VMWare Host Network will change to something like 192.168.137.1
  3. Stop VMware DHCP Service at service panel, set this service to manual startup type.
  4. Reboot guest. After reboot, guest should get a new ip in 192.168.137 subnet.
  5. Set http proxy in guest in necessary. Note: in RubyMine, svn has it’s own http settings tab.

 

 

AWS Spot instance

Concept

Compare to on-demand instance which costs about $0.02/h, spot instance price starts from $0.006, almost a third of the other one. Running a micro instance for a month will be only $4.5.

Why so cheap? One possible reason would be, on-demand instances are charged by hour, which means even if you only used it for one minute then stop your instance immediately, you will still be charged for the full hour.

The only drawback for spot instance is that there is no guarantee for server instance to continue running. When market price goes up, spot instance will be terminated. Try to pick a quiet region if you can, e.g., us-east-1b price history seems very stable  0.006/h for a month, even for past 3 months ( only 2 spikes on Apr. 23)

When instance terminated, all data will be lost. Root ebs will be deleted automatically. If state data is needed, an extra ebs can be attached as user-data storage.There are many different posts showing how to attach another ebs during start-up, like coding in rc.d

http://ec2dream.blogspot.ca/search/label/EBS

http://www.ioncannon.net/system-administration/199/automounting-amazon-ebs-volumes-on-ec2-instances/

but the easiest way is to set it in request, ec2 tool kit only.

ec2-request-spot-instances -p 0.006 -t t1.micro -n 1 -b ‘/dev/sdf=snap-a023dfdf::false’ ami-746fc91d -z us-east-1b -k mykeypaire -g my-group -r persistent

  1. Can not use sda1 (root), otherwise error: snapshotId cannot be modified on root device
  2. /dev/sdx start from a letter >f, in the example it uses b, I encountered an error saying snap id can only be changed on ebs device.
  3. Don’t forget the key-value pair and security group. They are key to access.
  4. -r persistent means repeat request.

Setup OS (environment, tools, your app, etc)

Spot instance should start working for your order immediately after request fulfilled, the perfect solution would be start from your private AMI.

Create AMI

To create an AMI is to request a on-demand instance, setup everything you need, then

  • Option A: created from an existing instance, better to stop the instance before
  • Option B: create an ebs snapshot, from which create a new image.

Write down your image id. then request spot instance. Request can be done through AWS console or ec2 tool kit.

Setup ec2 tool kit

Download zip file from http://developer.amazonwebservices.com/connect/entry.jspa?externalID=368&categoryID=88

Simply following http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/setting-up-your-tools.html

export EC2_HOME=~/tools/ec2…
export JAVA_HOME=/usr

Generate X509 cert following  http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/using-credentials.html#using-credentials-certificate
upload those 2 files to your work machine under  ~/.ec2 folder

$ export EC2_PRIVATE_KEY=~/.ec2/pk-blahblah.pem
$ export EC2_CERT=~/.ec2/cert-blahblah.pem

Test setup using a command like ec2-describe-regions

It should work.

Those export and path setup can be put into ~/.bash_profile or ~/.bashrc

Manually attach ebs

Created a new ebs 1G

Attach to new instance manually in AWS console
device name will change to /dev/xvdf from /dev/sdf in ubuntu

ebs needs format before mount

sudo mkfs -t ext3 /dev/xvdf
sudo mount -t ext4 /dev/xvdf /home/ubuntu/folder_to_mount

ref: http://yoodey.com/how-attach-and-mount-ebs-volume-ec2-instance-ubuntu-1010

Set trust scp/ssh for rc2 instance on your own VPS

local: ssh-keygen -t dsa -f $HOME/.ssh/id_dsa -P ”
remote:(~/.ssh) cat id_dsa >> authorized_keys

ref: http://www.csua.berkeley.edu/~ranga/notes/ssh_nopass.html

Bad news, spot instance is not included in free tier.

All the saving cost export I spent so far seems useless, and I will revisit this post when my 12 month free tier expired.

SSL3_GET_SERVER_CERTIFICATE error in JJ’s VPS manager

If you like me own a busy VPS at dreamhost, you probably already falling in love with JJ’s VPS manager, a tool to dynamically adjust server memory according server load.

Everything works OK until today I got SSL3_GET_SERVER_CERTIFICATE error.

CURL encountered an error. ‘SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed’

Because it happens on my two different VPSs,  I doubt it’s Dreamhost API server problem. Google results turn out there is a way to ignore server certificate.

Quick workaround:

  1.  vi ~jj/libs/DH_API/dreamhost.api.php
  2. find curl_setopt
  3. add the following 2 lines
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

Restart daemon, JJ seems happy now.

I know it’s not safe, if you know what’s happening on Dreamhost API server, please notify me to add those check back.

 

Apple TV, AirPlay

I need to do an iOS dev presentation this weekend at a local user group, one problem to solve is to connect my iPad to their projector. I know there is iPad to VGA or HDMI cable, cost about $40-50, Apple TV seems a much better solution, AirPlay should solve the problem easily.

Hook up AppleTV to my receiver is easy, only wifi password basically. I need to turn on the iTunes Home sharing feature on my MacMini, then on AppleTV I can see that shared iTunes library. Surprised Apple requests AppleID to turn home sharing on, all info save on their server?

Watched a few trailers, Hunger Games, AV quality is awesome. My daughter quickly took it over and starting watch youtube on AppleTV.

One annoying limitation for Youtube on AppleTV is no Chinese input, so can’t search Youtube with Chinese titles. Solution is login with youtube id, then can play youtube playlist created on somewhere else.

Remote control for AppleTV is cute, but too small for my hand, download the app called remote for my iPad, I can then control AppleTV on iPad. It’s good for playing music without turn on real TV.

About AirPlay, not many apps support this feature yet. Photos is one of them, but not Videos! Some people end up with converting their powerpoint file to separated images to be able to play on project through AirPlay.

Luckily, I have a iPad2. Turn on AirPlay mirroring feature on it and everything shows on iPad can be outputted to TV. Cool!

The app I developed, including iClip and maodou, are using iOS native media player, AirPlay doesn’t have any problem. But one of the app I purchased called OPlayer, AirPlay only works for the sound. no video. I had to back to another app called streamtome to play those non-h264 videos on my computer.

Cloud means surprise

I have been looking for an opportunity to work on queue base project after finishing Udi Dahan’s Advanced distributed system design course. Because most of my projects are running on Linux OS where NSerivceBus is not applicable, using Amazon SQS became a affordable work around for now.

Problem to solve

My iClip iOS app recently encountered  unexpected popular requests for unknown reason (listed somewhere on an iOS app category site?). Even I only grant every new client only 3 free requests, with the huge amount of daily downloads, my server becomes slow and unstable gradually.

I could keep bumping up the memory on server, but I don’t like this solution at all. First, server hosting bill will go up dramatically; second, hosting server memory still has a max limitation of 4GB. Someday the client requests will eventually break this ceiling, then what?

Solution

I decided to move my request model to queue based architecture based on Amazon’s SQS service. Rewriting app didn’t take very long. After a week of production experience, here are some gotcha I’ve learned.

  1. Message won’t be immediately available after send. Amazon actually state this delay will be up to 60 seconds on SQS admin console.
  2. Deleted message might still be visible in queue. Explanation from Amazon is:
    It is possible you will receive a message even after you have deleted it. This might happen on rare occasions if one of the servers storing a copy of the message is unavailable when you request to delete the message. The copy remains on the server and might be returned to you again on a subsequent receive request. You should create your system to be idempotent so that receiving a particular message more than once is not a problem.
  3. For the similar reason as above, queue processor should really deal with duplicated request very carefully. For me, I use sendtimestamp as the identity of message.
  4. Receiving message must set the visibility time out to a value greater than zero, to allow this message to be deleted successfully afterwards. (To be confirmed)

Re-configure dreamhost evniorment to support Amazon WebService

I was trying to make my dreamhost to support Amazon WebService (aws), the first problem I encountered is, missing libxslt.

Following the instruction here, I managed to install libxslt to my custom location.

Watch out, the link on http://xmlsoft.org/XSLT/downloads.html is actually pointing to libxml2 which doesn’t include libxslt. You want to find the correct link from ftp://xmlsoft.org/libxslt/

 

The next problem is openssl support missing from ruby. I had to re-configure ruby to make it openssl ready. Instruction can be found here.

 

All aws samples passed, then.

With one minor issue left, I got warning when running ruby:

Invalid gemspec in [/home/me/.gems/specifications/openssl-extensions-1.2.0.gemspec]: invalid date format in specification: “2011-11-03 00:00:00.000000000Z”

Hope I can figure this out later.

Share static html in MVC views

PartialView can be used to share page content, but our shared content are purely static and would like to share it among multiple web apps, doesn’t have to be MVC apps.

We have tried SSI (Server side include) on IIS,  but it turns out it doesn’t work in Razor view. Spuriously, many people said SSI is dead, and by default IIS7 doesn’t turn SSI on, here is the doc how to install and configure SSI on IIS7. install it, configure it (if your included file is not named as shtm)

For now the best solution I found is putting this code in Razor view.

@MvcHtmlString.Create(File.ReadAllText(Server.MapPath(“/_shared/footer.htm”)))

WIF, STS, MVC

We are looking for the 3rd party access management product, one of the requirements is STS support. Here is the procedure how to create a test STS client:

  1. Download WIF runtime and the WIF SDK – http://msdn.microsoft.com/en-us/evalcenter/dd440951.aspx
  2. Create a new MVC Project in VS 2010
  3. On the project right-click, select “Add STS reference” and follow the same wizard steps as the WebForms application. (to add the WIF information to web.config file.)
  4. Set the app pool to be able to load user profile in advanced settings panel.
  5. Create self-signed SSL, make certificate accessable by app pool, as descirbed in https://identity.thinktecture.com/download/startersts/v1/StarterSTS_InitialSetup.wmv
  6. DO NOT use “Add deployable dependencies” on MVC project when deploying webapp, otherwise the deployed webapp will be redirected back to /account/login from STS.

After tested with the local STS, we tried to switch to StarterSTS – http://startersts.codeplex.com/ as the 2nd test STS, then we can’t figured out how to add the customized claim type  into user profiles, claim type format like “http://schemas.myorg.ca/2011/10/OrganizationId”. Even though, the tutorial from startersts is still great helpful, http://identity.thinktecture.com/download/starterSTS/v1/StarterSTS_FederatingWebApps.wmv
Other useful tools like STSFederationMetadataEditor can be used to edit the WS-Federation of the STS on the fly.

YouTrack Gotcha

LDAP integration

Our ldap connection string is something like ldap://dcxx:389/DC=domain,DC=gov,DC=ds, a little bit different than the example given ldap://xxx:389/cn=users,dc=domain,dc=com

Also, needs to enable user registration via registration page, otherwise ldap user cannot login.

By default, newuser (All Users) group already has admin role added in, so ensure you remove it before allow ldap user login, otherwise all new users will be admin!

TeamCity integration

New YoutTrack project code must be added in TeamCity Tracking module, otherwise issue tab does not show in teamcity build dashboard.

The way YouTrack link to TeamCity is not by userid or name, instead it is by email address. It’s strange our YouTrack can grab email from our ldap server, while TeamCity can’t! This leaves the email field in user project empty in teamcity. When we try to use comments command, the error message was, user not found, no email specified for user (commiter).

Command in Comments

Comment format: your own comment. #PROJECT_ID-1 state Fixed

Watch out, don’t add .(dot) after fixed.

more command example: http://confluence.jetbrains.net/display/TSYSD/Quick+Start+Guide.+Using+YouTrack+command+window

Project assignee

Newly created project doesn’t have any team member in it, the result is when trying to assign a issue, error message just kept saying assignee expected.