طبقه بندی موضوعی

۴ مطلب در آذر ۱۳۹۱ ثبت شده است

Sublime Text به نظر من، یک ویرایشگر بسیار عالی است.

می خواهیم Sublime Text را  نصب کنیم.

1. آخرین نسخه را  از سایت sublime Text دانلود می کنیم.

۲.  پس از دانلود، از حالت فشرده خارج می کنیم.

tar xf Sublime\ Text\ 2.0.1\ x64.tar.bz2

۳. پس از اکسترکت کردن، تمام فایل های ویرایشگر، در داخل این پوشه قرار دارد. پس کل پوشه را به یک جای خوب (مانند مسیر /opt/)منتقل (move) می کنیم.

sudo mv Sublime\ Text\ 2 /opt/

۴. در برخی جاها می خواهیم Sublime Text را صدا بزنیم. تا باز شود. می توانیم در ترمینال با تایپ کردن sublime ، ویرایشگر را باز کنیم. برای این کار، یک لینک ثابت در /usr/bin قرار می دهیم.
sudo ln -s /opt/Sublime\ Text\ 2/sublime_text /usr/bin/sublime

۵. حالا که فایل ها را در جای مناسب قرار دادیم. ما نیازمند یک launcher در یونیتی هستیم. برای این کار یک فایل با پسوند .desktop  در مسیر /usr/share/applications می سازیم:

sudo sublime /usr/share/applications/sublime.desktop

و کدهای زیر را داخل فایل sublime.desktop قرار می دهیم.

[Desktop Entry]
Name=Sublime Text 2
# Only KDE 4 seems to use GenericName, so we reuse the KDE strings.
# From Ubuntu's language-pack-kde-XX-base packages, version 9.04-20090413.
GenericName=Text Editor

Icon=/opt/Sublime Text 2/Icon/48x48/sublime_text.png

[NewWindow Shortcut Group]
Name=New Window
Exec=sublime -n

6. حال می خواهیم sublime text را به عنوان ویرایشگر پیش فرض قرار دهیم.به مسیر /usr/share/applications/defaults.list می رویم و تمام gedit.desktop ها را به sublime.desktop تغییر می دهیم. و در نهایت فایل را ذخیره می کنیم.

sudo sublime /usr/share/applications/defaults.list

Recently I installed lampp on a CentOS 5 development server. My personal computer is Windows 7 so I also installed Samba so that I can directly access the files by mapping the network drive. You don’t really care about all that though. Since I like to do things with as few steps as possible it really annoyed me that I had to start Apache and Samba every time I started the server. So I have it now setup to auto start both Apache and Samba. It was easy to do.

Setting Apache To Start on Boot

Step 1 – Check to make sure the httpd(Apache) is installed

