Skip to content

Instantly share code, notes, and snippets.

View pipe.js
let pipe = (value, ...funs) => {
return funs.reduce((accumulator, currentFun) => currentFun(accumulator), value);
}
let add1 = x => x + 1;
let multiply2 = x => x * 2;
pipe(10, add1, add1, multiply2, console.log);
@tuan
tuan / onceWithin.js
Last active Jun 14, 2016
Executes a function once within a specified time window
View onceWithin.js
const once = (fun, timeoutInMilliseconds) => {
let inProgress = false;
setTimeout(() => {
inProgress = false;
}, timeoutInMilliseconds);
return () => {
if (inProgress) {
return;
@tuan
tuan / UploadMultipleBlobs.cs
Created Feb 6, 2016
A test console app to upload multiple blobs to Azure Blob Storage in parallel
View UploadMultipleBlobs.cs
class Program
{
static void Main(string[] args)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
UploadToBlobAsync().Wait();
stopwatch.Stop();
Debug.WriteLine("Elapsed time in seconds: " + stopwatch.ElapsedMilliseconds / 1000);
}
@tuan
tuan / SendMailAsync.cs
Created Feb 6, 2016
Implementation of SendMailAsync that correctly cancels the operation when CacellationToken is cancelled.
View SendMailAsync.cs
public async Task SendMailAsync(MailMessage message, CancellationToken ct)
{
try
{
var task = _smtpClient.SendMailAsync(message);
using (ct.Register(_smtpClient.SendAsyncCancel))
{
try
{
await task;
@tuan
tuan / SmtpClientWrapper.cs
Last active Feb 6, 2016
SendMailAsync with cancellation token
View SmtpClientWrapper.cs
public class SmtpClientWrapper : IDisposable
{
private SmtpClient _smtpClient;
public SmtpClientWrapper(SmtpClient smtpClient)
{
this._smtpClient = smtpClient;
}
public async Task SendMailAsync(MailMessage message, CancellationToken ct)
@tuan
tuan / ParallelUploadToBlobStorage.cs
Created Feb 6, 2016
Upload multiple files to azure blob storage in parallel
View ParallelUploadToBlobStorage.cs
class Program
{
static void Main(string[] args)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
UploadToBlobAsync().Wait();
stopwatch.Stop();
Debug.WriteLine("Elapsed time in seconds: " + stopwatch.ElapsedMilliseconds / 1000);
}