How to retrieve numeric indexes from enum type values in MySQL

Example usage is like the following:

CREATE TABLE persons(
	id INT NOT NULL AUTO_INCREMENT,
	name CHAR(30) NOT NULL,
	surname CHAR(30) NOT NULL,
	gender ENUM('male','female','unisex') NOT NULL,
	PRIMARY KEY (id,gender)
);

INSERT INTO persons(name,surname,gender) VALUES('erman','gülhan','male'),('ayşe','dolu','female'),('ali','veli','male');

# this returns gender as string
SELECT name,gender FROM persons;

# this returns gender as numeric index
SELECT name,gender+0 FROM persons;

Form validation example using CodeIgniter

Example is about simply user creation.

Controller file(user.php)

<?php

/**
 * User controller class
 */
class User extends CI_Controller
{

	public function create()
	{
		$data=['title'=>'Create New User'];
		$this->load->library('form_validation');

		// validation rules
		$rules=array(
			array(
				'field'=>'username',
				'label'=>'Username',
				'rules'=>'required|min_length[6]',
			),
			array(
				'field'=>'password',
				'label'=>'Password',
				// user-defined validation rule via method
				'rules'=>'required|callback_checkPasswordStrength',
			),
			array(
				'field'=>'passwordConfirm',
				'label'=>'Password Confirm',
				'rules'=>'required|matches[password]',
			),
		);
		$this->form_validation->set_rules($rules);

		// failed
		if ($this->form_validation->run() === FALSE)
		{
			$this->load->view('user/create',$data);
		}
		// successfull
		else
		{
			$attrs=$this->input->post(null,true);
			$this->load->view('user/success');
		}
	}

	// user-defined validation rule via method
	public function checkPasswordStrength($password)
	{
		if (strlen($password)<5) {
			$this->form_validation->set_message('checkPasswordStrength','Password length cant be less than 5 characters');
			return false;
		}
		else if (!preg_match('/[[:punct:]]/',$password)) {
			$this->form_validation->set_message('checkPasswordStrength','Password must contain at least 1 special character');
			return false;
		}
		return true;
	}
}

View file(create.php)

<ul>
	<?php echo validation_errors('<li class="error">','</li>'); ?>
</ul>

<form action="/index.php/user/create" method="post">
	<label>Username:</label>
	<input type="text" name="username" value="<?php echo set_value('username'); ?>" />
	<?php echo form_error('username','<div class="error">','</div>'); ?>
	<br />

	<label for="">Password:</label>
	<input type="password" name="password" value="<?php echo set_value('password'); ?>" />
	<?php echo form_error('password','<div class="error">','</div>'); ?>
	<br />

	<label for="">Password Confirm:</label>
	<input type="password" name="passwordConfirm" value="<?php echo set_value('passwordConfirm'); ?>" />
	<?php echo form_error('passwordConfirm','<div class="error">','</div>'); ?>
	<br />

	<input type="submit" name="submit" value="Create" />
</form>

Elasticsearch error dynamic scripting for [mvel] disabled

Dynamic scripting 1.2.0 sürümünden beri varsayılan olarak kapalı gelmektedir. Bu dynamic scripting ne anlama gelmektedir peki? Örneğin aşağıdaki gibi index’lenmiş bir doc’un bir alanını güncellemek istediğinizde bu hata ile karşılaşabilirsiniz:

curl -XPOST 'localhost:9200/esindex/estype/7/_update' -d '{
        "script":"ctx._source.counter=newval",
        "params":{
                newval:4
        }
}'

Bu hatayı almamak için config dosyasına (/etc/elasticsearch/elasticsearch.yml) aşağıdaki satır eklenmeli:

script.disable_dynamic: false

 

Kaynaklar:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-scripting.html

Bash prompt’da tam path yerine mevcut dizini gösterme (show only current path on bash prompt)

.bashrc dosyasında aşağıdaki değişiklik yapılmalı:

// PS1 geçen satırlardaki \w ler \W lere çevrilmeli
...
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '
...
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\W\$ '
...
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \W\a\]$PS1"
...