суббота, 24 ноября 2012 г.

Fedora and broadcom b43 wireless and b44 wired drivers

Tricks, tricks, tricks... They are always present when you are working with linux systems.
This may be actual for =< Fedora 17. There is great fedoraforum.org article about broadcom wireless drivers.
Open b43 (broadcom wireless) driver seems can work together with b44 (broadcom wired) driver, but not too well. On high load, for example - torrents, he can do such error:
ping: sendmsg: No buffer space available

And after that you may reload wireless or a whole system to make work it again. So temporary solution is to unload b44 module when wireless needs to be more stable at work.
Way to unload right now:
 sudo modprobe -v -r b44  
And we will get something like this:
 rmmod b44  
 rmmod mii  
Also for a long term it possible add to blacklist:
 sudo vim /etc/modprobe.d/blacklist.conf  
 blacklist b44  
p.S. Seems there is interesting solution with broadcom-wl drivers. This could also work with b43.

четверг, 15 ноября 2012 г.

jQuery UI in Drupal7

From the first sight looks easy but a bit tricky. Ok, we wanna use jQuery UI.
Yes, drupal7 has jquery ui in its core. But:
1) Its in old version. Because of that examples from http://jqueryui.com/ may not work. So we have to use jQuery update.
2) Its not enabled by default.
We need to insert to our code function:

 drupal_add_library('system', 'ui');  

Now we can try jquery ui coding.

воскресенье, 26 августа 2012 г.

Apache and mysql service bash aliases

ap - i mean apache service
my - i mean mysql service

 vim .bashrc  

Paste next lines:

 alias apstart="sudo systemctl start httpd.service"  
 alias apstop="sudo systemctl stop httpd.service"  
 alias aprestart="sudo systemctl restart httpd.service"  
 alias mystart="sudo systemctl start mysqld.service"  
 alias mystop="sudo systemctl stop mysqld.service"  
 alias myrestart="sudo systemctl restart mysqld.service"  

Thats it.

пятница, 24 августа 2012 г.

Vim gnome desktop file

Example .desktop file to select vim terminal editor for your files in the Open with other application dialog is (also you can found it at the "Programs" gnome3 meny tab):

 [Desktop Entry]  
 Name=Vim Text Editor (Console)  
 Comment=Edit text files in a console using Vim  
 Exec=vim %u  

Save it as:

Also I used that icon for vim. And put file into:


Fedora post installation guide

Some simple tricks, some details are always forget. Good idea to update guide  in nearest future. Skype, vim files...

Yum update

Fastest mirror yum plugin. RPM download should be faster.
 su -c 'yum install yum-fastestmirror'  

Anyway we can now add rpmfusion repos:

 su -c 'yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm'  


 su -c 'yum update -y'  

Configuring sudo

While update going on we can configure sudo.
 su --login -c 'vim /etc/sudoers'  

Look for line:
 root ALL=(ALL) ALL  
and than add this after it:
 username ALL=(ALL) ALL  
Where "username" is you current system username.

Also we should not need ask for pass when using sudo.
Comment this line:

 # %wheel ALL=(ALL) NOPASSWD: ALL  

And uncomment this:

 #%wheel ALL=(ALL)    NOPASSWD: ALL  

Done, save file and exit.

Add user to wheel group

 su -c 'gpasswd -a username wheel'  

Check it

 $ sudo whoami  


Lets do simple aliases.

 vim .bashrc   

Add this lines:

alias update="sudo yum update" 
alias install="sudo yum install" 
alias upgrade="sudo yum upgrade" 
alias remove="sudo yum remove" 


MS fonts

Maybe a good idea. Download rpm.

Packages are might be useful:

 sudo yum -y install mc vim p7zip unrar wget evince-djvu gstreamer-plugins-good gstreamer-plugins-bad gstreamer-plugins-ugly gstreamer-ffmpeg  

You also may want to install fixed fonts and configure gnome terminal:

 install bitmap-fixed-fonts  

...and isntall nautilus terminal extention.

 install nautilus-open-terminal  

понедельник, 16 июля 2012 г.

Sublime Text 2 fedora manual install

