Harry Seldon's blog

Psychohistory on Rails

Read

Some useful commands in Linux administration when making a website.

Posted by Harry Seldon on September 27, 2008

This is a cheatsheet of useful commands in Linux administration when making a website in Rails. I am using these commands over and over again so I thought it might help someone.

Linux 
—–
Detailed list of files 
    ls -l 
List the running processes 
    ps -e  
Create a directory 
    mkdir demo 
Kill the use of a specific port (I use it when Aptana/RadRails crashes and do not close the port) 
    fuser -k 3005/tcp  
Delete a directory and subdirectories, without confirmation, verbose mode. (BE CAUTIOUS !) 
    rm 20080120165422/ -r -f -v  
Add a cron jon 
    crontab cron_job.txt 
List cron jobs  
    crontab -l 
Create cron job 
    crontab -e 
Mount a local virtual directory for an actual remote directory 
    sshfs ‘-oworkaround-rename’ username@ssh.domain.com: /home/username/remote/ 
 
MySQL 
—–
Connect to mysql local server: 
    mysql -u username -p 
Connect to mysql remote server: 
    mysql -u username -h mysql.domain.com -p 

Create databases (Rails style) 
    CREATE DATABASE demo_development; 
    CREATE DATABASE demo_test; 
    CREATE DATABASE demo_production; 

Rails 
—–
Create a rails app 
    rails demo  
Install a plugin 
    script/plugin install git://github.com/pullmonkey/open_flash_chart.git 
Install a plugin, force reinstall 
    script/plugin install git://github.com/pullmonkey/open_flash_chart.git –force 
Launch server on a specified port 
    script/server -p 3005  
Open a console where you can send ruby commands to your app (Extremely useful!) in dev mode
    script/console development
Open a console where you can send ruby commands to your app (Extremely useful!) in prod mode (BE CAUTIOUS !)
    script/console production
Migrate the database 
    rake db:migrate 
Migrate the database to a given version  
    rake db:migrate VERSION-22 
Migrate the production database 
    rake db:migrate RAILS_ENV-production 
Install gem  
    gem install RedCloth 
Install a given version of Rails 
    gem install -v-2.0.2 rails  

Git  

Checkout a repo 
    git clone git://github.com/pullmonkey/open_flash_chart.git   
Get the differences 
    git diff 
Fetch from and merge with another repository or a local branch 
    git pull 
Checkout  
    git checkout 
Configure the user settings 
    git config –global user.name "toto" 
    git config –global user.email "toto@example.com" 

H

Posted in | no comments |

A Rails/OFC/Ajax raw example

Posted by Harry Seldon on September 27, 2008

Here is a simple exercise to use Rails, OFC, OFC rails plugin and ajax together. The idea is just to follow the example given here in php. At first I did not manage to get this working. That is why I asked some help to Pullmonkey. He did a great job to make this working in this nice post . Moreover, he came up with nice improvements on OFC to render a chart using ajax and using Rails helper to keep a pretty code (you need to update OFC plugin to make his example work). However I want to show you here the translation in Rails of Teethgrinder’s tutorial with minimum code (no need to update OFC plugin).

Controller code (test_it_controller.rb), notice it has the original php code from teethgrinder in it.

class TestItController < ApplicationController
def tuto_5
    title = Title.new("tuto_5")
    #$title = new title( date("D M d Y") );
    #$chart = new open_flash_chart();
    @chart = OpenFlashChart.new
    #$bar = new bar();
    bar = BarGlass.new
    #$bar->set_values( array(9,8,7,6,5,4,3,2,1) );
    bar.set_values([1,2,3,4,5,6,7,8,9])
    #$chart->set_title( $title );
    @chart.set_title(title)
    #$chart->add_element( $bar );
    @chart.add_element(bar)
end
end

Then I had directly coded the view code (tuto5.html.erb) without helpers (and quite ugly) :

<head>
<script type="text/javascript" src="/javascripts/json2.js"></script>
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
</head>

<body>
<script type="text/javascript">
swfobject.embedSWF("/open-flash-chart.swf", "my_chart", "350", "200", "9.0.0");
</script>
<script type="text/javascript">

function ofc_ready()
{
    alert('ofc_ready');
}

function open_flash_chart_data()
{
    alert( 'reading data' );
    return JSON.stringify(data);
}

function findSWF(movieName) {
  if (navigator.appName.indexOf("Microsoft")!= -1) {
    return window[movieName];
  } else {
    return document[movieName];
  }
}

