WebTechKitchen; Your Web Technology Kitchen, contact us to create, or maintain your websites and other digital properties.

Adding a node to an organic group programmatically

Submitted by barnettech on Wed, 05/15/2013 - 10:04

To add a node to an organic group programmatically this code absolutely works as of May 15th 2013.  There are a lot of articles on the web I've read with either incorrect code or outdated code:

 

$entity = node_load($nid); 
$values = array('entity_type' => 'node', 'entity' => $entity, 'field_name' => 'og_group_ref', 'state' => 1);
og_group('node', $row->gid, $values);
node_save($node);

 

Plug for my Drupal Course I'm teaching at Babson this Summer

Submitted by barnettech on Sat, 03/16/2013 - 08:35

The course begins July 9, 2013 and ends August 22, 2013  The class is available completely remotely, or on Tuesday nights from 6 - 9:10 pm EST I will be on Babson campus presenting the class.  But Tuesday night's classes will still be broadcasted over the internet for our remote students.  Here's the course description:

Tip of the Day: have your mac command prompt tell you which git branch you're in

Submitted by barnettech on Fri, 02/22/2013 - 09:50

A colleague just shared this tip with me to have my Mac command prompt tell me which git branch I'm in:  Put the following in your .bash_profile

 

function parse_git_branch () {

  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'

}

 

export PS1="\h:\W \u\$(parse_git_branch)\$ "

Now my command prompt looks like this in a git directory:  belldev2:docroot barnettech (master)$

Too many connections error

Submitted by barnettech on Thu, 02/21/2013 - 10:30

If you're getting a too many connections error on your Drupal site and the site is down -- likely once a day.  Never fear, here is the answer ... this blog just suffered through that, and just upgrading Drupal to the newest version -- all modules as well, solved the problem.  Yes i don't get paid to write this blog and it suffered some down time, as it doesn't bill as top priority, so sorry for that folks.  Anyhow, might I suggest you use drush to keep your Drupal install up to date.

Run:  drush @your_alias_name up  

What to do if your Drupal site gets attacked by spammers and Black Hat SEO

Submitted by barnettech on Wed, 02/13/2013 - 11:15

So your site is being attacked with lots of spam user registrations and comments, and even nodes, what should you do.

1.)  Install the Mollom module

   -- configure mollum by going to the mollum website http://mollom.com/ and get your free api keys.  You can get a paid account for larger corporate sites.

VIM tip of the day

Submitted by barnettech on Mon, 01/28/2013 - 15:31

to delete or yank (copy) a whole function try this:

If you're on a parentheis, or curly bracket or even a quote sign you can always hit the % sign to go to the closing parentheis, curly bracket or quote sign in vim.  So you can instead do "d%" to delete all in between said quotes, curly brackets, or parenthis or you can do "y%" to yank the lines (copy) and then later go to where you want to paste those yanked lines and hit the "p" key.

Yes finally.  Great for when you're refactoring your code and moving functions around.

Basic Linux Hardware analysis Notes:

Submitted by barnettech on Thu, 01/17/2013 - 15:43

How many php procs are running:  ps -A | grep php-cgi | grep -v grep | wc -l

 

A box with a 1 minute load average of 6.92 should have been below 2 if it had a 2 cpu core.

 

To find how many cpu cores there are:

cat /proc/cpuinfo  (or just type cat /proc/cpuinfo| grep processor| wc -l to get how many cpus)

4 processor core would look like

processor : 0

vendor_id : GenuineIntel

<---SNIP--->

processor : 1

vendor_id : GenuineIntel

<---SNIP--->

processor : 2

vendor_id : GenuineIntel

Make Drupal's l( function just be a false link for javascript pointing to the # (hash) sign

Submitted by barnettech on Thu, 01/10/2013 - 12:29

Make Drupal's l( function just be a false link for javascript pointing to the # (hash) sign

This works and is in production for us:

l(t('Start Chat'), '', array('attributes' =>
        array('title' => array('Start Chat with ' . $row2->full_name)),
          'fragment' => ' ', 'external' => TRUE)) 

Using Kcachegrind to profile your code

Submitted by barnettech on Tue, 01/08/2013 - 10:07

1.)  Install xdebug -- I'm running MAMP so it's already installed and in php.ini I just needed to turn it on here are my settings:

[xdebug]

zend_extension="/Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"

;xdebug.profiler_output_dir = "/tmp/xdebug/"

;xdebug.profiler_enable = On

xdebug.remote_enable=On

xdebug.remote_host="belldev"

xdebug.remote_port=9000

;xdebug.remote_handler="dbgp"

;xdebug.idekey=ECLIPSE_DBGP

;xdebug.remote_mode=jit