Archivos de la categoría ‘QuickSnippets’

Remove Outline in Firefox (in anchor, inputs, buttons, etc) with CSS

Septiembre 30, 2009

Firefox most-pain-in-the-ass-for-developers ‘feature’ it’s to put an outline dotted in grey in every link, button or input we focus (or click).

This could be easily solved using a simple CSS line using Mozilla’s own pseudo-selectors:

a::-moz-focus-inner { border: 0;outline:0 }

That’s it. And be careful: there are two colons not just one. That works for links, but you can make it to every tag Firefox implements like buttons or input button or submit.

It may work just with ‘

outline: 0;

‘ but it’s been reported of this working bad with old versions of Firefox.

input::-moz-focus-inner { border: 0;outline:0 } // for all inputs
input[type=button]::-moz-focus-inner { border: 0;outline:0 } // for input tag type button
input[type=submit]::-moz-focus-inner { border: 0;outline:0 } // for input tag type submit
button::-moz-focus-inner { border: 0;outline:0 } // for button tag

Or you can just apply when it’s on focus:

input:focus::-moz-focus-inner { border: 0;outline:0 } // for all inputs on focus

Mostrar archivos ocultos en Finder de MacOSX

Marzo 29, 2009

Siempre tengo que andar rebuscando por Internet la forma de hacer esto, así que voy a poner la forma para tenerla a mano, y ayudar a quién lo necesite.

Para visualizar archivos ocultos en Finder como los archivos .DS_Store, .htaccess o demás, abrid el terminal (Aplicaciones > Utilidades > Terminal) y escribís estas dos líneas, por separado:

defaults write com.apple.finder AppleShowAllFiles TRUE

Primero, y luego:

killall Finder

Y listo.

Natural Sort in MySQL

Enero 17, 2009

Usually, when we have a varchar field in a MySQL table, we need to sort the rows in natural order and MySQL returns them in linear order.

Given these three rows: Foo 10, Foo 400 and Foo 50 with a query like this:

select * from `table` order by `field` desc

Will return the rows in the order: Foo 50, Foo 400 and Foo 10, so, having that 400 is a larger int than 50, we need to make a little trick in the query:

select * from `table` order by `field + 0` desc

Adding this ‘ + 0 ‘ (plus zero) in the query will avoid the ‘bug’ and sort your rows in natural order in MySQL.

.htaccess – rewriteengine on doesn’t work

Noviembre 17, 2008

If when you start using the RewriteEngine On directive in .htaccess file you get an invalid error code, and Apache doesn’t seem to understand the Rewrite directives, you should find this in the error logs:

Invalid command ‘RewriteEngine’, perhaps misspelled or defined by a module not included in the server configuration, referer:

To solve this, you need to edit the httpd.conf and find the mod_rewrite module, and activate it:

LoadModule rewrite_module modules/mod_rewrite.so

If the line is disabled/commented (with a ‘#’), it just need to be removed. Restart Apache and everything should work now.

Get the number of Disqus comments with PHP (or any other language)

Agosto 21, 2008

Disqus a great service. I suppose it will take a few months until the whole ‘blogothingy’ realizes how important this is for all. Then, in less than a year from now any Internet giant will acquire them, i’m sure of it.

I’ve been playing with it from a time now and, as everyone should now, i really love APIs, but for the moment Disqus’ one is not ready yet.

So, I needed to get the number of comments of a thread dinamically to display the number outside the thread page and get some stats, but there’s no ‘direct way’ of getting them. Lucky me, I found a way.

Using Disqus’ Feedflare for Feedburner (Disqus > Your Panel > Tools > Feedburner) you’ll find a XML similar to this:

http://WEBSITE_NAME.disqus.com/~feedflare/comments_link.xml

This is an XML wich displays the number of comments in a Feedburner-Feedflare way. Pretty simple:

<FeedFlareUnit>
    <Catalog>
        <Title>Disqus Comments Link</Title>
        <Description>Display the number of comments for each post.</Description>
    </Catalog>
    <DynamicFlare href="http://disqus.com/forums/WEBSITE_NAME/%7Efeedflare/comments_link_dynamic.xml?url=${link}"/>
    <SampleFlare>
        <Text>17 Comments</Text>
</SampleFlare>
</FeedFlareUnit>

So, now we get a URL to display the number of comments of a given thread url with via HTTP GET:

http://disqus.com/forums/WEBSITE_NAME/%7Efeedflare/comments_link_dynamic.xml?url=${link}

That’s it all, replace ${link} with the URL of the thread and it will display the number of comments like this.

X Comment/s

So, now, if you now some basic programming, it’s easy to get the info.

function commentsNumber($website,$url) {
$c = file_get_contents('http://disqus.com/forums/'.$website.'/~feedflare/comments_link_dynamic.xml?url='.$url);
preg_match("#([0-9]+) (Comment|Comments)#",$c,$n);
return $n[1];
}

This will return ONLY the number of comments, but you can return $n[0] for example if you would like to get full string.