Skip to content

Instantly share code, notes, and snippets.

View antdimot's full-sized avatar
🎯
on target

Antonio Di Motta antdimot

🎯
on target
View GitHub Profile
@antdimot
antdimot / Repository.cs
Last active July 7, 2022 23:59
Example of mongodb repository in C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
@antdimot
antdimot / Blockchain.cs
Last active March 28, 2018 15:26
Basic Blockchain .Net implementation
using System;
using System.Security.Cryptography;
using System.Text;
namespace Blockchain
{
public class Block
{
private DateTime _timestamp;
public int Index { get; private set; }
@antdimot
antdimot / FlightManager.cs
Last active April 4, 2018 10:32
Flightstats API wrapper
public class FlightManager
{
string _protocol = "rest";
string _format = "json";
string _flightstatusBaseApiUrl;
string _flightscheduleBaseApiUrl;
public string AppId { get; private set; }
public string AppKey { get; private set; }
@antdimot
antdimot / HashUtility.cs
Last active October 10, 2018 15:32
Simple HashUtility useful for password encryption based on PBKDF2 algorithm
// https://en.wikipedia.org/wiki/PBKDF2
using Microsoft.AspNetCore.Cryptography.KeyDerivation;
using System;
using System.Security.Cryptography;
namespace Utils
{
public class HashUtility
{
@antdimot
antdimot / regexCheatsheet.js
Created January 14, 2019 16:10 — forked from sarthology/regexCheatsheet.js
A regex cheatsheet 👩🏻‍💻 (by Catherine)
let regex;
/* matching a specific string */
regex = /hello/; // looks for the string between the forward slashes (case-sensitive)... matches "hello", "hello123", "123hello123", "123hello"; doesn't match for "hell0", "Hello"
regex = /hello/i; // looks for the string between the forward slashes (case-insensitive)... matches "hello", "HelLo", "123HelLO"
regex = /hello/g; // looks for multiple occurrences of string between the forward slashes...
/* wildcards */
regex = /h.llo/; // the "." matches any one character other than a new line character... matches "hello", "hallo" but not "h\nllo"
regex = /h.*llo/; // the "*" matches any character(s) zero or more times... matches "hello", "heeeeeello", "hllo", "hwarwareallo"
@antdimot
antdimot / Office365SendEmailExample.cs
Created March 18, 2019 15:54
Email from office 365 account
class Program
{
static void Main( string[] args )
{
var to = new MailAddress( <to email here> );
var from = new MailAddress( <from email here> );
var oMail = new MailMessage( from, to )
{
Subject = "test email from office 365 account",
@antdimot
antdimot / CheckPCInfo.ps1
Created March 27, 2019 17:00
Check CPU, Memory and OS info
if($args.Count -eq 1)
{
$pcname = $args[0]
$meminfo = Get-WmiObject CIM_PhysicalMemory -ComputerName $pcname | Measure-Object -Property capacity -sum | % {[math]::round(($_.sum / 1GB),2)}
$CPUInfo = (Get-WmiObject Win32_Processor -ComputerName $pcname).Name
$OSInfo = (Get-WmiObject Win32_OperatingSystem -ComputerName $pcname).Version
Write-Output "CPU -> ""$CPUInfo"""
Write-Output "Memory -> ""$meminfo"""
Write-Output "OS -> ""$OSInfo"""
@antdimot
antdimot / dotnetmemorytest.cs
Last active June 13, 2019 12:37
.net memory test
namespace ConsoleApp1
{
// 1 gigabyte (GB) = 1073741824 bytes
// 2 gigabyte (GB) = 2147483648 bytes
class Program
{
static void Main( string[] args )
{
//int size = 130000000; // --> 2080000000 bytes
@antdimot
antdimot / json_sum.cs
Last active August 21, 2019 19:56
Example of sum for json array
using System;
using System.IO;
using Newtonsoft.Json;
namespace ConsoleApp1
{
/// <summary>
/// Example of sum for json array
/// </summary>
class Program
@antdimot
antdimot / UnitOfWork.cs
Last active August 21, 2019 20:07
Example of UnitOfWork
/* UnitOfWork using example
using( var context = new UnitOfWork( "db connection string here" ) )
{
var customer = await context.Use<ICustomerRepository>()
.GetBySerial( serial );
} */