Ok, here is my trick. Nothing serious, just some additional preferences.
Download original file from developer site.
Move directory to /opt

 sudo mv Sublime\ Text\ 2 /opt/sublime2  

Lets check it:

 cd /opt/sublime2 


Next is /usr/bin sublime file:

 touch /usr/bin/sublime 

 chmod 755 /usr/bin/sublime  

Lets edit it to start sublime from /opt directory:

 gedit /usr/bin/sublime  

Add these lines to /usr/bin/sublime file:


 export SUBLIME_HOME="/opt/sublime2" 


 $SUBLIME_HOME/sublime_text $*  

Thats good. Now sublime command should work from terminal.
Next is .desctop file:

 sublime /usr/share/applications/sublime.desktop  

You should paste these lines:

 [Desktop Entry] 



 Comment=Sublime Text Editor 

 Exec=sublime %U 







Finish. System restart and logout are not necessarily.

четверг, 31 мая 2012 г.

Fedora & drupal7 + mysql install

Nothing difficult. Its my recipt and its case of taste how you can configure your development environment.
Lets install http server and mysql:
 yum groupinstall 'Web Server' 'MySQL Database'   

Drupal7 and phpmyadmin:
  yum install drupal7 phpmyadmin   

Mysql server start:
 systemctl start mysqld.service   

Password for mysql server root user:
 mysqladmin -u root password $PASSWORD   

Selinux disable.
In my opinion its less problems if selinux disabled at development workstation. But I do not recommend to disable it on production sites.
Disable link.

Configure drupal.conf:
 gedit /etc/httpd/conf.d/drupal7.conf   

Uncomment lines below to have site access by yourself: 
 Allow from   

Configure php.ini file. Rise up memory limit, file upload limit and enter your timezone.
 gedit /etc/php.ini   

I prefer working with localhost, where your development sites links looks like:
  • example.tst
  • commerce.tst
I am using drupal multisite feature and host drupal file into /home/www/sites directory instead of  default way.
Lets create required directory, symbol link, drupal sites files to new directory, add a $username and apache users to each groups and own drupal files by current user.
  rm /usr/share/drupal7/sites   
  mkdir /home/www   
  mkdir /home/www/sites   
  ln -s /home/www/sites /usr/share/drupal7   
  cp -f -r /etc/drupal7/* /home/www/sites  
  mkdir /home/www/sites/example.tst  
  cp -f -r /home/www/sites/default/* /home/www/sites/example.tst  
  gpasswd -a $username apache   
  gpasswd -a apache $username   
  cd /home   
  chown $username www -R   
  chgrp $username www -R   

Lets add custom localhost:
 gedit /etc/hosts   

That line:     example.tst   

Lets add apache virtual host:
 gedit /etc/httpd/conf/httpd.conf   
Scroll down to virtual hosts section, and uncomment line:
 NameVirtualHost *:80   

Then add new localhost to apache server:
 &lt;VirtualHost *:80&gt;  
   ServerAdmin username@example.com   
   DocumentRoot /usr/share/drupal7   
   ServerName example.tst   

Lets start apache:
 systemctl start httpd.service   

Now we can check, enter to your browser

Easy way to create databases is at:

Thats it.

вторник, 15 мая 2012 г.

Very simple SimpleTest drupal example

It was done to check basics of drupal SimpleTest work.
Module part just created a menu page with some "Hello World" text.
Test should check:

  1. If drupal slice generated by SimpleText exists
  2. If menu page exists
  3. If menu page has a string "Lets test it!"
Module code:
1:  <?php  
3:  function alternative_example_menu() {  
4:   $items['alt_example'] = array(   
5:    'title' => 'Hello World test example',  
6:    'description' => 'Its easy and fun',  
7:        'page callback' => '_alt_example_basic_instructions',  
8:    'page arguments' => array(t('Hello World')),   
9:    'access callback' => TRUE,  
10:    'type' => MENU_NORMAL_ITEM,  
11:   );  
12:   return $items;  
13:   }  
15:   function _alt_example_basic_instructions($content = NULL) {  
16:   $base_content = t('Lets test it!');  
17:   return '<div>' . $base_content . '</div><br />';  
18:  }  

Test code:
1:  <?php  
3:  /**  
4:   * @file  
5:   * Tests for alternative example module.  
6:   */  
7:  class AlternativeExampleTestCase extends DrupalWebTestCase {  
8:   protected $custom_user;  
10:   public static function getInfo() {  
11:    return array(  
12:     'name' => 'Hello world example functionality',  
13:     'description' => 'Checks "Hello world" string and page',  
14:     'group' => 'Alternative Examples',  
15:    );  
16:   }  
18:   /**  
19:    * Enable modules and create user with specific permissions.  
20:    */  
21:   public function setUp() {  
22:    parent::setUp('alternative_example');  
23:   }  
24:   function testAlternativeHelloExample() {  
25:        // Load site  
26:    $this->drupalGet('');  
27:    // Load page  
28:    $this->clickLink(t('Hello World test example'));  
29:    // Look for string  
30:    $this->assertText(t('Lets test it!'));  
31:   }  
32:   }  