var data = <%= @chart.to_s %>;
</script>

<p>Hello World</p>
<div id="my_chart"></div>
</body>

In this example you need the json2.js library that you can find here. However notice that Pullmonkey uses directly the json capabilities of Rails which is a much better way.
This code works, you can check it out here.

Thanks to Pullmonkey ! H

Posted in | no comments |

A Rails/OFC/Ajax example

Posted by Harry Seldon on September 27, 2008

Following this nice work from Pullmonkey, here is a small example on how to use OFCII to dynamically load a chart. We will display a line chart and then dynamically add one more line.

Controller code (test_it_controller.rb):

class TestItController < ApplicationController
def index_js_3_line
   title = Title.new("Multiple Lines")

    data1 = [5, 3, 4, 1, 3, 2, 5, 4, 3, 3]
    data2 = [12, 9, 9, 7, 8, 8, 9, 9, 8, 9]
    data3 = [16, 14, 17, 18, 14, 15, 16, 18, 15, 15]

    line_dot = LineDot.new
    line_dot.text = "Line Dot"
    line_dot.width = 4
    line_dot.colour = '#DFC329'
    line_dot.dot_size = 5
    line_dot.values = data1

    line_hollow = LineHollow.new
    line_hollow.text = "Line Hollow"
    line_hollow.width = 1
    line_hollow.colour = '#6363AC'
    line_hollow.dot_size = 5
    line_hollow.values = data2

    line = Line.new
    line.text = "Line"
    line.width = 1
    line.colour = '#5E4725'
    line.dot_size = 5
    line.values = data3

    y = YAxis.new
    y.set_range(0,20,5)

    x_legend = XLegend.new("MY X Legend")
    x_legend.set_style('{font-size: 20px; color: #778877}')

    y_legend = YLegend.new("MY Y Legend")
    y_legend.set_style('{font-size: 20px; color: #770077}')

    chart = OpenFlashChart.new
    chart.set_title(title)
    chart.set_x_legend(x_legend)
    chart.set_y_legend(y_legend)
    chart.y_axis = y

    chart.add_element(line_dot)
    chart.add_element(line_hollow)
    @chart = chart
  end

  def some_server_data_line
    title = Title.new("Multiple Lines")

    data1 = [5, 3, 4, 1, 3, 2, 5, 4, 3, 3]
    data2 = [12, 9, 9, 7, 8, 8, 9, 9, 8, 9]
    data3 = [16, 14, 17, 18, 14, 15, 16, 18, 15, 15]

    line_dot = LineDot.new
    line_dot.text = "Line Dot"
    line_dot.width = 4
    line_dot.colour = '#DFC329'
    line_dot.dot_size = 5
    line_dot.values = data1

    line_hollow = LineHollow.new
    line_hollow.text = "Line Hollow"
    line_hollow.width = 1
    line_hollow.colour = '#6363AC'
    line_hollow.dot_size = 5
    line_hollow.values = data2

    line = Line.new
    line.text = "Line"
    line.width = 1
    line.colour = '#5E4725'
    line.dot_size = 5
    line.values = data3

    y = YAxis.new
    y.set_range(0,20,5)

    x_legend = XLegend.new("MY X Legend")
    x_legend.set_style('{font-size: 20px; color: #778877}')

    y_legend = YLegend.new("MY Y Legend")
    y_legend.set_style('{font-size: 20px; color: #770077}')

    chart =OpenFlashChart.new
    chart.set_title(title)
    chart.set_x_legend(x_legend)
    chart.set_y_legend(y_legend)
    chart.y_axis = y

    chart.add_element(line_dot)
    chart.add_element(line_hollow)
    chart.add_element(line)

    render :text => chart.to_s
  end
end

And in the view (index_js_3_line.html.erb):

<html>
  <head>
    <%= javascript_include_tag :defaults, 'swfobject' %>
  </head>
  <body>
    <%= @chart.js_open_flash_chart_object("my_chart_js_1", 550,300) %>
    <br/><br/>
    <%= @chart.link_to_ofc_load("Load Original Chart", "my_chart_js_1") %> ||
    <%= @chart.link_to_remote_ofc_load("Load Chart from server data", "my_chart_js_1", "/test_it/some_server_data_line") %>
  </body>
</html>

You can see this example in live here : http://www.thinkosphere.com/test_it/index_js_3_line.

Actually there is some “cheating” involved. Indeed we simply load a first chart and then reload a new chart identical with one more line. Next step is to load once the whole graph and to dynamically modify the JSON Data to display one line or another.

