nexoBlogs network
Anonymous Anonymous

GMAIL: Bulk deleted emails based on date

Wednesday, 12 de October del 2011
filed under ,

When I created my gmail account, there was a counter giving you everyday more space. They "sold us" the product as if you never had to delete email again. By looking at that counter it seemed that by now I should have more than a Terabyte of data, truth is that after many years I have less than 8GB. Although it's a lot of space for the email, if you have automatic notifications, reports, and so on... it's easy to see how you are fastly approaching to the limit.

So, from time to time, it is needed to clean up a little bit your GMAIL account. At least for old reports and automatic emails which may not have sense anymore.

I usually delete some of this nonsense emails by typing in the search box:

label:Label_to_delete before:2011/1/31

Instead of "Label_to_delete" write a "secure" label you want to clean. I say secure because if you label your email with vague rules it is possible that you delete something you shouldn't.

When the search results appear, select the checkbox to check them all, and then click on the link that selects all the items matching that search. With this you will be able to delete thousands of undesired emails in a couple of clicks. 

The search box of Gmail is very powerful. If you are used to code, you'll find how easy is to add conditions. A very simple example of that would be:

label:CRONS after:2011/01/01 AND before:2011/02/01 AND from:root AND !has:attachment

Translation: Delete emails coming from CRONS in January coming from root user and without any attachment.

Give it a try!

Conectar por SSH sin password (autenticación de clave pública)

Monday, 29 de August del 2011
filed under , , , ,

 TAGS:

Esta es una de aquellas cosas que uno hace una y otra vez y al final pierde 10 minutos intentando recordar los comandos o buscando la información.

Para conectar a un servidor remoto por SSH sin usuario ni contraseña todo lo que hace falta es compartir una clave entre cliente y servidor. Los pasos son "mu" sencillos:

  1. Asegurarse que la carpeta .ssh existe en el servidor al que nos queremos conectar
  2. Crear una clave RSA pública en la máquina cliente (la que se conecta):
    ssh-keygen -t rsa
    Cuando se te pida por un password, dale al enter sin poner ninguno (este es el propósito del artículo, sin passwords)
  3. Copiar la clave pública en el servidor:
    scp ~/.ssh/id_rsa.pub usuario@servidor.com:.ssh/authorized_keys2

    Puedes omitir la parte usuario@ si te conectas con el mismo usuario.

Y esto es todo amigos. En la siguiente conexión por SSH ya no se pedirá de nuevo el password.

Importante:

A partir de este momento, si alguien robara la clave pública que has guardado en ~/.ssh/id_rsa tendría acceso completo a tu servidor. Más vale que la protejas bien :)

Si dejas un password en la autenticación RSA puede ser una buena idea desactivar en el servidor el acceso SSH vía login/password y dejar sólo autenticación por clave.

Comando `tree` para Mac

Saturday, 27 de August del 2011
filed under , , ,

Existe una utilidad llamada "tree" en Windows y Linux que sirve para ver un listado de directorio en un formato ASCII un poco más agradable a la vista. Si no quieres bajarte los MacPorts para esta pequeña utilidad lo más fácil es crear un script de una línea y enlazarlo en /bin para poder llamarlo directamente.

El comando en cuestión es este:

find . -print | sed -e 's;[^/]*/;|--;g;s;--|; |;g'

Ahora, para utilizarlo a troche y moche basta con pegar su contenido en un fichero en cualquier ubicación. Por ejemplo, en mi carpeta de usuario de scripts (/Users/alombarte/scripts/tree.sh):

#!/bin/bash
find . -print | sed -e 's;[^/]*/;|--;g;s;--|; |;g'

Y entonces, para poder escribir allí donde queramos el comando tree hacemos un enlace simbólico:

sudo ln -s /Users/alombarte/scripts/tree.sh /bin/tree

Un ejemplo de la salida es este:

 

|--a1
| |--a11
| | |--fichero_en_a11.txt
| |--fichero_en_a1.txt
|--a2
| |--a21

Así de simple :)

Delete keys by pattern using REDIS-cli

