2015/06/28

Update from sqlserver example

UPDATE t
SET t.col1 = other_table.col1,
t.col2 = other_table.col2
FROM Table t INNER JOIN
OtherTable other_table ON (t.id = other_table.id)
view raw gistfile1.sql hosted with ❤ by GitHub

2015/06/20

How to send mail using SwiftMailer library through your gmail account in PHP ?

Swift mailer library:http://swiftmailer.org/

$transport = \Swift_SmtpTransport::newInstance("smtp.gmail.com", 465, "ssl");
$transport->setUsername("alias@gmail.com");
$transport->setPassword("password");
$email_body = \Swift_Message::newInstance()
->setSubject("Mach2 - error reporting")
->setFrom(["src_alias@gmail.com" => "Mach2"])
->setTo("dest_alias@gmail.com")
->setBody($message, 'text/html');
$mailer = \Swift_Mailer::newInstance($transport);
$ret = $mailer->send($email_body);
view raw gistfile1.php hosted with ❤ by GitHub

2015/06/18

How to redirect https request to http for domain ?

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(www\.)?domainname\.com$ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
view raw gistfile1.txt hosted with ❤ by GitHub

2015/06/12

How to give alias to namespace in using instruction ?

using DbAzure = JobOffers.EF.Azure;
view raw gistfile1.cs hosted with ❤ by GitHub

How to perform SET IDENTITY INSERT ON from Entity Framework ?

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
{
using (var conn = new System.Data.SqlClient.SqlConnection(_connectionstring))
{
conn.Open();
using (Context context = new Context(conn, false))
{
context.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [dbo].[TableName] ON");
context.TableName.AddRange(items);
context.SaveChanges();
context.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [dbo].[TableName] OFF");
scope.Complete();
}
}
}
view raw gistfile1.cs hosted with ❤ by GitHub
Thanks to: http://blog.robertobonini.com/2014/10/09/entity-framework-with-identity-insert/

2015/06/08

How to send email using gmail account in C# ?

MailMessage mail = new MailMessage("senuto.development@gmail.com", "mwlasny@gmail.com");
SmtpClient client = new SmtpClient()
{
Port = 587,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Host = "smtp.gmail.com",
Credentials = new NetworkCredential("senuto.development@gmail.com", "@stron@ut@"),
EnableSsl = true,
};
mail.Subject = "test";
mail.Body = "test";
client.Send(mail);
view raw gistfile1.cs hosted with ❤ by GitHub

2015/06/03

How to match GMT date using regular expression in PHP ?

// GMT date format 3 Jun 2015 06:59:23
preg_match("/(?<day>\d{1,2}) (?<month>[a-zA-Z]{3}) (?<year>\d{4}) (?<hours>\d{1,2}):(?<minutes>\d{2}):(?<seconds>\d{2})/", $date, $match);
view raw gistfile1.php hosted with ❤ by GitHub