Skip to content

Instantly share code, notes, and snippets.

View javierwilson's full-sized avatar

javier wilson javierwilson

  • Managua, Nicaragua
View GitHub Profile
@javierwilson
javierwilson / sessions.inc.php
Created February 9, 2012 03:16
php session management using postgresql
<?php
#
# manejador de sesiones
#
$sessiondb = pg_pconnect('dbname=sessions user=bob password=secret');
function on_session_start($save_path, $session_name) {
error_log("on_session_start: " . $session_name . " ". session_id());
}
@javierwilson
javierwilson / nginx.conf
Created February 20, 2012 22:41
soltando la conexión h ttp inmediatamente con nginx
server {
# this is to serve a 200.txt static file
listen 8888;
root /usr/share/nginx/html/;
}
server {
listen 8999;
location / {
rewrite ^ /200.txt break;
}
@javierwilson
javierwilson / reduce.py
Created February 27, 2012 03:06
Reduce "resolucion" de un KML
#!/usr/bin/python
import re
f = open('municipio.kml', 'r')
line = f.readline()
while line:
rline = line.rstrip()
redata = re.match('<coordinates>(.*?)</coordinates>',line)
if redata:
@javierwilson
javierwilson / soap-ejemplo.php
Created March 2, 2012 17:58
ejemplo de consulta soap usando SoapClient
<?php
$WSDL = 'http://example.com/?wsdl';
$client = new SoapClient( $WSDL );
$res = $client->consultaServicios(array('movil'=>'55555555', 'pass'=>'***'));
print_r($res);
@javierwilson
javierwilson / nusoap-ejemplo.php
Created March 2, 2012 18:02
ejemplo de consulta soap usando NuSoap
<?php
function consultaServicios($movil, $pass, $url){
require_once('nusoap/nusoap.php');
$cliente = new nusoap_client($url, true);
$err = $cliente->getError();
if($err){
$res = "->".$err;
return $res;
}
$params = array('movil' => $movil, 'pass' => $pass);
@javierwilson
javierwilson / smtp-nativo.txt
Created March 13, 2012 19:51
enviando correo vía telnet
$ telnet localhost 25
<< 220 mailserver.example.org ESMTP Sendmail; Tue, 13 Mar 2012 13:52:06 -0600
>> HELO my.example.com
<< 250 mailserver.example.org Hello localhost [127.0.0.1], pleased to meet you
>> MAIL FROM:[email protected]
<< 250 2.1.0 [email protected]... Sender ok
>> RCPT TO:[email protected]
<< 250 2.1.5 [email protected]... Recipient ok
>> DATA
<< 354 Enter mail, end with "." on a line by itself
@javierwilson
javierwilson / formats.py
Created March 15, 2012 01:28
solo usa decimales si es necesario y usa mil, millon
def number_format(x=0, precision=2, currency="US$ "):
x = Decimal('%.4f' % x)
fformat = '%.' + str(precision) + 'f'
nombres = ['', ' mil', ' millones']
if x < 1000:
s = (fformat % x).rstrip('0').rstrip('.')
s = s + nombres[0]
if 1000 <= x < 1000000:
s = (fformat % (x / 1000)).rstrip('0').rstrip('.')
s = s + nombres[1]
@javierwilson
javierwilson / utmToLatLng.py
Created March 30, 2012 17:44
Converts UTM to Latitude, Longitude
#!/usr/bin/python
# taken from http://stackoverflow.com/a/344083/1170404
# usage: cat filemame.txt | ./utmToLatLng.py
import math
import fileinput
# zone = 16 (Nicaragua)
def utmToLatLng(easting, northing, northernHemisphere=True, zone=16):
@javierwilson
javierwilson / exmaple.conf
Created March 30, 2012 18:18
configuracion nginx para proyecto django (gunicorn)
server {
listen 192.168.1.1:80;
server_name example.com;
root /var/www/example/static;
access_log /var/log/nginx/example-access.log;
location = /favicon.ico { access_log off; log_not_found off; }
location /media {
root /var/www/example/;
}
@javierwilson
javierwilson / example.sh
Created March 30, 2012 18:21
Script para ejecutar proyecto Django con gunicorn
#!/bin/sh
SITE_PATH=/var/www/example/; export SITE_PATH
USER=apache
#TCP=$HOSTNAME:8888
TCP=127.0.0.1:8888
runuser $USER -s /bin/bash -g $USER -c "/usr/bin/gunicorn_django -b ${TCP} -w 3 --max-requests=1000 ${SITE_PATH}settings 2>&1"