Skip to content

Instantly share code, notes, and snippets.

@davideicardi
davideicardi / msdeploy-azure.ps1
Last active February 24, 2017 17:35
Deploy a website to azure using web deploy cmd
# $deployCredentials = d3-CreateCredential
# d3-AzureMsDeployWebSite -deployCredentials $deployCredentials -siteName "webplu-test-distribution" -packageDeployCmd "./Deltatre.Forge.DistributionApi.deploy.cmd"
Function d3-AzureMsDeployWebSite
{
param(
[Parameter(Mandatory = $true)]
[PSCredential]$deployCredentials,
[Parameter(Mandatory = $true)]
@davideicardi
davideicardi / ThrottledWorker.cs
Last active June 5, 2017 14:33
C# throttled worker with duplicate detection
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsyncThrottledSetSample
{
class Program
{
@davideicardi
davideicardi / checkurl.ps1
Last active July 18, 2017 16:50
Check url with powershell
invoke-webrequest http://www.lastampa.it/ -DisableKeepAlive -UseBasicParsing | Select -ExpandProperty "StatusCode"
@davideicardi
davideicardi / oembed-webtask.js
Last active September 27, 2017 22:24
oEmbed creator webtask
'use latest';
import express from 'express';
import { fromExpress } from 'webtask-tools';
import bodyParser from 'body-parser';
import request from 'request';
import cheerio from 'cheerio';
import escapeHtml from 'escape-html';
const app = express();
@davideicardi
davideicardi / uuidHelpers.js
Created November 16, 2017 15:52
Mongodb uuid helpers
// Javascript helper functions for parsing and displaying UUIDs in the MongoDB shell.
// This is a temporary solution until SERVER-3153 is implemented.
// To create BinData values corresponding to the various driver encodings use:
// var s = "{00112233-4455-6677-8899-aabbccddeeff}";
// var uuid = UUID(s); // new Standard encoding
// var juuid = JUUID(s); // JavaLegacy encoding
// var csuuid = CSUUID(s); // CSharpLegacy encoding
// var pyuuid = PYUUID(s); // PythonLegacy encoding
// To convert the various BinData values back to human readable UUIDs use:
// uuid.toUUID() => 'UUID("00112233-4455-6677-8899-aabbccddeeff")'
@davideicardi
davideicardi / server.js
Created November 29, 2017 18:12
Stupid node.js utility that capture and print any http request
const express = require("express");
const app = express();
app.all("/*", (req, res) => {
console.log(`${req.method} ${req.originalUrl}`);
for (const h in req.headers) {
console.log(`\t ${h}:${req.headers[h]}`);
}
@davideicardi
davideicardi / TimerAsync.cs
Created February 19, 2018 21:34
A Timer that execute an async callback at the specified interval
/// <summary>
/// A Timer that execute an async callback after a due time and repeating it after a period (interval).
/// Callback is a non reentrant timer (ie. callbacks never overlaps). Dispose method wait for the current callback to finish.
/// Timer can be cancelled using a CancellationToken or by calling StopAsync or by calling Dispose.
/// Exception inside callbacks are ignored and just traced.
/// Callback is invoked at each interval (period) after the end of the previous invocation.
/// </summary>
public sealed class TimerAsync : IDisposable
{
private readonly Func<CancellationToken, Task> _callback;
@davideicardi
davideicardi / README.md
Last active March 7, 2018 16:37
Development mongodb cluster tutorial
@davideicardi
davideicardi / guide.md
Last active July 30, 2018 13:49
Steps to convert .csproj to new VS 2017 format (.NET 4.5 to .NET Core)

Convert a .NET 4.x project to .NET Core

Steps to convert .csproj to new VS 2017 format (.NET 4.5 to .NET Core)

  • delete any files inside the project folder but not included in the project
  • unload project from visual studio
  • edit .csproj
  • a .csproj template with nuget packages, nuget info, code analysis, style cop:
@davideicardi
davideicardi / BsonToJson.cs
Last active April 28, 2024 14:49
BsonDocument to Json string
// This method convert a json to a valid string json
// It should handle all mongodb data types correctly (Date, ObjectId, ...) thanks to the
// Newtonsoft.Json.Bson.BsonReader serializer
public string ToJson(BsonDocument bson)
{
using (var stream = new MemoryStream())
{
using (var writer = new BsonBinaryWriter(stream))
{