Skip to content

Instantly share code, notes, and snippets.

View supix's full-sized avatar

supix supix

View GitHub Profile
@supix
supix / create_replica_set.bat
Last active December 9, 2017 14:34
These two scripts allow to configure a MongoDB replica set in a msdos console
#mkdir -p /data/rs1 /data/rs2 /data/rs3
"c:\Program Files\mongodb\Server\3.2\bin\mongod" --replSet replica_name --dbpath "c:\data\rs1" --port 27017 --oplogSize 64 --smallfiles
"c:\Program Files\mongodb\Server\3.2\bin\mongod" --replSet replica_name --dbpath "c:\data\rs2" --port 27018 --oplogSize 64 --smallfiles
"c:\Program Files\mongodb\Server\3.2\bin\mongod" --replSet replica_name --dbpath "c:\data\rs3" --port 27019 --oplogSize 64 --smallfiles
@supix
supix / CheckCodiceFiscale.cs
Last active October 19, 2022 06:38
Validatore codice fiscale in linguaggio C#
/// <summary>
/// Computes checksum validity on an Italian Fiscal Code
/// </summary>
/// <param name="fiscalCode">The Fiscal Code to be checked</param>
/// <returns>Checksum is valid</returns>
/// <remarks>Checksum routines are at https://en.wikipedia.org/wiki/Italian_fiscal_code_card</remarks>
/// <remarks>Used regular expression is at http://blog.marketto.it/2016/01/regex-validazione-codice-fiscale-con-omocodia/</remarks>
private bool IsFiscalCodeOk(string fiscalCode)
{
const string regex = @"/^(?:[B-DF-HJ-NP-TV-Z](?:[AEIOU]{2}|[AEIOU]X)|[AEIOU]{2}X|[B-DF-HJ-NP-TV-Z]{2}[A-Z]){2}[\dLMNP-V]{2}(?:[A-EHLMPR-T](?:[04LQ][1-9MNP-V]|[1256LMRS][\dLMNP-V])|[DHPS][37PT][0L]|[ACELMRT][37PT][01LM])(?:[A-MZ][1-9MNP-V][\dLMNP-V]{2}|[A-M][0L](?:[\dLMNP-V][1-9MNP-V]|[1-9MNP-V][0L]))[A-Z]$/i";
@supix
supix / service.ts
Last active June 26, 2017 20:12
Consuming http service in Angular4
//see https://www.sitepoint.com/angular-rxjs-create-api-service-rest-backend/
import { Injectable } from '@angular/core';
import { environment } from 'environments/environment';
import { Http, Response } from '@angular/http';
import { Todo } from './todo';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';

Gli smartphone hanno distrutto una generazione?

Un giorno, la scorsa estate, ho chiamato Athena, una ragazza di 13 anni che vive a Houston, in Texas. Mi rispose dal suo iPhone, ne ha uno da quando aveva 11 anni, e sembrava si fosse appena svegliata. Chiacchierammo delle sue canzoni e delle sue trasmissioni preferite e le chiesi cosa le piaceva fare con i suoi amici. "Andiamo al centro commerciale", disse. "Ti ci lasciano i tuo genitori?", le chiesi ricordando i tempi delle mie scuole medie, nel 1980, quando mi divertivo a trascorrere ore di shopping libera dai miei genitori. "No, ci vado con la mia famiglia", rispose. "Andiamo con mia mamma e mio fratello e cammino poco dietro di loro. Devo solo dire a mia mamma dove vado. E mi devo far vedere ogni ora, oppure ogni mezz'ora".

Queste puntate al centro commerciale sono abbastanza rare, circa una al mese. Più spesso Athena e i suoi amici trascorrono il tempo insieme al cellulare, senza il controllo dei genitori. Diversamente dai teenager della mia generazion

@supix
supix / Web.Config
Last active June 14, 2018 20:05
Portable way to instantiate a log4net logger throughout all classes
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="TraceAppender" type="log4net.Appender.TraceAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
@supix
supix / pg_create_db_users
Last active August 1, 2019 05:26
Create new postgres database with owner and app user
psql -U postgres
create database myNewDB;
create user myNewDB_web;
create user myNewDB_owner;
ALTER USER myNewDB_web WITH PASSWORD 'pwd';
ALTER USER myNewDB_owner WITH PASSWORD 'pwd';
psql -U postgres -d myNewDB
@supix
supix / create_mongodb_users
Last active February 18, 2019 21:37
Create read-only, read-write and owner-user users on mongodb database
use myDbName
// drop users
db.dropUser("ro_user");
db.dropUser("rw_user");
db.dropUser("owner_user");
// read-only user
db.createUser({
user: "ro_user",
@supix
supix / index.html
Last active May 5, 2018 20:32
Angular template for a website with top nav menu and fixed width
<body>
<div class="topnav">
<a class="active" href="#home">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
<a href="#about">About</a>
</div>
<div class="content">
<app-root></app-root>
@supix
supix / DbContext.cs
Last active December 15, 2022 21:22
Sample C# MongoDb setup
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Conventions;
using MongoDB.Bson.Serialization.IdGenerators;
using MongoDB.Bson.Serialization.Serializers;
using MongoDB.Driver;
namespace Persistence.MongoDB
{
internal class DbContext
@supix
supix / Bayes.md
Last active June 19, 2018 07:11
Applying Bayes Theorem and verifying if through frequentist probability approach

Context

We are in a university campus. There are two faculties: math and business administration. 10% of student are enrolled in math (then, 90% of students are enrolled in business administration). Within math faculty, 75% students are shy. Within business administration, 15% students are shy.

Problem

I see a student, and he is clearly shy. What's the probability that he is enrolled in math faculty?

Theoretical solution through Bayes Theorem