Thursday, 18 de August del 2011
filed under , , ,

I do store a lot of statistical data in Redis, storing information on what users do and behave every day, week, month and so on... But storing a huge amount of data in memory has a little drawback: memory is cheap and fast, but is finite.

From time to time (e.g: cron job) I need to clean up the house because there is too much memory filled that is no longer interesting to keep it. Maybe you are thinking now, why this guy is not setting an EXPIRATION date? Well, I do.

Problem is that with early versions of Redis after the expiration time a KEY won't be really deleted from memory until the next access to the key, which never might happen. There is also a random process that deletes keys and there was a change of behaviour regarding expiration in Redis 2.2,  read more on expiration here.

In my case, I do store keys using human-readable dates as part of the key name, which I need to delete by pattern. To make it more graphical with a similar example, imagine you are storing user behavior in keys named like:

ub:2011-08-18:id-tracked-page...

Decomposing the elements:

  • ub: user-behavior alias
  • 2011-08-18: Stores all the events for August 18th
  • id-tracked-page: Name or code of the page I want to track (e.g: home)
  • ... more constraints could be added

Then, I am not interested in last month's data (July) regarding user behaviour so I can trigger in the terminal the following command:

redis-cli -n 0 KEYS ub:2011-07-* | xargs redis-cli DEL

This deletes all the redis keys based on this pattern.

The output would produce something like:

$ redis-cli -n 0 KEYS ub:2011-07-* | xargs redis-cli DEL
(integer) 188
(integer) 175
(integer) 191
(integer) 186
(integer) 153

You should notice that there is a -n 0 in the command indicating to trigger the command in the DATABASE 0. Since I do have many databases in a single server (multiple database support will be removed soon) I do always specify it. If you use a single database, just drop the "-n 0".

Also, you might need to surround by quotes the pattern part if contains spaces or other unfriendly chars.

Hope this helps

How to backup your full Flickr account (script)

Sunday, 24 de July del 2011
filed under , , ,

Why you would like to copy all your images stored at Flickr to your computer? Well, maybe you want to browse them later offline, maybe you want to stop paying your PRO account, or to keep them just in case...

In any case, Flickrtouchr is a simple command-line script to backup Flickr. You don't need to know python or programming at all. A couple of lines in the Terminal and that's it.

After downloading and uncompressing the .py script all you need is to:

Create a directory, e.g: A folder called "Flickr" in your Home dir:

mkdir ~/Flickr

And then call the script:

python flickrtouchr.py ~/Flickr

After this a browser will be opened and Flickr will ask you to authorize Flickrtouchr, and that's it!

Now maybe you want to add this line to your crontab so you can run it periodically. The script will check if the files exists to prevent continuous download.

Cómo cambiar la extensión a múltiples ficheros desde terminal (unix shell)

Friday, 17 de June del 2011
filed under , ,

Para renombrar la extensión de muchos ficheros a la vez en la terminal, se puede hacer con la siguiente línea:

for file in *.phtml ; do mv $file `echo $file | sed 's/\(.*\.\)phtml/\1tpl/'` ; done

Esto cambiaría todas las extensiones phtml por tpl del directorio en que lo lanzéis. Cambiando la parte en negrita por vuestra extensión favorita ya funcionaría.

Lo que hace la línea es buscar todos los archivos que cumplen la condición *.phtml e iterarlos en un bucle. Para cada uno de ellos hace un mv del orígen al destino. El destino es una expresión regular que substitye el patrón .phtml por el .tpl (gracias al comando sed)

Writing complex regular expressions

Friday, 15 de April del 2011

Regular expressions are usually hard to read and understand. Even if you have a lot of experience on the subject, when you retakeone that you wrote some time ago, it is difficult to catch up.

Some days ago, a very smart guy at work named Zoltán recommended us to write complex regular expressions sepparating each logical part in a different line and also comment every one.

I did not know that this was possible at all, but he shown us how the modifier "x" (see it at the end of the following example) makes the compiler to ignore any whitespaces (spaces, tabs, line breaks) and even comments!!

