Ruby on Rails: Simple Form, remover opción nula

Explicando un poco lo que sucede, si bien se tiene una colección de registro en un arreglo por ejemplo:

options = ["option1", "option2", "option3"].

Luego se genera el elemento en la vista:

= f.input :options_selected, as: :select, include_blank: false, collection: options, input_html: {multiple: true}

Si los elementos seleccionados son option1 y option3, la manera en que se almacena es:

["", "option1", "option3"]

Aun cuando se incluyo la opción include_blank se tiene un elemento nulo. Para solucionar esto es necesario agregar una opción mas, include_hidden, y el elemento seria:

= f.input :options_selected, as: :select, include_blank: false, include_hidden: false, collection: options, input_html: {multiple: true}

Y cuando se guarden las mismas opciones se almacenara sin el elemento nulo:

["option1", "option3"]

Measurement Lab, tienes acceso libre a internet ?

Muchas veces estamos restringidos al contenido completo que brinda la red Internet (en mi caso por usar una conexión 3G tengo bloqueado los puertos para programas P2P y últimamente los servicios de megaupload, rapidshare, fileserve y similares… gracias Tigo), aquí es donde entra M-Lab, un servicio gratuito y respaldado por Google para poder hacer pruebas a nuestra conexión de Internet.

Entre las pruebas disponibles están las siguientes:

  • Network Diagnostic Tool. Prueba la velocidad de tu conexión y reciba diagnóstico sofisticado de los problemas que limitan la velocidad.
  • Glasnost. Pruebe si BitTorrent esta bloqueado u obstruido.
  • Network Path and Application Diagnosis. Diagnostica problemas comunes que impactan las redes de banda ancha.
  • ShaperProbe. Determina si un proveedor de servicio de Internet está dando algún tráfico de menor prioridad que el resto del tráfico.
  • NANO (próximamente – hoy, se puede utilizar la versión alfa no relacionado con M-Lab.). Determinar si un proveedor de acceso a Internet está reduciendo el desempeño de un determinado subgrupo de usuarios, aplicaciones o destinos.
En el caso de Glasnost sirve para probar otros programas P2P por ejemplo Ares.

Consola: arreglar comando ls

Instale crunch (con make), que es un generador de textos, luego de probarlo y desintalarlo, vaya sorpresa!

Al ejecutar la orden (comando) ls (que sirve para listar los archivos y directorios) en consola tenía el siguiente texto:

crunch version 2.4
usage: crunch <min-len> <max-len> [charset] [-o wordlist.txt] [-t [FIXED]@@@@] [-s startblock] [-c number]orusage: crunch <min-len> <max-len> [-f <path to charset.lst> charset-name] [-o wordlist.txt] [-t [FIXED]@@@@] [-s startblock] [-c number]
min-len is the minimum length string you want crunch to start atmax-len is the maximum length string you want crunch to end at
[charset] is optional.  You may specify a character set for crunch to use on the command line or if you leave it blank crunch will use abcdefghijklmnopqrstuvwxyz as the character set.  NOTE: If you want to include the space character in your character set you use enclose your character set in quotes i.e. "abc "
[-f <path to charset.lst> <charset-name>] is the alternative to setting the character set on command line.  This parameter allows you to specify a character set from the charset.lst.NOTE: You may either not specify a charset, you may specify a character set on the command line, or you may specify -f <path to charset.lst> <charset-name>.  You can only do one.
[-t [FIXED]@%^] is optional and allows you to specify a pattern, eg: @@god@@@@ where the only the @'s will change.  You can specify @ or % or ^  which will allow to change letters numbers and symbols.  For example @@dog%^ abcd 1234 @#$% the @'s will chnage with the characters the % will change with the numbers and the ^ will change with the symbols you specifed.  If you use %dog^ + 1234 @#$% the plus sign is a placeholder.
[-s startblock] is optional and allows you to specify the starting string, eg: 03god22fs
[-i] is optional and will invert the output.  Instad of aaa, aab, aac you will get aaa, baa, caa, etc
[-o wordlist.txt] is optional allows you to specify the file to write the output to, eg: wordlist.txt
[-c number] is optional and specifies the number of lines to write to output file, only works if -o START is used, eg: 60  The ouput files will be in the format of starting letter-ending letter for example: ./crunch 1 1 -f /pentest/password/crunch/charset.lst mixalpha-numeric-all-space -o START -c 60 will result in 2 files: a-7.txt and 8-\ .txt  The reason for the slash in  the second filename is the ending character is space and ls has to escape it to print it.  Yes you will need to put in the \ when specifing the filename.
[-b size] is optional and will break apart the output file based on the size you specify.  you must specify the size as a number followed by kb, mb, gb, kib, mib, or gib.  kb, mb, and gb are based on the power of 10 (i.e. 1 kb = 1000 bytes).  kib, mib, and gib are based on the power of two (i.e. 1 kb = 1024 bytes).  To use this option you must specify -o START.  NOTE There is no space between the number and the type.  For example 500mb is correct, 500 mb is NOT correct.
[-z option] is optional and will compress the outfile using bzip, gzip, or lzma
[-p string-of-letters] is optional crunch will now generate permutations instead of combinations.  The string of letters is the string of letters you use to permute.  This parameter ignores min and max
[-m string1 string2 string3 ...] is optional crunch will now generate permututions of the strings you specify.  This parameter ignores min and max
[-r] is optional and resume a previous crunch session.  You must use the same syntax as the original command.  This option will not work with the -p or -m options.
examples:./crunch 1 8crunch will display a wordlist that starts at a and ends at zzzzzzzz
./crunch 1 6 abcdefgcrunch will display a wordlist using the charcterset abcdefg that starts at a and ends at gggggg
./crunch 1 8 -f charset.lst mixalpha-numeric-all-space -o wordlist.txtcrunch will use the mixalpha-numberic-all-space character set from charset.lst and will write the wordlist to a file named wordlist.txt.  The file will start with a and end with "        "
./crunch 8 8 -f charset.lst mixalpha-numeric-all-space -o wordlist.txt -t @@dog@@@ -s cbdogaaa crunch will generate a 8 character wordlist using the mixalpha-number-all-space characterset from charset.lst and will write the wordlist to a file named wordlist.txt.  The file will start at cbdogaaa and end at "  dog   "

Que no es exactamente la lista de archivos y directorios, después de romperme la cabeza por un par de horas y leyendo algo por aquí y por allá y aplicando el principio KISS solucione este pequeño problema de la manera más fácil que pude.

Primero debemos probar que las rutas /usr/bin y /bin se encuentren el path, hay dos formas de hacer esto (en consola claro):

  • cat /etc/environment
  • echo $PATH

El resultado:

PATH=»/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games»

Por tanto todo esta bien aquí, continuamos.

Luego localizar (físicamente) el comando ls (para ver el archivo de error), para esto en consola:

which ls

Lo que devuelve:

/usr/sbin/ls

Ahora si escribimos la ruta completa del comando ls (la que se encuentra en /bin) para ver si este se encuentra en buen estado:

/bin/ls

Eureka! tenemos la lista de directorios y archivos, pero claro es mucho más sencillo usar ls que la ruta completa, lo que solamente quedaría crear un enlace a /bin/ls y copiarlo (reemplazarlo) a /usr/sbin/ls (que es el que tiene problemas).

Latex: alinear texto verticalmente

Esto que parece tan simple en realidad necesita un poco de ingenio, las características de este pequeño problema son las siguientes:

  • Se necesita alinear verticalmente una línea de texto.
  • En toda la página solo existe una única  línea de texto (también puede ser un párrafo).
  • No se puede usar varios saltos de línea, ya que Latex no lo permite.
  • Podría ser una alternativa modificar el margen superior aunque no muy estético ni funcional.
  • No se puede usar ningún tipo de salto de línea como \bigskip ya que este solo funciona para el salto de un párrafo a otro.
  • Tampoco funciona \vspace{alto}, ya que este también necesita de un párrafo anterior, pero en este caso solo tenemos una línea o un solo párrafo.

Y la solución sería… usar \vspace pero con \fill, para tener una línea de texto justo al centro se usa:

\vspace*{\fill}
	Al centro
\vspace*{\fill}

Para ponerlo un poco arriba:

\vspace*{1cm}
	Arriba
\vspace*{\fill}

Y abajo:

\vspace*{\fill}
	Abajo
\vspace*{1cm}

Con esto ya se puede ir jugando un poco con la posición en la que queramos que este el texto.

Latex: formas de escribir la letra ñ

Existen varias maneras de escribir esta letra (medio rara) en Latex, ahora la forma correcta es… pues la que funcione…

Vayamos por el inicio, definiendo el idioma, y la codificación:

\usepackage[spanish, activeacute]{babel} %Definir idioma español
\usepackage[utf8]{inputenc} %Codificacion utf-8

El termino activeacute sirve para poder utilizar el signo » » (ojo, no es un acento es la comilla simple). También se puede usar la codificación iso-8889-1, reemplazando a la utf-8:

%\usepackage[latin1]{inputenc} %Codificacion iso-8889-1

Ahora las maneras de escribir la ñ:

  1. ñ
  2. ‘n (ojo que es comilla simple)
  3. ~n
  4. \~n
  5. \~{n}

En últimas versiones ya no funciona la opción 3 (que era una de las que más se usaba) ahora fue reemplazada por la opción 2 (siempre y cuando activeacute este definido), si no se define activeacute se puede usar la forma 4 o la 5.