Category Archives: Software

Node.js’s Stitch + NginX: don’t use the trailing slash on proxy_pass

This is a remainder for me of what failed. While using stitch module for Node.js together with NginX as proxy-reverse for my application I got 404 while trying to get /application.js, except anything else being generated at run-time.

The reason was the trailing slash in proxy_pass variable. So, instead of

proxy_pass http://127.0.0.1:88334/;

You should use

proxy_pass http://127.0.0.1:88334;

That fixed my issue, didn’t had time to do further investigation, but that’s a workaround for that issue.

Express Sessions with connect-redis + Socket.IO in CoffeeScript

If you are working with Socket.IO and Express Framework while developing your applications you must know they work together so Socket.IO will listen on the same port that your HTTP/S server and will serve the requests by that way, but Socket.IO doesn’t works on the same paradigm where you pass a middleware to the route and you could get authentication on this manner. Instead, you must configure Socket.IO with a global authorization method or a handshake authorization manner.

Since in my applications I serve cookies already where I save session info and this is already stored in Redis with help of the module connect-redis then I should be able to get this info onto Socket.IO authorization method and with this allow only to authorized users to get info from my websockets.

I found how to do it with the default session-store in-memory from Express, and adapted that so it could work with Redis.

Here’s the snippet:

Hope anyone can found it useful!

Polipo and uncachable file

Dear lazyweb,

I was searching through the internet what was I doing wrong, I wrote to the polipo-user list but my email got stuck on moderation, and my connection is really shitty (that’s why I’m using polipo the way I’m using it). I have relaxTransparency and mindlesslyCacheVary set to true, but I don’t need so aggresive caching in my development stages that are located under *.local and another development subdomain on the net.

Already tried setting uncachableFile to /etc/polipo/uncachable and to ~/.polipo-uncachable, according to the web-config thing is properly setted up, but can’t get it to recognize it’s content. I first thought it was I was writing bad the regex, .*\.local but it does work in the /etc/polipo/forbidden file. Besides, adding complete domains to the uncachable file doesn’t works neither. Could someone confirm this or throw me a hand on this? I’m using 1.0.4.1-1.1 version which is the last one on unstable repos.

and issues on vim with $TERM=”screen”

Because of tmux I run with $TERM=”screen” instead of my regular rxvt-unicode, but I had a big issue with VIM because of this, it kept writing and F\n and H\n each time I pressed and keys respectively. I finally found the way to solve this, making VIM use $TERM=”xterm” internally writing this on my ~/.vimrc:

if &term == "screen"
  set term=xterm
endif

So, this way, even in my servers without XTerm installed (but ncurses-term) I can use VIM as I’m used to.

Moving from Screen to Tmux

I’ve been a long-time user of GNU Screen, as almost every person I know that spend a lot of time in a terminal.

I must admit I was happy, I really was. I was used to my workflow with 4 terminals 8×25 and a bunch of screens, with several nested-screens. I used awesome-wm before, so definitely I felt I wasn’t using all the space in my laptop screen (my laptop is a ThinkPad X61, so 1024×768 in a 12 inches-screen) but that was OK, after all my workflow was, well, good.

Until 2 days ago, I was told to try tmux, in fact, I was told «and why are you using screen? use tmux». As a daily-user of Screen my first reaction was «I’m used to», «I can use it as I want», and a lot of excuses for just not trying something new. But then I made a little research (on Google, of course). In about 30 minutes I ended up with a multiplexer working as I wanted and as I never got Screen to work. Finally I was using just a terminal and using all the space available in my tiny-laptop-screen and plus: saving a lot of bandwidth with my permanent SSH connection (a really big plus now that I’m living with a capped link to the net with a GSM-modem).

I changed the Ctrl-b shortcut to Ctrl-a (b is too far for using it with only one hand), configured so I could use nested tmux’es like screen when I push Ctrl-a a, activated visual monitoring and even got to use the tmux’s buffer along with my X11 buffer when I press Ctrl-a >!!

It’s all in my ~/.tmux.conf, use it at will. Later I will make a screencast about using tmux, so more people can get a working tmux easily.

ATM, I’m even more happy than I was with GNU Screen, so, any other recommendation, people?

Changing background sync’d with jQueryUI Tabs