[root#] chkconfig --list|grep http

This looks for the httpd service in the list of services running on your machine. If Apache is installed properly then you should see

[root#] 0:off  1:off  2:off 3:off 4:off 5:off 6:off

Step 2 – Set httpd to auto start

This is a pretty easy straight forward command that sets Apache to start on boot

[root#] chkconfig httpd on

Step 3 – Confirm the Apache is set to auto-start

Just to make sure that every took, lets check again to see that httpd is set to auto-start

[root#] chkconfig --list|grep http

and you should see something like:

[root#] 0:off  1:off  2:on 3:on 4:on 5:on 6:off

Setting Samba To Start on Boot

The steps for this are identical except you just need to change the service name:

[root#] chkconfig --list|grep smb
[root#] 0:off  1:off  2:off 3:off 4:off 5:off 6:off
[root#] chkconfig smb on
[root#] chkconfig --list|grep smb
[root#] 0:off  1:off  2:on 3:on 4:on 5:on 6:off

I wanted some auto populating Select boxes in a site I was creating so that when I changed a Category the Subcategories would automatically update. CakePHP can do this pretty easily but it is let down by the documentation as there are no examples.

Initially I came up with a version that wrote JSON into a JavaScript variable in the page and then used jQuery to achieve the updating of select elements but I wanted to do this the Cake way which uses AJAX and as little code as possible.

Here is a simplified solution to demonstrate how it can be done.

This assumes a new CakePHP site already configured with a database connection. I used CakePHP 2.0.3 but this may also work with 1.3 (?)

1. Models

We need 3 associated tables

CREATE TABLE `categories` (
  PRIMARY KEY (`id`)
INSERT INTO `categories` (`id`, `name`)
CREATE TABLE `posts` (
  `subcategory_id` INT(10) UNSIGNED DEFAULT NULL,
  PRIMARY KEY (`id`)
INSERT INTO `posts` (`id`, `title`, `subcategory_id`)
	(1,'The title',1),
	(2,'A title once again',4),
	(3,'Title strikes back',7);
CREATE TABLE `subcategories` (
  `category_id` INT(10) UNSIGNED DEFAULT NULL,
  PRIMARY KEY (`id`)
INSERT INTO `subcategories` (`id`, `category_id`, `name`)

Bake the 3 Models for these and allow CakePHP to define model associations for you.

2. Controllers

Bake a Controller for the Post Model with the default CRUD actions.

While you are at it you will also need to bake the CRUD Views for the Post Controller.

If you browse to the posts index page now you can view the data.
In this example I will add the Category and Subcategory select lists to the Add view, so now we need to change this so that the selection in the second list changes according to the selection in the first list.
This will be done via the Js Helper so make it available at the top of the Posts controller (after the Class declaration) with:

public $helpers = array('Js');

You need a Subcategories Controller with a single action to provide the data via AJAX:

App::uses('AppController', 'Controller');
class SubcategoriesController extends AppController {
	public function getByCategory() {
		$category_id = $this->request->data['Post']['category_id'];
		$subcategories = $this->Subcategory->find('list', array(
			'conditions' => array('Subcategory.category_id' => $category_id),
			'recursive' => -1
		$this->layout = 'ajax';


The view is a very simple AJAX view that renders the option tags that go within the select tag.

<!-- file path View/Subcategories/get_by_category.ctp -->
<?php foreach ($subcategories as $key => $value): ?>
<option value="<?php echo $key; ?>"><?php echo $value; ?></option>
<?php endforeach; ?>

4. Putting it all together

In the Post Add view, file path: View/Posts/add.ctp we can finally add the Js methods that make the dynamic updating happen. This is the cryptic bit that I struggled with for a few hours as although the CakePHP documentation outlines all the options there are not any complete examples.
Firstly add a categories select element to the form (and change the order of the elements):

	echo $this->Form->input('category_id');
	echo $this->Form->input('subcategory_id');
	echo $this->Form->input('title');

Add the following code to the bottom of the view, this uses the Js Helper to create the necessary jQuery to perform the updating:

		), array(
		'async' => true,
		'method' => 'post',
		'data'=> $this->Js->serializeForm(array(
			'isForm' => true,
			'inline' => true

This is saying – watch the HTML element with Id PostCategoryId for a change. When it changes update the HTML element with Id PostSubcategoryId with the response from subcategories/GetByCategory, the data option is used to send the current value from the initial select element.

Before you leap to test this you need to make changes to the default layout to include jQuery and provide a place for your scripts to be written out.

// file path View/Layouts/default.ctp
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
	<?php echo $this->Html->charset(); ?>
		<?php echo $title_for_layout; ?>
		echo $this->Html->meta('icon');
		echo $this->Html->css('cake.generic');
	<div id="container">
		<div id="header">
			<h1>Dynamic Select Box Demonstration</h1>
		<div id="content">
			<?php echo $this->Session->flash(); ?>
			<?php echo $content_for_layout; ?>
		<div id="footer">
	<?php echo $this->element('sql_dump'); ?>
	<script type="text/javascript" src=""></script>
	<!-- scripts_for_layout -->
	<?php echo $scripts_for_layout; ?>
	<!-- Js writeBuffer -->
	if (class_exists('JsHelper') && method_exists($this->Js, 'writeBuffer')) echo $this->Js->writeBuffer();
	// Writes cached scripts

Now you can test the application. On changing the category select list, the subcategory one will automatically update to show the relevant options.

A friend told me about Aptana Studio, an Open Source web development IDE. I think I used it years ago but then switched to NetBeans for some reason. After taking a look at Aptana’s website I decided I wanted to try it again. Below are three simple steps I followed to install Aptana Studio in Fedora 15.

1.Download Apatana Studio 3 from and extract the content of the downloaded zip file.

2.Move Aptana Studio 3 to a standard location

mv Aptana\ Studio\ 3 /usr/local/aptana-studio-3

3.Create a file /usr/share/applications/aptana.desktop with the following content:

[Desktop Entry]
Name=Aptana Studio 3
Comment=The professional, open source development tool for the open web
GenericName=Aptana Studio

Although Aptana can be easily run just after you download the application, I like to have menu entries for most of the software I use, hopefully I’m not the only one who thinks like that and the above can help them.