jueves, 18 de febrero de 2010

Disable USB devices on GRUB in Ubuntu 9.10 Karmic Koala

For security it's important to disable all usb devices for not get out information, then I write a small bash script that do it. I hope that work succesfully.



#!/bin/bash
cp /etc/default/grub /tmp && cd /tmp
sed 's/splash/splash nousb/g' grub > grub.2 && sudo mv grub.2 /etc/default/grub
echo "Disable USB on GRUB..."

jueves, 3 de diciembre de 2009

Generate new certificate for jabber server on OpenBSD

Modify the configuration file

sudo vi /etc/ejabberd/ejabberd.cfg

Modify the line for set certificate value before load the configuration file


[{5222, ejabberd_c2s, [{access, c2s},
{max_stanza_size, 65536},
starttls_required, {certfile, "/etc/ejabberd/server.pem"},
{shaper, c2s_shaper}]},


In the command line generate the key

openssl req -new -x509 -newkey rsa:1024 -days 3650 \
-keyout privkey.pem -out server.pem


openssl rsa -in privkey.pem -out privkey.pem

cat privkey.pem >> server.pem

rm privkey.pem


Finally restart the service


sudo ejabberctl restart

lunes, 23 de noviembre de 2009

Active Record Without Rails and PostgreSQL

a script for connect a database and copy a single table in two tables, copy and save with the .rb extension for execute with Ruby, for example "inicio2tablas.rb" and run in a command line

 cmonterrosa@dibd02:~$ ./inicio2tablas.rb mydatabase myhost  




#!/usr/bin/ruby -w

require 'rubygems'
require 'active_record'

#--------- Carlos Augusto Monterrosa Lopez / cmonterrosa@gmail.com

def usage
STDERR.puts "Uso:
#{File.basename $0} dbname host
"
exit 1
end

usage if ARGV.size != 2
dbname = ARGV[0]
host = ARGV[1]

ActiveRecord::Base.establish_connection(
:adapter => 'postgresql',
:database => dbname,
:username => 'your-user',
:password => 'your-password',
:encoding => 'utf8',
:host => host )


#------ Declaramos las clases para mapear las tablas --------
class Inicio < ActiveRecord::Base
set_table_name :inicio
end

class Palabra < ActiveRecord::Base
set_table_name :palabras
has_many :significados
end

class Significado < ActiveRecord::Base
set_table_name :significados
belongs_to :palabra
end


puts "Cargando palabras..."
@contador=0
@inicio= Inicio.find(:all)
@inicio.each do |inicio|
@palabra = Palabra.create(:palabra => inicio.palabra,
:abreviatura => inicio.abreviatura)
@contador+=1

#------------ Vinculamos los significados -------------
(1..12).each do |num|
next if inicio["significado#{num}"].nil? || inicio["significado#{num}"].empty?
@palabra.significados.create(:significado => inicio["significado#{num}"])
end
end
puts "Finalizo la carga de palabras.."
puts "Total: #{@contador}"

viernes, 16 de octubre de 2009

How to migrate MySQL backup to PostgreSQL

Hi, the first step is generate a dump with all data from your mysql database. for example. I am working in Ubuntu 8.04 Hardy Heron


cmonterrosa@dibd02:~$ mysqldump dbname > file.sql -u root -p


enter your password and mysqldump generate a file with the BD backup. then you have tu run the script to format this file.sql into postgresql valid format.

This script is available in:

http://pgfoundry.org/frs/download.php/1535/mysql2pgsql.perl


cmonterrosa@dibd02:~$ perl mysql2pgsql.perl file.sql file-pgsql.sql



where file-pgsql.sql is the file valid for introduce the schema and data into postgresql.Now we are going to restore the schema and the rows.


cmonterrosa@dibd02:~$ psql -h localhost -d diccionarios -U cmonterrosa -W


where -h option is host, in this case is the localhost, -d is the database and -U is the owner of the database.

Comments with

Carlos Augusto Monterrosa Lopez
cmonterrosa@gmail.com / cmonterrosa@sef-chiapas.gob.mx

martes, 29 de septiembre de 2009

GLOBAL AND LOCAL SELECTION IN DIFFERENTIAL EVOLUTION FOR CONTRAINED NUMERICAL OPTIMIZATION

Global and Local Selection in Differential Evolution for Constrained Numerical Optimization
Efrén Mezura-Montes and Carlos A. Monterrosa López


emezura@lania.mx
cmonterrosa@gmail.com

Laboratorio Nacional de Informática Avanzada (LANIA A.C.) Rébsamen 80, Centro, Xalapa, Veracruz, 91000

Instituto Tecnológico de Tuxtla Gutiérrez
Depto. de Ingeniería en Sistemas Computacionales
Carretera Panamericana Km. 1080, Tuxtla Gutiérrez, Chiapas



ABSTRACT

The performance of two selection mechanisms used in the most popular variant of differential evolution, known as DE/rand/1/bin, are com- pared in the solution of constrained numerical op- timization problems. Four performance measures proposed in the specialized literature are used to analyze the capabilities of each selection mech- anism to reach the feasible region of the search space, to find the vicinity of the feasible global op- timum and the computational cost (measured by the number of evaluations) required. Two para- meters of the differential evolution algorithm are varied to determine the most convenient values. A set of problems with different features is cho- sen to test both selection mechanisms and some findings are extracted from the results obtained.

Keywords: Constrained Numerical Optimiza- tion, Differential Evolution, Selection Mecha- nisms.


THE PAPER WAS PUBLISHED AT "Journal of Computer Science & Technology", in October 2009
AND YOU CAN DOWNLOAD HERE

jueves, 10 de septiembre de 2009

How to convert iso-8859-1 into utf-8-charset files

the solution:


iconv --from-code=ISO-8859-1 --to-code=UTF-8 ./oldfile.htm > ./newfile.html


using bash shell and using Linux - of course !

jueves, 13 de agosto de 2009

ActiveRecord::StatementInvalid customize messages

I tried to customize the active record error messages on Rails project, and I was boring to find the answer, the simple way of have my personal messages is use a begin rescue block, an example is above, I am working with RoR 1.26 and PostgreSQL.

The function is delete_row and is in application.rb (Global controller)


#---- written by Carlos Augusto Monterrosa Lopez
def delete_row(row)
  begin
    row.destroy
    flash[:notice]="Row deleted"
    redirect_to :action => 'list', :controller => "#{params[:controller]}"
  rescue
    flash[:notice]="Here you personal error message"
    redirect_to :action => 'list', :controller => "#{params[:controller]}"
  end
end