Skip to content

Instantly share code, notes, and snippets.

static async Task<string> DownloadAllAsync(IEnumerable<string> locations)
{
var client = new HttpClient();
var downloads = locations.Select(client.GetStringAsync);
var downloadTasks = downloads.ToArray();
var pages = await Task.WhenAll(downloadTasks);
return string.Concat(pages);
}
@AlexArchive
AlexArchive / Program.cs
Created January 10, 2015 05:46
Exponential back off
private static async Task<string> DownloadStringWithRetries(string location)
{
using (var client = new HttpClient())
{
var nextDelay = TimeSpan.FromSeconds(1);
for (int i = 0; i != 3; i++)
{
try
{
Console.WriteLine("trying to download {0}.", location);
private static async Task<string> DownloadStringWithTimeout(string location)
{
using (var client = new HttpClient())
{
var downloadTask = client.GetStringAsync(location);
var timeoutTask = Task.Delay(TimeSpan.FromSeconds(3));
var completedTask = await Task.WhenAny(downloadTask, timeoutTask);
if (completedTask == timeoutTask)
USE [Medium]
GO
DELETE FROM [Post_Tag_Junction]
DELETE FROM [Posts]
DELETE FROM [Tags]
INSERT INTO [Tags]
VALUES
public class AddPostCommandHandler : IRequestHandler<AddPostCommand, string>
{
public string Handle(AddPostCommand command)
{
var param = new
{
PublishDate = DateTime.Now,
Slug = SlugConverter.Convert(command.Title),
command.Title,
command.Body,
public ActionResult AddPost(PostCommand command)
{
var response = mediator.Send(command);
if (response.Success) {
return RedirectToAction("Index", "Post", new { slug = response.Data.Slug });
}
ModelState.AddModelError("", response.Message)
return View(command);
}
@AlexArchive
AlexArchive / ndc-london-recordings.txt
Last active August 29, 2015 14:10
Powershell script to parse NDC London VODs prematurely
Capability Red - Requirements at Scale by Liz Keogh
http://www.ndcvideos.com/#/app/video/2111
----
Beyond Rectangles in Web Design - CSS Shapes and CSS Masking by Razvan Caliman
http://www.ndcvideos.com/#/app/video/2121
----
Coding Culture by Sven Peters
http://www.ndcvideos.com/#/app/video/2131
----
The Ultimate Logging Architecture - You KNOW You Want It by Michele Leroux Bustamante
class Program
{
static void Main(string[] args)
{
// The message you want to send accross the network
var outboundMessage = new ChatMessage { Body = "Hello" };
// Serialize the outbound message
byte[] outboundMessageData;
@AlexArchive
AlexArchive / gist:2fba07d46701acc11a7d
Last active August 29, 2015 14:10
SQL FILESTREAM with ADO.NET and C#
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.IO;
using System.Security.Cryptography;
namespace Uhu
{
public class Program