lunes, 6 de octubre de 2014

Agregar exepciones al firewall desde C#

Primero agregamos la referencia a la dll:

Microsoft.TeamFoundation.Common


Luego pegamos el código:


public static INetFwMgr WinFirewallManager()
{
Type type = Type.GetTypeFromCLSID(
new Guid("{304CE942-6E39-40D8-943A-B913C40C9CD4}"));
return Activator.CreateInstance(type) as INetFwMgr;
}

public static bool AuthorizeProgram(string title, string path,
NET_FW_SCOPE_ scope, NET_FW_IP_VERSION_ ipver)
{
Type type = Type.GetTypeFromProgID("HNetCfg.FwAuthorizedApplication");
INetFwAuthorizedApplication authapp = Activator.CreateInstance(type)
as INetFwAuthorizedApplication;
authapp.Name = title;
authapp.ProcessImageFileName = path;
authapp.Scope = scope;
authapp.IpVersion = ipver;
authapp.Enabled = true;

INetFwMgr mgr = WinFirewallManager();
try
{
mgr.LocalPolicy.CurrentProfile.AuthorizedApplications.Add(authapp);
}
catch (Exception ex)
{
System.Diagnostics.Trace.Write(ex.Message);
return false;
}
return true;
}


Y por ultimo lo llamamos de la siguiente forma:


AuthorizeProgram("TCP", @"C:\TCP.exe", NET_FW_SCOPE_.NET_FW_SCOPE_ALL, NET_FW_IP_VERSION_.NET_FW_IP_VERSION_ANY);

jueves, 14 de agosto de 2014

Obtener día Lunes de la semana en C#

Para obtener el día lunes de la semana que queramos, podemos utilizar la siguiente linea de código:


DateTime Lunes = new DateTime(2014, 08, 14);
Lunes = Lunes.AddDays(-1 * (Convert.ToInt32(Lunes.DayOfWeek) == 0 ? 7 : Convert.ToInt32(Lunes.DayOfWeek)));

viernes, 4 de julio de 2014

Para los amantes de MVC, un e-commerce open source

Dejo aquí un muy buen e-commerce totalmente realizado en MVC de Microsoft:

Página: http://www.nopcommerce.com/

Demo Front End: http://demo.nopcommerce.com/

Demo Back End: http://admin-demo.nopcommerce.com/login?ReturnUrl=%2fadmin%2f

De la misma página pueden bajar el código o solo la web lista para instalar.

Espero que les sirva.

jueves, 3 de julio de 2014

Leyendo RSS con PHP

<?php
header('Content-Type: text/html; charset=utf-8');
$url = "[URL]";
$rss = simplexml_load_file($url);
if($rss)
{
echo '<h1>'.$rss->channel->title.'</h1>';
echo '<p>'.$rss->channel->pubDate.'</p>';
$items = $rss->channel->item;
foreach($items as $item)
{
$title = $item->title;
$link = $item->link;
$published_on = $item->pubDate;
$description = $item->description;
$totallen = strlen($title);
echo '<h3><a href="'.$link.'">'.$title.'</a></h3>';
echo '<span>('.$published_on.')</span>';
echo '<p>'.$description.'</p>';
}
}
?>

miércoles, 2 de julio de 2014

Pequeño sistema que permite subir fotos y realizar un resize antes deguardarlas en nuestro servidor

Dejo aquí un pequeño sistema que permite subir, hacer resize, guardar la imagen en nuestro y por ultimo entrega una URL para poder utilizarla en foros y demás.

Descarga: http://1drv.ms/1pWpYjs

post.php

Se debe especificar cual es el ancho y largo máximo en la linea:

$resize->resizeTo(500, 500, 'maxWidth');


y por ultimo cambiar http://tuweb.com/loadimg/ por tu path.

Espero que les sirva!

lunes, 30 de junio de 2014

miércoles, 18 de junio de 2014

Instalar LAMP en Ubuntu

Dejo aquí la forma de instalar LAMP  (Linux Apache MySQL PHP) sobre Ubuntu y que salga funcionando sin problemas.

Apache


Instalación:
sudo apt-get install apache2

Con esto ya queda instalado, a continuación les dejo varios comandos que quizás necesiten:

Iniciar el servidor:
sudo service apache2 start

Detener se servidor:
sudo service apache2 stop

Por ultimo, la carpeta donde debes dejar tus HTML y PHP es
/var/www

PHP


Instalar PHP:
sudo apt-get install php5 libapache2-mod-php5 php5-cli php5-mysql

Reiniciar el PHP:
sudo service apache2 restart

Podemos probar esto poniendo un archivo PHP como por ejemplo /var/www/index.php e insertando la dirección http://localhost en nuestro navegador.

MySQL


Instalación:
sudo apt-get install mysql-server mysql-client libmysqlclient-dev

Por ultimo instalamos (si queremos) el phpMyAdmin con la siguiente linea:
sudo apt-get install phpmyadmin