Spidermonkey – Execute javascript from console

SpiderMonkey is the code-name for the Mozilla's C implementation of JavaScript. This is useful to test part of our JavaScript from the console or in scripts.
In Debian we have a package called spidermonkey-bin.
apt-get install spidermonkey-bin
After installing you will have a program called smjs.
If you start the program without parameters you will get a Javascript shell, in which you can write and test javascript.
$ /usr/bin/smjs js> function test() { print('test'); } js> test function test() { print("test"); } js> test(); test js> function test() { print('test'); test2(123); } js> function test2(param) { print ('test2: ' + param); } js> test(); test test2: 123 js>
To exit the shell, just press "Ctrl+D".
It's important to note that in spidermonkey you doesn't have the "document" Object. If you want to print out text, you cant use document.write, you should use print.
document.write('test'); // In browser print('test'); //spidermonkey
You can also make smjs to execute the content of a file.
Installing TRAC with mod_wsgi using virtualenv
This guide is for installing Trac as a user using virtualenv for a isolated Python environment so that the whole installation runs under a specific user.
First of all we need to install needed packages
apt-get install libapache2-mod-wsgi python-virtualenv python-setuptools
Once we have installed the required packages proceed to create the Python environment
mkdir /usr/local/trac cd /usr/local/trac virtualenv python
We now have the isolated Python environment locate under /usr/local/trac/python.
To make possible to use easy_install with repositories we need to upgrade easy_install. I use this to install Trac plugins directly from SVN.
/usr/local/trac/python/bin/easy_install -U trunk
We now can install trac 0.12 using the 0.12b1 SVN Tag (http://svn.edgewall.com/repos/trac/tags/trac-0.12b1 or Trac==0.12b1) or directly from SVN Trunk:
/usr/local/trac/python/bin/easy_install http://svn.edgewall.org/repos/trac/trunk
This will download and install the latest trunk version for Trac.
Mysql Replication
Aqui voy a explicar como poder montar un sistema de maestro-esclavo(s) en mysql. La idea es que hay un servidor principal, que es en el que se modifican los datos y los esclavos solo estan ahi para tenerlo todo duplicado, esto es perfecto para hacer copias de seguridad. Si la idea es tener transferencia de datos bidireccional, hay que montar un "MySQL Cluster"
La replicacion funciona por medio de los binary log de mysql, asi que lo primero sera configurar correctamente el servidor maestro. Asi que añadimos estas opciones en el fichero my.cnf si aun no estan.
[mysql] #Activamos el log binario log-bin=mysql-bin #Establecemos un id para el servidor, el maestro SIEMPRE sera 1 server_id=1 #Esto ayuda por si el master tiene un cuelgue y no haya problemas en la replicacion al volver a arrancarlo sync_binlog=1 #Si trabajamos con INNODB, hay que activar esto innodb_flush_log_at_trx_commit=1
IMPORTANTE: Hay que comprobar que la linea skip-networking no este puesta en el master, ya que sino no abrira el puerto
PHP5 eAccelerator
Hacia tiempo que queria poner esto, pero nunca me he puesto. eAccelerator es un modulo de php que compila y carga en memoria las aplicaciones php, y con esto consigue que haya una mejora de respuesta y descarga bastante el servidor. Aqui os explico como instalar eAccelerator con PHP5 en una debian.
Lo primero que hay que hacer es descargarse la ultima version de eAccelerator, tambien necesitaremos en el server las utilidades de desarrollo de php
apt-get install php5-dev
La instalacion es realmente muy sencilla, solo tenemos que descomprimir, compiler, instalar y configurar.
- Descomprimimos
tar xvfj eaccelerator-0.9.5.tar.bz2- Compilamos
cd eaccelerator-0.9.5 phpize ./configure make
- Instalamos (nos pondra el modulo en la carpeta de modulos de php)
9e2f406f9c26a90c765c173da7f3c3f0025
MRTG Total
MRTG es una utilidad para monitorizar y generar graficos por medio de snmp. Para los que tengan como yo limite de consumo de trafico mensual, va muy bien tener un contador del total de consumo por dias y por meses.
Lo primero que tenemos que hacer es instalar los paquetes necesarios:
apt-get install mrtg libgd-graph-perl libgd-graph3d-perl snmpd
Una vez instalado, configuramos MRTG (/etc/mrtg.cfg):
################################################# # Multi Router Traffic Grapher -- Sample Configuration File ################################################# # This file is for use with mrtg-2.5.4c # Global configuration WorkDir: /var/www/mrtg #General title Title[^]: Traffic Analysis for Atlantis #We dont need Ipv6 EnableIPV6: no #Count in bits, grow from right to left, log unknow data as zero Options[_]: bits,growright,unknaszero #Target to monitor Target[atlantis]: 2:atlantis@localhost #Page title Title[atlantis]: Traffic Analysis for Atlantis PageTop[atlantis]: <H1>Our 100mbps link to the outside world</H1> #100mb MaxBytes[atlantis]: 12500000 WithPeak[atlantis]: ymw AbsMax[atlantis]: 1000000000000 #MRTG Total config (Title, Unit = M(Bytes)) #-#Total[atlantis]: Traffic Totals for Atlantis #-#Total-Unit[atlantis]: M #-#Total:Ratio[atlantis]: yes
Configurar SNMP (/etc/snmp/snmpd.conf):
com2sec local localhost atlantis com2sec atlantis 66.111.52.100 atlantis group MyROGroup v1 local group MyROGroup v1 atlantis view all-nibs included .1 80 access MyROGroup "" v1 noauth exact all-nibs none none syslocation altantis syscontact Root
Configuramos iptables para que no puedan acceder al SNMP desde fuera
#SNMPD Solo Local $IPTABLES -A INPUT -s 127.0.0.1 -p tcp --dport 199 -j ACCEPT $IPTABLES -A INPUT -s 127.0.0.1 -p udp --dport 161 -j ACCEPT $IPTABLES -A INPUT -s 85.17.1.127 -p tcp --dport 199 -j ACCEPT $IPTABLES -A INPUT -s 85.17.1.127 -p udp --dport 161 -j ACCEPT $IPTABLES -A INPUT -s 0/0 -p tcp --dport 199 -j DROP $IPTABLES -A INPUT -s 0/0 -p udp --dport 161 -j DROP
Descargamos mrtg_total y lo descomprimimos:
tar xvfj mrtg_total.tar.bz2 cd mrt_total unzip mrtg_total.zip
El script importante es mrtg_total.pl, y hay que añadirle en la primera linea del fichero #!/usr/bin/perl
Ahora añadimos al crontab que ejecute mrtg_total, por ejemplo cada 3 horas (/etc/crontab):