Web output:

Also there is possible to run SimpleTest through drush:

Nothing enormous. Tests should run faster if they will done like unit tests way but i should check that option next time.

воскресенье, 25 марта 2012 г.

array_rand function alternative

Strange thing happened with array_rand function after PHP 5.2.10 Release... I should paste it from official site:

"The resulting array of keys is no longer shuffled." 
C'mon i dont even understand now how it works. Anyway some good man make good and also elegant alternative, when you need to shuffle an array and take some entries from it.

 function array_random($arr, $num = 1) {  
   $r = array();  
   for ($i = 0; $i < $num; $i++) {  
     $r[] = $arr[$i];  
   return $num == 1 ? $r[0] : $r;  
 $a = array("apple", "banana", "cherry");  
 print_r(array_random($a, 2));  

среда, 7 марта 2012 г.

taxonomy name save programmatically

Drupal 7 In this tick we will save taxonomy name into node taxonomy field programmaticaly.
Basic data:

  • taxonomy name (ex. 'John Doe')
  • taxonomy field (ex. field_term)
  • we dont have this taxonomy name in our vocabulary
  • we have this taxonomy name in our vocabulary
  • Drupal taxonomy field saves only 'tid' not title
Soliution is simple. We must save not existing taxonomy name before programmaticall node save.
Here is some (maybe not perfect) code:

 $term_name = 'John Doe';  
 $term_array = taxonomy_get_term_by_name($term_name);  
 if($term_array == array()) { # empty term .. we can save new taxonomy  
      $term->name = $term_name;   
      $term->vid = 1;   
      taxonomy_term_save($term); # here  
      $term_array = taxonomy_get_term_by_name($term_name); # call agaim, we need a 'tid' for save  
      foreach ($term_array as $tid => $term_object)  
      $node->field_term[$node->language][0]['tid'] = $term_object->tid;  
       } else {  
       $term_array = taxonomy_get_term_by_name($term_name);  
      foreach ($term_array as $tid => $term_object)  
           $node->field_term[$node->language][0]['tid'] = $term_object->tid;  

вторник, 6 марта 2012 г.

php string function

Elegant way to extract certain words or letters from a string. Found at php.net.
 /* subtok(string,chr,pos,len)  
  * chr = chr used to seperate tokens  
  * pos = starting postion  
  * len = length, if negative count back from right  
  * subtok('a.b.c.d.e','.',0)   = 'a.b.c.d.e'  
  * subtok('a.b.c.d.e','.',0,2)  = 'a.b'  
  * subtok('a.b.c.d.e','.',2,1)  = 'c'  
  * subtok('a.b.c.d.e','.',2,-1) = 'c.d'  
  * subtok('a.b.c.d.e','.',-4)  = 'b.c.d.e'  
  * subtok('a.b.c.d.e','.',-4,2) = 'b.c'  
  * subtok('a.b.c.d.e','.',-4,-1) = 'b.c.d'  
 function subtok($string,$chr,$pos,$len = NULL) {  
  return implode($chr,array_slice(explode($chr,$string),$pos,$len));