Una linea con epoch time, latitud y longitud.
El epoch time se esta reemplazando por la fecha en formato "%Y%m%dT%H%M%S"
echo "1288552753,38.995177,-76.881886" | \
TZ=UTC awk -F, '{ print strftime("%Y%m%dT%H%M%S",$1)","$2","$3 }'
viernes, 17 de diciembre de 2010
jueves, 11 de noviembre de 2010
Usando indice de Qgis con Python
Si es que alguna vez tienen que asignar un lat long a una id de un polygono, una forma de hacerlo procesando por linea es usando la API de Qgis
from qgis.core import *
QgsApplication.setPrefixPath("/usr", True)
QgsApplication.initQgis()
vlayer = QgsVectorLayer( "polygons.shp", "temp_layer", "ogr" )
provider = vlayer.dataProvider()
#main dict to get precalculated values from layer
id2feat = {}
#spatial index to optimize lookup
index = QgsSpatialIndex()
#retrive just the first field from the map layer
provider.select([ 0 ])
#temporal feature
feat = QgsFeature()
while provider.nextFeature( feat ):
index.insertFeature( feat )
id2feat[ feat.id() ] = str( feat.attributeMap()[ 0 ].toString() )
for line in sys.stdin:
fields = line.strip().split(',')
#read longitude and latitude values
if len( fields[ 0 ] ) and len( fields[ 1 ] ):
longitude = float( fields[ 0 ] )
latitude = float( fields[ 1 ] )
else:
print ','.join( fields + [ '' ] )
continue
#query geometries
rect = QgsRectangle(longitude,latitude,longitude,latitude)
point = QgsGeometry.fromPoint( QgsPoint( longitude, latitude ) )
#query the index for bbox intersections
intersects = index.intersects( rect )
found = False
for i in intersects:
provider.featureAtId( i, feat )
if point.intersects( feat.geometry() ):
print ','.join( fields + [ id2feat[ i ] ] )
##IN CASE WE CARE ABOUT JUST ONE INTERSECTION
found = True
break
if not found:
print ','.join( fields + [ '' ] )
Cambiar de usuario en svn
Perdonen lo básico, pero siempre se me olvida...
Cómo cambiar de usuario en svn
svn --username=new_user
va a preguntar por el password del nuevo usuario, y en lo sucesivo quedará ese usuario almacenado para todas las futuras transacciones con svn.
miércoles, 20 de octubre de 2010
Postgres Statistics
These are some queries that could be useful, extracted
from Zabbix project.
And oid2name is very useful too, we can know what is the OID code for each
object in our database
from Zabbix project.
psql --version|head -n1
psql -t -c "select sum(numbackends) from pg_stat_database"
psql -t -c "select sum(xact_commit) from pg_stat_database"
psql -t -c "select sum(xact_rollback) from pg_stat_database"
psql -t -c "select sum(xact_commit) from pg_stat_database"
psql -t -c "select sum(xact_rollback) from pg_stat_database"
psql -t -c "select pg_database_size('$1')"
psql -t -c "select numbackends from pg_stat_database where datname = '$1'"
psql -t -c "select tup_returned from pg_stat_database where datname = '$1'"
psql -t -c "select tup_fetched from pg_stat_database where datname = '$1'"
psql -t -c "select tup_inserted from pg_stat_database where datname = '$1'"
psql -t -c "select tup_updated from pg_stat_database where datname = '$1'"
psql -t -c "select tup_deleted from pg_stat_database where datname = '$1'"
psql -t -c "select tup_returned from pg_stat_database where datname = '$1'"
psql -t -c "select tup_fetched from pg_stat_database where datname = '$1'"
psql -t -c "select tup_inserted from pg_stat_database where datname = '$1'"
psql -t -c "select tup_updated from pg_stat_database where datname = '$1'"
psql -t -c "select tup_deleted from pg_stat_database where datname = '$1'"
And oid2name is very useful too, we can know what is the OID code for each
object in our database
/usr/lib/postgresql/8.3/bin/oid2name -d database -x
jueves, 19 de agosto de 2010
copy files to another machine using tar
tar cf - * | ssh user@host "(cd /destination_dir; tar xf -)"
miércoles, 18 de agosto de 2010
viernes, 13 de agosto de 2010
viernes, 11 de junio de 2010
Mas un validador de RUT en javascript
Buscando por la red encontré varios validadores de RUT, pero los encontré amorfos y con mucho código extra. Como soy niubi en esto, espero vuestros comentarios y recomendaciones.
Para terminar, condimente con este pedazo de código:
// String aceptado debe incluir solo numeros y "k"
function rut_check(rut){
var sum = 0;
var tail = rut.slice(-1);
for(f = 2, i = 0, j = rut.length - 2; i < rut.length - 1; ++i, --j, ++f){
f = (f > 7) ? 2 : f;
sum += f * rut.substr(j, 1);
}
digit = 11 - (sum % 11);
digit = (digit == 11) ? 0 : digit;
digit = (digit == 10) ? "k" : digit;
return digit.toString() == tail;
}
Para terminar, condimente con este pedazo de código:
// Funcion para permitir solo entrada numerica o k
function rut_validkey(e){
var key;
if(window.event) e = window.event // Windows Support
key = e.keyCode ? e.keyCode : e.which; // Firefox & Chromium support
// control keys
if(key==8 || key==9 || key==13 || key==27 || (key > 36 && key < 41))
return true;
if(key == 107 || key == 75 || (key > 47 && key < 58))
return true;
return false;
}
Suscribirse a:
Entradas (Atom)