Skip to content

Instantly share code, notes, and snippets.

View goedecke's full-sized avatar

Werner E. Goedecke goedecke

View GitHub Profile
@goedecke
goedecke / mongodb-rep1-01.ps1
Last active August 29, 2015 14:20
Tutorial de Mongo
Estos son un conjunto de pequeños scripts para ayudar a entender cosas de programación
@goedecke
goedecke / cacheTest.php
Created May 22, 2016 02:45
Simple Sistema de Almacenamiento de Caché
<?php
// Define la ruta y nombre del archivo que se almacenara el cache
$cachefile = 'cached-files/'.date('M-d-Y').'.php';
// define el tiempo que queremos esperar el archivo en segundos.Yo puse el mio en 5 horas.
$cachetime = 18000;
// Revisa si el cache sigue fresco (activo). En el caso de que si lo incluye y sale
if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
include($cachefile);
exit;
}
@goedecke
goedecke / distancia.php
Created May 22, 2016 02:49
Calcula Distancias en PHP
<?
function distance($lat1, $lon1, $lat2, $lon2, $unit) {
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);
@goedecke
goedecke / download.php
Created May 22, 2016 02:53
Forzar un archivo a descargar
<?
function downloadFile($file){
$file_name = $file;
$mime = 'application/force-download';
header('Pragma: public'); // required
header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
@goedecke
goedecke / whois.php
Created May 22, 2016 03:02
whois basico con PHP
<?
$domains = array('home.pl', 'w3c.org');
function creation_date($domain) {
$lines = explode("n", `whois $domain`);
foreach($lines as $line) {
if(strpos(strtolower($line), 'created') !== false) {
return $line;
}
}
@goedecke
goedecke / xml2array.php
Created May 22, 2016 03:12
Este Script convierte un XML a un Arreglo
<?php
function xml2array($contents, $get_attributes=1, $priority = 'tag') {
if(!$contents) return array();
if(!function_exists('xml_parser_create')) {
//print "'xml_parser_create()' function not found!";
return array();
}
@goedecke
goedecke / extensions_custom.conf
Created May 22, 2016 03:37
Añadir re-enviador de SMS
//AL FINAL de /etc/asterisk/extensions_custom.conf
// Reemplaza <Tu TELEFONO> por Tu telefono
// Reemplaza <Tu correo> por Tu correo
[from-trunk-dongle]
exten => sms,1,Verbose(Incoming SMS from ${CALLERID(num)} ${BASE64_DECODE(${SMS_BASE64})})
exten => sms,n,System(echo "To: <Tu correo>\nSubject: Incoming SMS from ${CALLERID(num)}\n\n${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME} - ${CALLERID(num)}: " > /tmp/sms.txt)
exten => sms,n,Set(FILE(/tmp/sms.txt,,,a)=${BASE64_DECODE(${SMS_BASE64})})
exten => sms,n,System(sendmail -t < /tmp/sms.txt)
exten => sms,n,DongleSendSMS(dongle0,<Tu TELEFONO>,${BASE64_DECODE(${SMS_BASE64})} - De ${CALLERID(num)})
exten => sms,n,Hangup()
@goedecke
goedecke / dongle.conf
Created May 22, 2016 03:38
Archivo DONGLE.CONF
[general]
interval=15 ; Number of seconds between trying to connect to devices
;------------------------------ JITTER BUFFER CONFIGURATION --------------------------
;jbenable = yes ; Enables the use of a jitterbuffer on the receiving side of a
; Dongle channel. Defaults to "no". An enabled jitterbuffer will
; be used only if the sending side can create and the receiving
; side can not accept jitter. The Dongle channel can't accept jitter,
; thus an enabled jitterbuffer on the receive Dongle side will always
//Function
function csv($array) {
$csv = "";
for( $i = 0; $i < count($array); $i++ ) {
$csv .= '"' . str_replace('"', '""', $array[$i]) . '"';
if( $i < count($array) - 1 ) $csv .= ",";
}
return $csv;
}
@goedecke
goedecke / readcfdi.php
Created November 24, 2016 15:40
Extraer información de CFDI XML facil con simplexml
<?php
$xml = simplexml_load_file('test.xml');
$ns = $xml->getNamespaces(true);
$xml->registerXPathNamespace('c', $ns['cfdi']);
$xml->registerXPathNamespace('t', $ns['tfd']);
//EMPIEZO A LEER LA INFORMACION DEL CFDI E IMPRIMIRLA
foreach ($xml->xpath('//cfdi:Comprobante') as $cfdiComprobante){
echo $cfdiComprobante['version'];