Nov
29
2009
blaxter
A veces es útil mostrar algún tipo de notificación gráfica para informarte, por ejemplo, de cuándo se ha terminado una tarea. Las notificaciones emergentes de Ubuntu, añadidas hace un par de versiones, son una muy buena opción.
Dos opciones, (1) instalarnos esta librería de perl libnet-dbus-perl, y nos ponemos esta función en nuestro ~/.bashrc
function notify()
{
perl -e "use Net::DBus; my \$sessionBus = Net::DBus->session; my \$notificat
ionsService = \$sessionBus->get_service('org.freedesktop.Notifications'); my \$n
otificationsObject = \$notificationsService->get_object('/org/freedesktop/Notifi
cations', 'org.freedesktop.Notifications'); my \$notificationId; \$notificationI
d = \$notificationsObject->Notify(shift, 0, '', '$1', '$2', [], {}, -1);"
}
$ notify foooooooo baaarrr

El primer parámetro es el título y el segundo el contenido.
Otra forma (2) todavía más fácil es instalarnos el paquete libnotify-bin, el cual contiene el binario notify-send que hace justamente esto. Probablemente la primera solución nos servirá para cualquier distro, mientras que la segunda solo en debian, ubuntu y derivados. Ambas funcionan exactamente igual y sin problemas.
3 comments | tags: bashrc, d-bus, notificaciones, notify, tips, ubutu | posted in Ubuntu
Nov
23
2009
blaxter
If you are not very careful, monkeypatching could be very harmful. One thing to remember is that you should never override a method to add funcionality, for those kind of thinks you must use alias chain method pattern, a safer way of doing that.
For the rest of the monkeypatching, i.e. add new methods, you could debug them really easy with something like this:
class Class
def method_added(method_name)
puts "#{method_name} added to #{self}, callstack:"
puts caller.map{|line| "\t#{line}" }.join("\n")
end
end
You can always add more code to filter by class or by method's name. Let's see an example:
$ more example.rb
require 'date'
require 'time'
class Class
def method_added(method_name)
return if %w(method_added).include? method_name.to_s
puts "#{method_name} added to #{self}, callstack:"
puts caller.map{|line| "\t#{line}" }.join("\n")
end
end
class Time
def to_date
Date.ordinal self.year, self.yday
end
end
class Date
def to_time
Time.parse self.to_s
end
end
raise "to_date not working" unless
Time.now.to_date == Date.today
raise "to time not working" unless
Time.now.to_date.to_time == Date.today.to_time
The output will be:
$ ruby example.rb
to_date added to Time, callstack:
example.rb:13
to_time added to Date, callstack:
example.rb:19
Nice, isn't it?. Remember to be carefull with your monkeypatching, with great power comes great responsibility, it's just a tool, neither magic nor the panacea.
no comments | tags: debug, english, method_added, monkeypatching, Ruby | posted in Ruby
Nov
21
2009
blaxter
Si por cuestiones del destino tienes la mala suerte de tener que lidiar con este sistema operativo, he aquí unas pequeñas ayudas para típicas tareas a realizar, traduciendo desde comandos *nix.
- Matar un proceso
- Linux: kill -9 PID
- Windows: taskkill /f /pid PID
- Mirar procesos y filtrarlos
- Linux: ps aux | grep PID
- Windows: tasklist /fi "PID eq $PID" | filter $PID
- Establecer la ruta por defecto
- Linux: route add default gw IP
- Windows: route change 0.0.0.0 mask 0.0.0.0 IP
- Iniciar/parar servicios
- Linux: /etc/init.d/foobar start|stop
- Windows: net start|stop foobar
Espero que nunca tengas que usarlos, por el bien de tu salud mental. Si llega a ser el caso, y no hay forma de salir del atolladero sin matar gente, te recomiendo usar alguna que otra ayuda en este hostil, adverso y aciago entorno.
1 comment | posted in Linux, Windows
Nov
21
2009
blaxter
Cuando no apetece escribir, simplemente no apetece escribir, qué le vamos a hacer. Después de mucho tiempo creo que toca ya volver a dar mal por estos lares. Van ya cerca de 5 años con el blog, y aunque últimamente las redes sociales y el microblogging han quitado muchos usuarios a los blogs (posiblemente todos aquellos que creaban un blog y a los cuatro post lo dejaban abandonado), a la blogosfera la veo mejor que nunca.
De nuevo, como otras muchas veces, tengo el dilema sobre qué idioma elegir, español o inglés. Mientras que con el primero puedo conseguir, a veces, no cometer faltas ortográficas y crear frases coherentes y comprensibles por otros seres humanos, el segundo, por suerte o desgracia, es el idioma neutral y empleado principalmente en esto del interné, nuevas tecnologías y especialmente en el desarrollo de software. Posiblemente iré decidiéndolo post a post, intercalando, para dar emoción al asunto.
Y tú, ¿has dejado de escribir en tu blog? Él no lo haría.
3 comments | posted in Blog
Top Commenters