Mostrando las entradas con la etiqueta perl. Mostrar todas las entradas
Mostrando las entradas con la etiqueta perl. Mostrar todas las entradas

20100302

ruby on rails and reorder the columns order in the view

This year was quite difficult to me, as I don't have a job since the 4th of January until now (2nd of March). And I think that is going to be like that for a some more time (as the interesting projects that I was offered to work in, the money is not enough, but that projects are really cool).

Well, this weekend I tried to keep going into my cook book, now in ruby, as the previous version in Perl was quite nice, but nobody would take that serious, as I did everything by myself and with my own XML definitions. The model that now I'm working is quite easy, a simple database:



ActiveRecord::Schema.define(:version => 20100302024114) do

create_table "categories", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "ingredients", :force => true do |t|
t.string "name"
t.integer "recipe_id"
t.integer "quantity"
t.string "measure"
t.string "part"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "notes", :force => true do |t|
t.integer "recipe_id"
t.string "keyword"
t.text "text"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "recipes", :force => true do |t|
t.string "name"
t.integer "yield"
t.integer "category_id"
t.text "preparation"
t.datetime "created_at"
t.datetime "updated_at"
end

end



This is quite simple, but yet powerful enough to what I need. For example, if i ever need something like the origin of the recipe, I just could add a note titled "origin" and the region in the text field. The only problem and that I should reconsider in some time, is that some preparations have parts, for example the base, the filling and the cover (for example a lemon pie). I manage to put that in the ingredients, as some parts uses the same ingredients, but in different measures, and perhaps somebody just want to make only the filling or the cover, but not the whole meal. But having another table for the preparation, just I don't like for now (as the preparations could vary from 1 to 5 or more, that should be in a separated table).

The main problem that I had was that the documentation was quite nasty about the reorder of the columns. Every web that I found was telling how to reorder the rows (the information in the columns) by an specified column. But I want to reorder the column, and the formal documentation just don't say anything useful to me.

So, after digging a lot of time in Google, I found http://api.rubyonrails.org/ and inside that http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002294 That was the beginning of the solution.

I printed that method, the code was:

class RecipesController < ApplicationController

active_scaffold :recipe do |config|
p config.columns()
end

end


That was quite useful, the very first line of the output was:


Completed in 301ms (View: 26, DB: 0) | 200 OK [http://10.0.0.52/recipes/new?_method=get&adapter=_list_inline_adapter]
#<ActiveScaffold::DataStructures::Columns:0x7fa930f14100 @_inheritable=[:name, :yield, :category, :ingredients, :preparation, :notes],
[...]


For the first time I had the proper names to call the others tables and my recipe table without the default order.


config.columns = [:name, :yield, :category, :ingredients, :preparation, :notes]


I know that this post was quite long and in this nasty language, but most of the people (well, programmers) just search the things in English.

20080309

programista renkontiĝo

Pasinta Vendredo mi renkontis kun Viktoro (bit-man) kaj N3krodamus, en la uzada renkontiĝo de la CaFePM grupo. Tiam mi komentis ili la ideon de la Ruby Programistgrupo (RubyAr). Ilin volas fari renkontiĝo kun la grupo CaFePM (nia grupo) kaj PyAr (la grupo de Python Argentina Grupo).

La ideo estas tro interesa, tiom interesa ke hieraŭ kaj hodiaŭ ni interŝanĝis ret-poŝton per organizi renkontiĝo inter reprezentulo de la diversaj grupoj.

Ni pensas ke la kongreso povus esti en Junio aŭ Julio. Sed ni havas serĉi lokon per fari la kongreso.

Kiam mi havas pli informo, mi skribu ĉi tie la novaĵojn.

20080111

cafePM meeting

ES:
Hola:

Este viernes (2008 01 11) nos reunimos en The Oldest (Elcano, Av.
3410 - Ciudad de Buenos Aires, Colegiales) a las 19:08.

La idea de las meetings del grupo de CaFe PM es hablar de programación
(basandonos en Perl) y de otras cosas (novedades del Software Libre,
Linux, FreeBSD y otras yerbas). El idioma en que se habla es
castellano.

EO:
Saluton:

Venonta Vendredo (2008 01 11) ni renkontigxis en The Oldest
(Elcano, AV. 3410 - Ciudad de Buenos Aires, Colegiales) al la horo
19:08

La ideo de la renkontigxo de la grupo CaFePM estas paroli pri
programado (precipe en Perl) kaj aliaj ajxoj (libera programaro
novajxoj, Linukso, LiberaBSD, k.p.t.). La principa lingvo estas
hispania.

20070924

Programming Sockets with Perl

[...]What is a socket? Just another bit of computer jargon? Devling a little into networking history, it is a Berkeley UNIX mechanism of creating a virtual duplex connection between processes. This was later ported on to every known OS enabling communication between systems across geographical location running on different OS software. If not for the socket, most of the network communication between systems would never ever have happened.

Taking a closer look; a typical computer system on a network receives and sends information as desired by the various applications running on it. This information is routed to the system, since a unique IP address is designated to it. On the system, this information is given to the relevant applications which listen on different ports. For example a net browser listens on port 80 for information. Also we can write applications which listen and send information on a specific port number.
[...]

Mor info at http://www.devshed.com/c/a/Perl/Programming-Sockets-with-PERL/

20070915

propuesta de esquema de base de datos

Para el PMLibrary suguiero:

--
-- Table structure for table `editoriales`
--

DROP TABLE IF EXISTS `editorial`;
CREATE TABLE `editorial` (
`id` int(7) NOT NULL auto_increment,
`name` varchar(100) default NULL,
`contact` varchar(200) default NULL,
`email` varchar(200) default NULL,
PRIMARY KEY (`id`),
KEY `name` (`name`,`contact`)
);

--
-- Reviews
--

DROP TABLE IF EXISTS `reviews`;
CREATE TABLE `reviews` (
`id` int(7) NOT NULL auto_increment,
`object_id` int(7) NOT NULL default '0',
`review_title` varchar(100) NOT NULL default 'review title',
`review_text` text NOT NULL,
PRIMARY KEY (`id`),
KEY `review_title` (`review_title`),
FULLTEXT (`review_title`,`review_text`)
);

--
-- Table structure for table `media`
--

DROP TABLE IF EXISTS `objects`;
CREATE TABLE `objects` (
`id` int(7) NOT NULL auto_increment,
`title` varchar(100) default NULL,
`review` enum('s','n') default NULL,
`editorial_id` int(7) NOT NULL default '0',
`other_notes` TINYTEXT NULL,
PRIMARY KEY (`id`),
KEY `title` (`title`),
FULLTEXT (`title`,`other_notes`)
);


--
-- Table structure for table `withdraw`
--

DROP TABLE IF EXISTS `withdraw`;
CREATE TABLE `withdraw` (
`id` int(7) NOT NULL auto_increment,
`object_id` int(7) default NULL,
`user_id` int(7) default NULL,
`date_withdraw` date default NULL,
PRIMARY KEY (`id`)
);

--
-- Table structure for table `prestamos_historico`
--

DROP TABLE IF EXISTS `historical_rent`;
CREATE TABLE `historical_rent` (
`id` int(7) NOT NULL auto_increment,
`object_id` int(7) default NULL,
`user_id` int(7) default NULL,
`date_withdraw` date default NULL,
`date_deposit` date default NULL,
PRIMARY KEY (`id`)
);

--
-- Table structure for table `users`
--

DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` int(7) NOT NULL auto_increment,
`name` varchar(100) default NULL,
`surname` varchar(100) default NULL,
`nick` varchar(100) default NULL,
`email` varchar(200) default NULL,
PRIMARY KEY (`id`),
KEY `Nombre` (`name`,`nick`)
);

20070813

usando referencias en Perl

Hoy en el trabajo tuve que hacer un código simple para mostrar el uso de referencias en Perl, en vez de pasar parámetros y recibirlos luego de llamar a la función.

El código es:


#!/usr/bin/perl -w

use strict;

sub myfun {
my $k = \shift;
${$k} = "Chau Mundo";
print "k es '" . ${ $k } . "'\n";
print "k es '" . $$k . "'\n";
return $$k ;
}

my $p = "Hola Mundo";
print myfun($p) . "\n";;
print "p es $p\n";


La salida de este programa es:

matias@t0001850023:/tmp$ perl -w k.pl
k es 'Chau Mundo'
k es 'Chau Mundo'
Chau Mundo
p es Chau Mundo


Una de las razones para necesitar usar referencias en vez de variables, es que el paso de variables simples copia la variable de un lado a otro, pero si uno tiene problemas de memoria, o tiene algunas variables muy pesadas (megas), puede ser necesario usar referencias para economizar recursos.

La explicación es bastante simple, al usar la "\" delante del shift (el shift regresa el primer valor del array -en este caso @_- y lo borra del array), en realidad no se hace la asignación del valor, sino de la dirección (puntero). Luego, para usar el valor del scalar, hay que llamarlo con un "$" extra. Al hacer una asignación, se hace la asignación a donde apunta el puntero, y no al puntero en sí (si se pierde todo si se hace un "$k = 0;", abortaría por intentar modificar un valor de solo lectura).

Esta es una referencia con ruby, dado que todo es una referencia, y hacer una asignación de valores es lo que es "no convencional".

20070413

cafe-meeting

Hoy a las 19:08 nos reunimos en Down Town Matias (San Martin 979) los
miembros/colaboradores del grupo Perl Mongers de Capital Federal.

Se habla de programación en general (y de Perl en particular),
GNU/Linux, *BSD y de cualquier cosa.

20070308

Nueva meeting de Perl

Como es usual, cada viernes que caiga en el [3,9], se realiza la juntada de Perl Monkers de Buenos Aires.

La reunión se hace en Down Town Matias, San Martin 939 (o al menos en la cuadra del 900), a las 19:08.

Aunque yo seguramente voy a estar desde antes (a eso de las 17:30).

En dichas reuniones se habla de Perl, Programación en general, GNU/Linux, Software Libre en general y de cualquier otra cosa que surja en el momento.

20050630

otro blog

Desde que no tengo internet que dejé de tener internet dejé de darle atención al blog, y ahora vuelvo a la marcha.

Esta vez para decir solamente:


#!/usr/bin/perl -w

my $flag=0;
my $tty=`/usr/bin/tty`;
my $dig="/usr/bin/dig";
my $domain="telecom.com.ar";
$tty=~s/(\n\r\r\n)$//;
$tty=~s/dev/;
my $ip = "";
chop($tty);
my $tflag = 1;
open("TMP","last") die "No pude ejecutar last: $!";

while (($tflag) && ($line = )){
if (($line =~ m/$ENV{'LOGNAME'}/) && ($line =~ m/$tty/)
&& ($line =~ m/still/i)){
my @li = split(" ",$line);
$ip = $li[2];
close(TMP);
$tflag = 0;
}
}
if(($ip=~ m/(\d{1,3})?\.(\d{1,3})?\.(\d{1,3})?\.(\d{1,3})?/)
&&($1<255)&&($2<255)&&($3< 255)&&($4<255)){
$ip="$1.$2.$3.$4";
$flag=1;
}else{
@b=split(" ",$ip);
$b[2]=~ s/([a-b]*)\..*/$1/;
$b[2]=`$dig $b[2].$domaingrep $b[2]grep -v "^;"awk '{print \$5}'`;
$ip=$b[2]; $ip=~s/(\n\r\rn)$//;
$flag=1;
}
print"export DISPLAY=$ip:0\n" if($flag);
__END__


Es un script en Perl (apto para cualquier Unix libre con dig instalado), que da la línea exacta para poner en cualquier host remoto (unix) y así levantar aplicaciones graficas de forma remota.

Se requiere que la máquina en la cual estamos permita las conexiones remotas (que escuche en el puerto 6000).

Devuelve algo como
---8<---8<---8<---8<---8<---8<---8<---8<---
$ myipx
export DISPLAY=10.33.37.12:0
$
--->8--->8--->8--->8--->8--->8--->8--->8---

Por cierto, AMMA (A Mi Me Andaaaaaaaaaaaa) ;-)

gxis revidas