Skip to content

Instantly share code, notes, and snippets.

View FernandoVezzali's full-sized avatar

Fernando Ayrosa Vezzali FernandoVezzali

  • 06:16 (UTC -03:00)
View GitHub Profile
@FernandoVezzali
FernandoVezzali / ModelState.cs
Last active October 3, 2015 15:58
Model State
public ActionResult Index(Model model)
{
if (ModelState.IsValid)
{
// do stuff here
}
else
{
foreach (ModelState modelState in ViewData.ModelState.Values)
{
@FernandoVezzali
FernandoVezzali / gist:5029517
Last active December 14, 2015 04:39
hosts file - how to make the internet not suck (as much)
# This hosts file is brought to you by Dan Pollock and can be found at
# http://someonewhocares.org/hosts/
# You are free to copy and distribute this file, as long the original
# URL is included. See below for acknowledgements.
# Please forward any additions, corrections or comments by email to
# [email protected]
# Last updated: Feb 17th, 2013 at 13:37
@FernandoVezzali
FernandoVezzali / Extension Methods
Created February 26, 2013 14:46
Extension Methods
class Program
{
static void Main()
{
string s = "Hello Extension Methods";
int i = s.WordCount();
}
}
public static class MyExtensions
@FernandoVezzali
FernandoVezzali / ExtensionsAndDelegates
Last active December 14, 2015 12:59
Extensions with delegates
class Program
{
static void Main()
{
IEnumerable<string> names = new string[] { "Ireland", "Brazil", "Iceland" };
foreach (var name in names.Filter(predicate: StringThatStartWithI))
{
Console.WriteLine(name);
}
public static byte[] Foo()
{
using (var memStream = new MemoryStream())
using (var streamWriter = new StreamWriter(memStream))
{
for (int i = 0; i < 6; i++)
streamWriter.WriteLine("TEST");
streamWriter.Flush();
return memStream.ToArray();
@FernandoVezzali
FernandoVezzali / format Dates
Created April 3, 2013 09:39
This example shows how to use custom formatting strings to format Dates
d - Short date
%d - Day number
M?d - Month and day number
dd - Day number, two digits
ddd - Abbreviated day name
dddd - Full day name
f - Full (long date, short time)
%f - Fractions of second, one digit
s^f - Seconds and fractions of second, one digit
ff - Fractions of second, two digits
public static String Sha1(String plainText)
{
Byte[] text, hashBytes;
using (SHA1Managed sha1 = new SHA1Managed())
{
text = Encoding.Unicode.GetBytes(plainText);
hashBytes = sha1.ComputeHash(text);
}
return Convert.ToBase64String(hashBytes);
}
@FernandoVezzali
FernandoVezzali / gist:5654264
Last active December 17, 2015 18:38
models and commands
Install-Package EntityFramework.SqlServerCompact
Install-Package MvcScaffolding
public class Task
{
[Key]
public int TaskId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
@FernandoVezzali
FernandoVezzali / MailChimp.cs
Last active June 27, 2018 09:56
MailChimp example in C#
class Program
{
static void Main()
{
const string apiKey = "99999999999999999999999999999999-us2"; // Replace it before
const string listId = "b999jw9999"; // Replace it before
var options = new List.SubscribeOptions{DoubleOptIn = true,EmailType = List.EmailType.Html,SendWelcome = false};
var merges = new List<List.Merges> { new List.Merges("[email protected]", List.EmailType.Html) { { "FNAME", "John" }, { "LNAME", "Smith" } } };
var mcApi = new MCApi(apiKey, false);
@FernandoVezzali
FernandoVezzali / GetFakeStream
Created August 6, 2013 15:43
String To Stream
private MemoryStream GetFakeStream(string s)
{
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
}