Skip to content

Instantly share code, notes, and snippets.

View FernandoVezzali's full-sized avatar

Fernando Ayrosa Vezzali FernandoVezzali

  • 09:00 (UTC -03:00)
View GitHub Profile
// first install this NuGet package: Install-Package ftplib
static void Main(string[] args)
{
using (var tConn = new FtpConnection("00.000.00.000", "UserName", "Password"))
{
tConn.Open();
tConn.Login();
if (tConn.DirectoryExists("/www"))
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#@ assembly name="System" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="System.Xml.Linq" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Xml.Linq" #>
<#@ import namespace="System.Collections.Generic" #>
@FernandoVezzali
FernandoVezzali / 0_reuse_code.js
Last active August 29, 2015 14:12
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@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
# hosts@someonewhocares.org
# 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);
}