So, with this, you can write crazy regular expressions easy to parse and understand. Here there is a silly example, imagine it in a single line!:

if ( preg_match('/
    ^                       # We match the beginning because we match full string.
    (Can|May)\x20           # May is more formal, can Can is also OK.
    [yY]ou\s                # You can match space with backslash and space or any whitespace with \s
    (please)?\x20           # "Please" is optional ;)
    (comment|document)\x20  # Commenting = documenting
    this\ regexp\x20        # If UNICODE mode is on (modifier "u"), you can also match space with \x20
    to\s(know|see)\x20
    (what|WTF)\x20          # WTF = World Taekwondo Federation
    it\ does\?              # Note the "x" modificator int he next line. If makes regexp ignore whitespaces.
    $                       # We match the end because we match full string.
    /x',
    "Can you please comment this regexp to know what it does?" ) )
{
    echo "Thank you!";
}
 

Thank you Zoly!

No funciona el pulsómetro o GPS del Garmin Forerunner?

Tuesday, 12 de April del 2011
filed under ,

Garmin Forerunner 305Tengo un Garmin Forerunner 305 GPS que utilizo para salir a correr. Un día el pulsómetro dejó de funcionar correctamente, primero empezó a espaciarse el ritmo de los latidos hasta que finalmente (en un par de días) el reloj no llegaba ni a sincronizarse, problema: no detecta los latidos del corazón. Si que detectaba sin embargo los pulsómetros de mis amigos. para añadir más elementos a esta fiesta, uno de estos mismo amigos, tenía un problema con el GPS:  El dispositivo Garmin GPS no detecta los satélites. Ambos problemas fueron solucionados:

El Garmin no detecta el pulsómetro

El pensamiento primero fué que cambiando la pila se solucionaría todo, pero no fué así. Empezé a buscar en internet que podía hacer y encontré varias cosas que se podían hacer, y fué la última la que solucionó mi problema.

  1. Cambiar la pila del pulsómetro (es normal que se agote, aunque justo lo acabes de comprar)
  2. Humedecer la banda del pulsómetro
  3. Reiniciar el rastreo desde el menú de Accesorios/Pulsómetro
  4. Dejar pulsados el botón de Lap y Start/stop simultáneamente durante 10 segundos
  5. Y sin con todo esto nada de nada: Dar la vuelta a la pila del pulsómetro, mantenerla al revés durante 10 segundos y ponerla bien de nuevo.

Esta última técnica que parece una broma, lo que hace realmente es resetear el ID del pulsómetro y le asigna un identificador nuevo. Con esto el pulsómetro vuelve a funcionar al siguiente rastreo. Para mí, fué como agua del carmen. Ojo que la pila, al estar al revés, hay que sacarla con un golpe seco.

El Garmin GPS no detecta los satélites

La solución empleada para que el reloj empezara a detectar los satélites fué pulsar simultáneamente la flecha hacia abajo y el botón de encendido. Es muy recomendable hacer esto en cielo abierto y dejarlo quieto al menos 20 minutos. Con esto se reinciará la información del satélite y debería permitir al dispositivo conectarse rápidamente la siguiente vez.

Si con todos estos consejos no te funciona, mira en el foro de Garmin [en inglés.]

Sponsors

Comments

No funciona el pulsómetro o GPS del Garmin Forerunner? (Juanma)
Muchiiisimas gracias!!!! me has salvado media vida y de llevarle al SAT de Garmin, porque ya no ......(02 Feb)
Borrar muchas fotos en Flickr (pansho)
hola, saben como eliminar un flickr? no me acuerdo de la contraseña y quiero eliminar esas fotos, ......(01 Feb)
Convert a CSV to JSON with PHP (alombarte)
For PHP5 you can use the function str_getcsv directly...(01 Feb)
Las mejores series de tv (debian)
joer tio eres muy gi, pa q carajo adelantas asuntos de las series? Pq dices que Lost termina ......(25 Jan)
Cómo reiniciar o resetear un ipod colgado (Nerva)
oh shit I work...(11 Jan)

Login

Otros blogs de nexoBlogs: