Warning: Declaration of WPSDAdminConfigAction::render() should be compatible with WPSDWPPlugin::render($ug_name, $ug_vars = Array, $action = NULL) in /var/www/html/code/wp-content/plugins/wp-stats-dashboard/classes/action/WPSDAdminConfigAction.php on line 42
:: vee.in.th/code ::

Basic Facebook’s Open Graph Tags (OG) for your wordpress blog

1. Create a new file in your theme folder (e.g. wp-content/themes/Your-theme/) named social-og.php Fill with this stuff

	// Helper function to render og tags
	function print_tag($property, $content) {
		echo "<meta property=\"$property\" content=\"$content\" />\n\r";

	$default_img = 'http://yoursite.com/Your-default-image.jpg';

	// If the page is of posts (is_single()) or pages (is_page())
	if (is_single() || is_page()) {
		$id = get_the_ID();
		print_tag('og:url', get_permalink($id));
		print_tag('og:type', 'website');
		print_tag('og:title', get_the_title($id));

		if ($excerpt = get_the_excerpt($id)) {
			print_tag('og:description', $excerpt);
		} // I haven't figured this out yet, but sometimes my excerpt returns empty

		if ($post_thumbnail_id = get_post_thumbnail_id($id)) {
			$image_attributes = wp_get_attachment_image_src($post_thumbnail_id, 'large', 0);
			print_tag('og:image', $image_attributes[0]);
		} // Do not put og:image tag if it doesn't exist, so that facebook can fetch whatever image that is in the page
	// For homepage, archive page, etc
	} else {
		print_tag('og:url', get_bloginfo('url'));
		print_tag('og:type', 'website');
		print_tag('og:title', get_bloginfo('name'));
		print_tag('og:description', get_bloginfo('description'));
		print_tag('og:image', $default_img);


2. Include social-og.php in your header.php by placing this code below <title> or somewhere within <head></head>)

<?php get_template_part('social', 'og'); ?>

Run out of memory? (Cannot allocate memory)

If composer shows proc_open() fork failed on some commands:

PHP Fatal error: Uncaught exception ‘ErrorException’ with message ‘proc_open(): fork failed – Cannot allocate memory’ in phar

This could be happening because the VPS runs out of memory and has no Swap space enabled.

free -m

total used free shared buffers cached
Mem: 2048 357 1690 0 0 237
-/+ buffers/cache: 119 1928
Swap: 0 0 0

To enable the swap you can use for example:

/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1

source: https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors

Forward/Change your Node.js app port from port 3000 to port 80

I redirect port 80 to port 3000 with this command:

sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000

Then I launch my Node.js on port 3000. Requests to port 80 will get mapped to port 3000.

You should also edit your /etc/rc.local file and add that line minus the sudo. That will add the redirect when the machine boots up. You don’t need sudo in /etc/rc.local because the commands there are run as root when the system boots.

source: http://stackoverflow.com/a/16573737

Install any version of Node.js on CentOS 6 using NVM

I’m not sure if the ‘yum’ install works on other CentOS or not. But I come across the problem that I get some problems with upgrading NodeJS from v0.10 to v5.4.0 on CentOS. I don’t know what I should do so I started clean, and found that install nvm is super easy then install NodeJS itself. (And the perk is that you can have multiple versions of Node.js that you want!)

I don’t know about the perf though. Feel free to share if you do!

How to do:

Follow the instruction here: https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-a-centos-7-server

(Section “Install Node Using the Node Version Manager”)

For short:

curl https://raw.githubusercontent.com/creationix/nvm/v0.13.1/install.sh | bash
source ~/.bash_profile
nvm list-remote
nvm install v5.4.0 # or whichever version you'd like
nvm list # must have v5.4.0 show in the list
nvm use v5.4.0 # use it
nvm alias default v5.4.0 # set default node
node --version # there should show v5.4.0


Install Virtualenv with Wrapper for OSX and zsh

Get necessary lib

sudo easy_install pip #probably don't need to sudo
sudo pip install virtualenv #probably don't need to sudo
sudo pip install virtualenvwrapper #probably don't need to sudo

Append this to ~/.zshrc (the file is hidden)

# set where virutal environments will live
export WORKON_HOME=$HOME/.virtualenvs
# ensure all new environments are isolated from the site-packages directory
# use the same directory for virtualenvs as virtualenvwrapper
# makes pip detect an active virtualenv and install to it
if [[ -r /usr/local/bin/virtualenvwrapper.sh ]]; then
    source /usr/local/bin/virtualenvwrapper.sh
    echo "WARNING: Can't find virtualenvwrapper.sh"

You might need to restart your zsh.

Creating env

mkvirtualenv testenv

it will access the env automatically

Feel free to ‘pip’ anything now

pip install rq

more at: http://mkelsey.com/2013/04/30/how-i-setup-virtualenv-and-virtualenvwrapper-on-my-mac/