Client

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

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

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]
Version=1.0
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

Exec=sublime
Terminal=false
Icon=/opt/Sublime Text 2/Icon/48x48/sublime_text.png
Type=Application
Categories=TextEditor;IDE;Development
X-Ayatana-Desktop-Shortcuts=NewWindow

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

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` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(60) DEFAULT NULL,
  PRIMARY KEY (`id`)
);
 
INSERT INTO `categories` (`id`, `name`)
VALUES
	(1,'books'),
	(2,'music'),
	(3,'electronics');
 
CREATE TABLE `posts` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `title` VARCHAR(50) DEFAULT NULL,
  `subcategory_id` INT(10) UNSIGNED DEFAULT NULL,
  PRIMARY KEY (`id`)
);
 
INSERT INTO `posts` (`id`, `title`, `subcategory_id`)
VALUES
	(1,'The title',1),
	(2,'A title once again',4),
	(3,'Title strikes back',7);
 
CREATE TABLE `subcategories` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `category_id` INT(10) UNSIGNED DEFAULT NULL,
  `name` VARCHAR(60) DEFAULT NULL,
  PRIMARY KEY (`id`)
);
 
INSERT INTO `subcategories` (`id`, `category_id`, `name`)
VALUES
	(1,1,'fiction'),
	(2,1,'biography'),
	(3,1,'children'),
	(4,2,'classical'),
	(5,2,'rock'),
	(6,2,'jazz'),
	(7,3,'camera'),
	(8,3,'audio'),
	(9,3,'tv');

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:

<?php
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->set('subcategories',$subcategories);
		$this->layout = 'ajax';
	}
}

3. Views

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):

<?php
	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:

<?php
$this->Js->get('#PostCategoryId')->event('change', 
	$this->Js->request(array(
		'controller'=>'subcategories',
		'action'=>'getByCategory'
		), array(
		'update'=>'#PostSubcategoryId',
		'async' => true,
		'method' => 'post',
		'dataExpression'=>true,
		'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.

<?php
// file path View/Layouts/default.ctp
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<?php echo $this->Html->charset(); ?>
	<title>
		<?php echo $title_for_layout; ?>
	</title>
	<?php
		echo $this->Html->meta('icon');
 
		echo $this->Html->css('cake.generic');
	?>
</head>
<body>
	<div id="container">
		<div id="header">
			<h1>Dynamic Select Box Demonstration</h1>
		</div>
		<div id="content">
 
			<?php echo $this->Session->flash(); ?>
 
			<?php echo $content_for_layout; ?>
 
		</div>
		<div id="footer">
			footer
		</div>
	</div>
	<?php echo $this->element('sql_dump'); ?>
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
	<!-- scripts_for_layout -->
	<?php echo $scripts_for_layout; ?>
	<!-- Js writeBuffer -->
	<?php
	if (class_exists('JsHelper') && method_exists($this->Js, 'writeBuffer')) echo $this->Js->writeBuffer();
	// Writes cached scripts
	?>
</body>
</html>

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 http://www.aptana.com/products/studio3/download 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]
Encoding=UTF-8
Version=1.0
Name=Aptana Studio 3
Comment=The professional, open source development tool for the open web
Icon=/usr/local/aptana-studio-3/icon.xpm
GenericName=Aptana Studio
Type=Application
Exec=/usr/local/aptana-studio-3/AptanaStudio3
MimeType=text/plain;
Categories=Development;IDE;

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.