H

Posted in | no comments |

Ranking rankings

Posted by Harry Seldon on September 01, 2008

Web 2 is a lot about grading and ranking. So I guess it is logical that bloggers themselves get ranked. However there are dozens of ranking systems. Thus bloggers get their revenge: they can rank the ranking systems !
Ouriel Ohayon made a great post (in French) here and he asks the following :
Which ranking is, according to you, the most meaningful ?
You can answer below:

As I am coding the poll website thinkosphere.com you probably already know that I am a huge fan of internet polls, even if they currently lack too many features. Thanks to this post I discovered one more lacking feature : publishing a poll in several languages. I do not know about a poll engine offering this capability. I guess I will have to do it myself !

H

Posted in | no comments |

2 tricks for Firefox, 1 for KDE

Posted by Harry Seldon on August 22, 2008

I noticed these nice firefox 3 features haphazardly :
On the tab bar : 
you can duplicate a tab thanks to a ctrl+click
you can move the tabs left or right using your mouse scrolling button

By the way, one thing I do not understand for Firefox is why open new tab does not open your start page ?

1 trick for KDE
Right click on a window name bar and you have the option to keep the window above others. That is nice to do some copy/paste from one page to a notepad or also to keep the command line while typing code in an IDE….
 

Posted in | no comments |

Some News and Tech Links about Ruby and Rails

Posted by Harry Seldon on August 22, 2008

Some News and Tech Links about Ruby and Rails

You are looking for info about Rails ? Here are some useful links.

News
Railsinside
Rubyinside
Railsenvy
Nuby on rails
locomotivation
peepcode
Stone age blog (in French)
I assume you already know the official website.

API
http://api.rubyonrails.org/
http://www.ruby-doc.org/core-1.8.6/index.html
http://start.gotapi.com/
http://www.railsbrain.com
NB Some people find api.rubyonrails.org hard to use. I just use the google toolbar to make a “search on this website” and I get the info I was looking for in 0.1 sec. Equivalently you can search on google using site:api.rubyonrails.org.

Book
http://pragprog.com/titles/rails3/agile-web-development-with-rails-third-edition

Forum
http://www.ruby-forum.com

Posted in | no comments |

Tile windows on Linux

Posted by Harry Seldon on August 09, 2008

In the same kind of ideas as my post on 2 monitors, it would be great to be able to tile windows under Gnome or KDE. Some people thought about it as some softs do it : whaw or a compiz plugin (but using compiz to do that is really an overkill).

Posted in | no comments |

Ubuntu Global Bug Jam in Toulouse

Posted by Harry Seldon on August 09, 2008

I went yesterday night to the Ubuntu Global Bug Jam. The session in Toulouse was organized by Christophe Sauthier, Ubuntu-Fr association president and toulibre association. Many thanks to them !

Posted in | no comments |

Wifi on Linux

Posted by Harry Seldon on August 08, 2008

I installed Kubuntu Feisty about one year ago. That was my first Linux installation. Since then I got plenty of troubles with my (pci) wifi card a WMP54G with a ralink rt61 chipset. But the most surprising is that each time you update the ubuntu version you need to setup again but differently your wifi network. My first advice is use a wirewith connection as much as you can. My second advice is if you have a rt61 chipset just change it. A wireless card is not that expensive. I should have done that one year ago, I would have avoided many troubles. Under Feisty Fawn after some work the wifi was perfectly working in wpa. With Gutsy Gibbon it was working ok but only in wep. And with Hardy Heron, it is working in wep but I still have some weird problems. The wifi card does not wake up from suspend ot hibernate and if my router is rebooted I cannot connect. In all cases I need to reboot. Here is my configuration.

Posted in | no comments |

Installing Typo : trackbacks and markup

Posted by Harry Seldon on August 07, 2008

After installing Typo 5.1.2, I had some troubles with mail capabilities. My second problem came from the trackbacks. Typo should add a trackback link at the end of an article (see below "Use the following link to trackback"). However, this link was not added even if the "allow trackbacks" option was activated in Typo.After some more debugging, it simply appeared that this was due to the theme. I had downloaded a new theme (techblue) but this theme like others at typogarden are not updated for Typo 5.

A beginning of solution is to copy all files from themes/typographic/articles to themes/techblue/articles.

Another question I had is how to use Markdown or textile markups with Typo. I was using the default mode to write content but actually you need to be in source mode.

Posted in | no comments |

Older posts: 1 2 3 4

Search