I love to use jQuery UI plugins. The one I use constantly is Tabs and this time I needed to sync the auto-changing of tab with the background. For this I used an event called

tabsshow

to trigger my function + the code I wrote yesterday for full-page background with CSS:

/* @author Jose Luis Rivas <joseluis@eserre.com>
 *
 * @desc swaping full-background pages with jQuery UI's Tabs plugin events.
*/



$(document).ready(function() {

  $( "#slides" ).bind( "tabsshow", function(event, ui) {
    var tabattr = $('.ui-state-active').find('a').attr('href');

    switch(tabattr) {
      case '#tab1':
        $('img#bg').attr('src', '/img/tab1.jpg');
        break;

      case '#tab2':
        $('img#bg').attr('src', '/img/tab2.jpg');
        break;

      default:
        $('img#bg').attr('src', '/img/tab1.jpg');
                                break;
    }

  });

});

What it does the script?

Finds the active-tab identified with the

.ui-state-active

class and then changes the

img

tab

src

attribute according to the

href

attribute of the active-tab.

Full-Page Background with CSS with crossbrowser support

I’ve been trying to get the perfect full-page background without using JavaScript since a while. I tried with CSS3 but, obviously for IE <9 was a pain in the ass, even for older Firefox' releases. So I decided to go with the plain-CSS option:

<!doctype html>
<head>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <img id="bg" src="/img/bg.jpg">

  <p>Content</p>
</body>
</html>
img#bg {
  min-width: 100%;
  min-height: 100%;
 
  /* Proportionate re-dimension */
  width: 100%;
  height: auto;

  position: fixed; top: 0; left: 0;

  z-index: -1;
}

What does it does?

It takes an inline image and uses it as if were a

background-image

thanks to the

z-index: -1

CSS-rule.

There are lots of other techniques at CSS-Tricks but none works in every browser as this one in particular.

Enjoy.

Moved from approx to apt-cacher-ng

I have been a long-time user of

approx

, I got used to it and knew how to configure it so all my machines + VMs used the same cache and saved me a lot of bandwidth.

But that was when I got a stable connection at >100KiB/s in a daily-basis. Now I’m with a mobile connection at <30KiB/s and sometimes is intermittent, so

approx

started giving me a lot of headaches.

When

approx

tries to connect a host that can’t be resolved its domain name, then gets 404. How does that reflects in the

/pool

? Well, you get a file

touch

‘d and 0 bytes size. When you try again,

approx

will find the same file with 0 bytes size and will gives you again a 404, even if you can now resolve the name address of that domain. And as I like to use what I know, then I made a workaround: Each time this happened I ran:

# find /var/cache/approx -size 0 | xargs rm

So next time I requested a file to

approx

it tried to connect to the host. But I got tired.

I installed

apt-cacher-ng

, tweaked a bit

/etc/apt-cacher-ng/acng.conf

so it uses port 9999 and the cache dir redirects to the same cache than

approx

and done.

apt-cacher-ng

returns 503 when it can’t connect to the peer, even tries to several repositories with only a line in

/etc/apt/sources.list

in my clients. It makes me happy and keeps saving me a lot more of bandwidth than

approx

.

Deck.js: Para hacer presentaciones con HTML+JS

Hoy navegando me topé con esta librería Javascript para hacer lo que llaman presentaciones modernas con HTML. Depende de jQuery y Modernizr para hacer la magia y está bajo una licencia dual MIT/GPL. Funciona en IE7+, Opera, Chrome, Firefox y Safari.

La librería en cuestión se llama Deck.js y pueden ver una demostración de sus resultados, incluye más temas y documentación para que tú mismo crees tus temas si manejas CSS+JS.

Pueden hacer un fork del código de Deck.js desde GitHub.

«Licencias para Desarrolladores en el mundo Open Source», la presentación en PDF

Para los que asistieron y para los que no a mi charla en el Día Debian 2011 de Barquisimeto, aquí les dejo mis láminas en formato PDF y fácilmente leíbles desde la web con Scribd.

Pronto estaré escribiendo más sobre el tema de la propiedad intelectual que poco se ha urgado en la comunidad hispana pero que sigue teniendo efectos sobre nuestras acciones.