Default Green Orange
grzegorz brzezinka.eu
Be curious. Laugh a lot.
    Home Page Home
  • Contact
RSS

Posts Tagged ‘tips&tricks’

RoR: Railroad plugin with Rails 2.3.5 on Windows error

Ruby 4 Comments »

While looking for a tool that’d help me to generate the database schema diagram, I’ve found RailRoad Ruby gem. However, it was not working with my Rails 2.3.5 + Ruby 1.8.7 on Windows. While running railroad in command line, I was getting an error:

 c:/Ruby/lib/ruby/gems/1.8/gems/railroad-0.5.5/lib/railroad/app_diagram.rb:54:in 'reopen': No such file or directory - /dev/null (Errno::ENOENT)

(...)

This seemed to me as an error similar to RoR: plugin install from GIT repository in Windows error. And luckily it was!

Solution

The soultion is as follows:

  1. Go to %ruby_installation_directory\lib\ruby\gems\1.8\gems\railroad-0.5.5\lib\railroad\ and open app_diagram.rb in a text editor.
    (%ruby_installation_directory is c:\Rails by default)
  2. Around line 54 find:
    STDOUT.reopen(PLATFORM =~ /mswin/ ? "NUL" : "/dev/null")

    and change it to:

    #STDOUT.reopen(PLATFORM =~ /mswin/ ? "NUL" : "/dev/null")
    	STDOUT.reopen('NUL:')
  3. Open controllers_diagram.rb in the same directory with a text editor.
  4. Around line 39 find:
    require "app/controllers/application.rb" 

    and change it to:

    require "app/controllers/application_controller.rb" 
  5. That’s all! Now you can create for example your Rails project models schema (having Graphvis installed) just typing in command line:
    railroad -a -i -M | dot -Tpng > models.png

Create tasks

To automate the process of creating schemes, you can create Rails task. In your rails_project_dir/Libs/tasks create diagrams.rake and copy the text:

namespace :doc do
  namespace :diagram do
    task :models do
      sh "railroad -a -i -M | dot -Tpng > doc/models.png"
      sh "railroad -i -l -a -m -M | dot -Tsvg doc/models.svg"
    end

    task :controllers do
      sh "railroad -i -l -C | neato -Tsvg > doc/controllers.svg"
    end
  end

  task :diagrams => %w(diagram:models diagram:controllers)

end

Now you can run the task by typing in console: rake doc:diagrams to generate all diagrams (for models an controllers) or rake doc:diagram:models to generate diagram for models only.

Due to the information on RailsRoad Docs, there is a bug in Graphvis while crating svg graphic. There is a simple way to correct it (citation from RailsRoad Docs):

Important: There is a bug in Graphviz tools when generatingSVG files that cause a text overflow. You can solve this problem editing (with a text editor, not a graphical SVG editor) the file and replacing around line 12 „font-size:14.00;” by „font-size:11.00;„, or by issuing the following command (see „man sed„):

sed -i 's/font-size:14.00/font-size:11.00/g' file.svg

Note: For viewing and editing SVG there is an excellent opensource tool called Inkscape (similar to Adobe Illustrator.) For DOTprocessing you can also use Omnigraffle (on Mac OS X).


Maj 3rd, 2010  
Tags: Ruby on Rails, tips&tricks



RoR: plugin install from GIT repository in Windows

Ruby 0 Comment »

Since Ruby 1.8.7 and Rails 2.3.5 under MS Windows system there is a common error when you run:

%rails_project_directory> ruby script/plugin install git://github.com/user/project.git

The problem is that no matter what variations and workarounds through comman line would you try:

%rails_project_directory>ruby script\plugin install http://github.com/user/project.git/

you always get the error:

Plugin not found: [git://github.com/user/project.git]

Certainly you could just download a from GIT project and copy/clone it to the vendor/plugins directory of your project. However you must admit it is a pain. Each time I installed manually  a git-hosted plugin (so almost in 95% of Rails plugins :-P ), I spent about half an hour looking for a solutions. And this morning I’ve eventually found it on www.ruby-forum.com.

Soultion

The soultion is as follows:

  1. Install msysgit if you haven’t done it yet.
  2. Go to %ruby_installation_directory\lib\ruby\gems\1.8\gems\activesupport-2.3.5\lib\active_support\core_ext\kernel and open reporting.rb in a text editor.
    (%ruby_installation_directory is c:\Rails by default)
  3. Around line 38 find:
    stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')

    and change it to:

    #stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
    stream.reopen('NUL:')
  4. Save the file and live in a joy and happiness of working git hosted Rails plugin installation

Maj 1st, 2010  
Tags: Ruby on Rails, tips&tricks



utf8 in WordPress 2.8 database connection (PL: problem z kodowaniem polskich znaków w WordPress)

WordPress Komentowanie nie jest możliwe

Recently I had problem with coding polish diacritic signs (ąćęśźółń). Webpage encoding was set to UTF-8 (both for front and backstage). It seemed to be a database problem. Following

Marzec 23rd, 2010  
Tags: encoding, tips&tricks, wordpress



Touchsmart tx2 1050ew problem (and solution) – keyboard not working!

computer 1 Comment »

In the middle of the day, suddenly the keyboard of my laptop together with all the surrounding buttons (volume etc.) stopped working! After the reboot, as the ESC button (it enters BIOS) was not responding while starting the computer, it seemed like a hardware problem. Damn, I have work to do! – I thought.

Hp TouchSmart tx2 1050ew

Hp TouchSmart tx2 1050ew

Luckily, my notebook is a tablet, so I could use touchscreen keyboard. I was about to look for the instruction how to remove the keyboard from the notebook. Imagine what was my relief when I found the solution: HP Touchsmart TX2 keyboard failure (and the cure) at Laurent Bugnion blog. He had exactly the same problem and got help from HP support. The cure is simple:

  1. Unplug the power and remove the battery.
  2. Hold the power sliding button for about 3 min (yeah, this is painful).
  3. Still holding the power button, plug the power cable.
  4. Release the power button and turn on the computer :-)

As I’ve read elsewhere, the notebook has hardware shipping keyboard lock. It seems it has been somehow reactivated during my work. It is just enough to discharge all capacitors and that’s it – the lock removed, keyboard working like a charm.


Marzec 20th, 2010  
Tags: hardware, hp touchsmart tx2, notebook, tips&tricks



Gmail address case- and dot insensitive

webmaster tips 2 Comments »

Do you use gmail? If so, good choice ;-) It has a lot of useful features!

I wanted to send an e-mail to a friend who once told me that his address is jacksmith@gmail.com (common practice)… or it was jack.smith@gmail.com? Hmm…
Read the rest of this entry »


Marzec 18th, 2010  
Tags: google, tips&tricks



How to have plugins rendered (processed) when generating PDF from Joomla article content?

Joomla 0 Comment »

Recently, I’ve been working on Joomla CMS based project, where I’ve added some additional features to the content (AJAX added content from database) using Jumi plugin.

In standard Joomla installation, by clicking PDF icon in top right corner of the article, you can generate a PDF version of your content. However, plugins are not processed: instead you will see plugin tags, ie. {jumi [test.php}. How to get it processed?

Solution (for Joomla 1.5)

I have found the solution on phpGTK2 CookBook. Quickly summarizing:

  1. Edit view.pdf.php localized in <joomla root>/components/com_content/views/articles.
  2. Around line 72 (just before $document = &JFactory::getDocument();), add two lines that triger plugin processing:
  3. JPluginHelper::importPlugin('content');
    $results = $dispatcher->trigger('onPrepareContent', array (& $article, & $params, 0));
    

    So the whole code in the neighbourhood of line 72 should look like this:

    // process the new plugins
    JPluginHelper::importPlugin('content', 'image');
    $dispatcher->trigger('onPrepareContent', array (& $article, & $params, 0));
    
    JPluginHelper::importPlugin('content');
    $results = $dispatcher->trigger('onPrepareContent', array (& $article, & $params, 0));
    
    $document = &JFactory::getDocument();
    
    // set document information
    $document->setTitle($article->title);
    $document->setName($article->alias);
    $document->setDescription($article->metadesc);
    $document->setMetaData('keywords', $article->metakey);
    

This is it! Now after clicking PDF icon, all your plugins should be processed in the output document. However, not all CSS is processed… but this is another story ;)


Marzec 17th, 2010  
Tags: Joomla, tips&tricks, webmastering



Joomla FishEye menu (Camp26) with jQuery in no conflict mode

Joomla 18 Comments »

Recently I had to implement a fish menu on a client website based on Joomla CMS. As the deadline was short, I decided to look for a script or module.

Open Source Script (javascript)

First I came across Fisheye Menu by Marc Grabanski. This is an open source script, maybe the mouseover effect is not compelling and extremely spectacular, but it does it job good and, what is really important, is quite easy to implement. You’ll find a firendly tutorial written by John Kolbert.

Fisheye menu script

Fisheye menu script (click to view it in action!)

Joomla module

Looking through Joomla Extension directory I have found non-commerial FishEye Menu from Camp26 team. It looks  much more similar to Mac-like Dock bar than the Grabanski’s script. It is based on jQuery and interface element script. The module is Joomla 1.5 native.

FishEye Menu Module by Camp26

FishEye Menu Module by Camp26

jQuery in non-conflict mode

The only problem is… the Camp26 module needs jQuery working in a normal mode, ie. using $(…) syntax:

$(document).ready(function() {
     ...
});

Joomla 1.5 has MooTools included as default javascript framework. Adding to this some components using Prototype, it is highly recommended to use jQuery in a non-conflict mode, ie. using jQuery(…) instead of $(…) syntax:

jQuery.noConflict();
jQuery(document).ready(function(){
       ...
});

The jQuery javascript framework may be easily included to your Joomla CMS in the non conflict mode with SC jQuery plugin.

Make FishEye Menu module work in non conflict mode

Normally, adopting a script to work with jQuery in non conflict mode is quite easy: just find&replace all $(… with jQuery(… . However, in case of that module it is not that easy. It was encrypted by Code26 team in order to protect from editing. Instead of regular javascript code you will find something like:

eval(function(p,a,c,k,e,d){e=function(c){return(c&lt;a?'':e(parseInt(c/a)))+(...)

Fortunately, it is not a dead end. The solution is to put the encrypted content inside:

jQuery(document).ready(function($) {
    $('sth').removeClass();
});

As you can see, inside this structure a regular $(…) syntax may be used.

So finally, we have to edit:

  • fisheye.js and iutil.js modifying it as written above:
    (...)
    jQuery(document).ready(function($) {
        eval(function(p,a,c,k,e,d){e=function(c){return(c&lt;a?'':e(parseInt(c/a)))+(...)
    });
    
  • default.php by simply replacing $(…) with jQuery(…) (in two places in code).

That’s it – now the module is properly working with jQuery in non conflict mode.

Here you can download a modified module.


Marzec 9th, 2010  
Tags: Joomla, tips&tricks, webmastering



jQuery and WordPress

jQuery 0 Comment »

Chris Coyier & Jeff Starr in their Digging into WordPress blog present an easy and efficiet way to include jQuery in WordPress.

It works ;-)


Marzec 9th, 2010  
Tags: jQuery, tips&tricks, wordpress



Redirect page through .htaccess

webmaster tips 0 Comment »

Some time ago I have changed my hosting provider. I’ve turned to http://www.site5.com as my old provider http://www.nazwa.pl lacked of several useful options.

As a consequence, I had to move several websites to a new server… You know, a nightmare changing configuration files in different CMSes…

I have faced the following problem: some of the websites were stored in subfolders (subdomains), let’s say /blog (http://www.mydomain.com/blog). After the change, we want to have the website available under the main domain http://www.mydomain.com. How to do it?

Well, the answer seems to be quite simple: copy all files to your main directory and… sadly some elements are not working. Why? It turned out that some elements references still targeted to elements in /blog. There are two solutions:

  1. Manually change the path of each element (ex. using find&replace). But if you have thousends of files + entries in database… This may drive you crazy after a while, you can imagine. Far  better solution is:
  2. Create/modify the .htaccess file in the /blog directory:
    Redirect /blog http://www.mydomain.com

That’s it :-) The latter applies also if you want to redirect a subdomain to another web address.


Marzec 7th, 2010  
Tags: .htaccess, domain, hosting, tips&tricks, webmastering



Next Entries
  • Newest posts

    • Export to Excel (xls) in Rails3
    • Linux: how to renew DHCP IP address?
    • Full page background image in Prawn PDF in Rails3
    • Github error – fatal: Unable to look up github.com (port 9418) (Name or service not known)
    • RubyGems warning/error: Gem::Specification# default_executable = is deprecated with no replacement. It will be removed on or after 2011-10-01.
  • Tags

    human body eye hosting domain movie image google brain gym Math .htaccess wordpress science riddle Joomla webmastering fun Rails3 jQuery Ruby on Rails tips&tricks
  • In the blog you’ll find:

    • Funny (3)
      • Riddles (2)
    • interesting facts (1)
    • linux (1)
    • Projects (1)
    • science (5)
      • computer (1)
      • human body (1)
      • Math (1)
      • physics (1)
    • Uncategorized (2)
    • webmaster tips (23)
      • Joomla (2)
      • jQuery (6)
      • Rails3 (5)
      • Ruby (11)
      • WordPress (1)
  • Translate!

      Translate to:

      Powered by Google Translate.
Copyright © 2012 grzegorz brzezinka.eu All Rights Reserved
XHTML CSS Zaloguj się
Designed by iSoftware Reviews and