Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / forge-array-behavior.html
Last active November 10, 2018 22:22
Polymer web components sample for Deltatre's Forge
<script>
(function() {
function InvalidEntityError(message) {
this.message = message;
var last_part = new Error().stack.match(/[^\s]+$/);
this.stack = `${this.name} at ${last_part}`;
}
Object.setPrototypeOf(InvalidEntityError, Error);
InvalidEntityError.prototype = Object.create(Error.prototype);
InvalidEntityError.prototype.name = "InvalidEntityError";
@davideicardi
davideicardi / mongo.aspx
Last active September 1, 2016 15:21
MongoDb diagnostic page
<!-- directives -->
<% @Page Language="C#" %>
<%@ Import namespace="MongoDB.Bson.Serialization" %>
<%@ Import namespace="MongoDB.Bson.Serialization.Conventions" %>
<%@ Import namespace="MongoDB.Driver" %>
<%@ Import namespace="MongoDB.Bson" %>
<!-- call example:
https://server/_diagnostics/mongo.aspx?connectionString=mongodb%3A%2F%2Fserver%3A27017%2Ftest&collectionName=logs
@davideicardi
davideicardi / dns.aspx
Last active September 1, 2016 15:22
Host name resolution diagnostic page
<!-- directives -->
<% @Page Language="C#" %>
<%@ Import namespace="System.Net" %>
<!-- call example:
https://server/_diagnostics/dns.aspx?hostName=microsoft.com
-->
<script runat="server">
private string HostName2IP(string hostname)
{