sudo apt-get install libmagickwand-dev imagemagick
sudo gem install rmagick
Site mainly dedicated to diffusion of Ruby/RoR, Security, Evolutionary Algorithms and BSD/GNU Linux Operating Systems.
lunes, 14 de marzo de 2011
Installing RMagick on Ubuntu 9.04 (Jaunty)
Ruby :: The bundled mysql.rb driver has been removed from Rails 2.2
sudo apt-get install libmysqlclient-dev
sudo gem install mysql
sábado, 20 de febrero de 2010
Easy Groups Authentication in Ruby on Rails using before_filter
first It's necessary to create two new tables: a table called groups with the fields (id, groupname, description) and other table called systables, with the fields (id, group_id, controller). Then create a file login_system.rb in the Lib folder under the main project. This file it's the library for send a filter to "before_filter" method in a rails controller. the modified code it's above:
finally, in a controller write a line like this:
require_dependency "user"
module LoginSystem
protected
def autorizado?(user, controller)
@usuario= User.find(user)
@grupo = @usuario.grupo.id.to_i
@systable = Systable.find(:all, :conditions => ["grupo_id = ? and controller = ?", @grupo, controller])
if @systable.empty?
return false
else
return true
end
end
#------ Group permissions ------------
def check_permissions
if not protect?(action_name)
return true
end
if @session['user'] and autorizado?(@session['user'], controller_name)
return true
end
store_location
access_denied
return false
end
# overwrite if you want to have special behavior in case the user is not authorized
# to access the current operation.
# the default action is to redirect to the login screen
# example use :
# a popup window might just close itself for instance
def access_denied
redirect_to :controller=>"/account", :action =>"login"
end
# store current uri in the session.
# we can return to this location by calling return_location
def store_location
@session['return-to'] = @request.request_uri
end
# move to the last store_location call or to the passed default one
def redirect_back_or_default(default)
if @session['return-to'].nil?
redirect_to default
else
redirect_to_url @session['return-to']
@session['return-to'] = nil
end
end
finally, in a controller write a line like this:
class CatalogosController < ApplicationController
before_filter :check_permissions
end
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
Modify the line for set certificate value before load the configuration file
In the command line generate the key
Finally restart the service
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}"
Etiquetas:
active record,
Carlos Augusto Monterrosa Lopez,
postgresql,
ruby on rails
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
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
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.
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
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
Etiquetas:
Carlos Augusto Monterrosa,
MySQL,
Mysqldump,
postgresql,
sef-chiapas.gob.mx
Suscribirse a:
Entradas (Atom)