This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static string GetJsonFromURL(string url) | |
{ | |
var request = WebRequest.Create(url); | |
var response = request.GetResponse(); | |
var dataStream = response.GetResponseStream(); | |
var reader = new StreamReader(dataStream); | |
string json = HttpUtility.HtmlDecode(reader.ReadToEnd()); | |
reader.Close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tasks = new Task[10]; | |
for (var i = 0; i < 10; i++) | |
{ | |
var x = i; | |
tasks[i] = Task.Factory.StartNew(() => new WorkerClass(x).Do()); | |
} | |
Task.WaitAll( tasks ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string[] names = new string[] { "Bill", "Jane", "Bob", "Frank" }; | |
var Bs_1 = names.Where(delegate(string s) { return s.StartsWith("B"); }); // Delegate | |
var Bs_2 = names.Where(s => s.StartsWith("B")); // Lambda |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://www.peterprovost.org/blog/2012/06/16/unit-testing-asp-dot-net-web-api/ | |
private static void SetupControllerForTests(ApiController controller) | |
{ | |
var config = new HttpConfiguration(); | |
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/products"); | |
var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}"); | |
var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "products" } }); | |
controller.ControllerContext = new HttpControllerContext(config, routeData, request); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.replaceAll = function( token, newToken, ignoreCase ) { | |
var _token; | |
var str = this + ""; | |
var i = -1; | |
if ( typeof token === "string" ) { | |
if ( ignoreCase ) { | |
_token = token.toLowerCase(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using(var scope = new TransactionScope(TransactionScopeOption.Required, | |
new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) | |
{ | |
// Do something | |
context.SaveChanges(); | |
// Do something else | |
context.SaveChanges(); | |
scope.Complete(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private MemoryStream GetFakeStream(string s) | |
{ | |
MemoryStream stream = new MemoryStream(); | |
StreamWriter writer = new StreamWriter(stream); | |
writer.Write(s); | |
writer.Flush(); | |
stream.Position = 0; | |
return stream; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("john@provider.com", List.EmailType.Html) { { "FNAME", "John" }, { "LNAME", "Smith" } } }; | |
var mcApi = new MCApi(apiKey, false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |