Skip to content

Instantly share code, notes, and snippets.

View JonathanLoscalzo's full-sized avatar

Jonathan Loscalzo JonathanLoscalzo

View GitHub Profile
@JonathanLoscalzo
JonathanLoscalzo / Sample.cs
Created March 31, 2018 01:39 — forked from marisks/Sample.cs
Improved Jimmy Bogard's ValueObject<T> which supports inheritance
// Ordinary
public class SimpleDto : ValueObject<SimpleDto>
{
public string Value { get; set; }
}
// With base class
public abstract class BaseDto<T> : ValueObject<T>
{
public string BaseValue { get; set; }

Often referred to as the "swiss army of knife" for TCP/IP networking, [Netcat][1] is an extremely versatile Linux utility that allows you to do anything under the sun using TCP/UDP sockets. It is one of the most favorite tools for system admins when they need to do networking related troubleshooting and experimentation.

In this tutorial, I am sharing a few useful netcat examples, although the sky is the limit when it comes to possible netcat use cases. If you are using netcat regularly, feel free to share your use case.

Note that when you are binding to well-known ports (0-1023) with nc, you need root privilege. Otherwise, run nc as a normal user.

1. Test if a particular TCP port of a remote host is open.

$ nc -vn 192.168.233.208 5000
@JonathanLoscalzo
JonathanLoscalzo / Entity.cs
Last active June 18, 2018 02:02
DDD - Domain Service example
public abstract class BaseEntity
{
public int Id { get; set; }
}
public class ToDoEntity : BaseEntity
{
public int Id { get; set; }
/* some fields and properties*/
using System;
class DateTimeRange : ValueObject<DateTimeRange>
{
public DateTime Start { get; }
public DateTime End { get; }
public DateTimeRange(DateTime start, DateTime end)
{
Start = start;
@JonathanLoscalzo
JonathanLoscalzo / IRepository.cs
Last active May 24, 2018 04:12
IRepository example
public interface IRepository<Entity, Tkey> : IQueryable<Entity> where Entity : IBaseEntity<Tkey>
{
Entity Add(Entity entity);
void Add(IEnumerable<Entity> entities);
Entity FindById(string id);
IList<Entity> Find(Expression<Func<Entity, bool>> match);
IList<Entity> GetAll();
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Collections.Generic;
public static class PredicateBuilder
{
public static Expression<Func<T, bool>> True<T> () { return f => true; }
public static Expression<Func<T, bool>> False<T> () { return f => false; }
public class EfRepository<T> : IRepository<T> where T : BaseEntity
{
private readonly AppDbContext _dbContext;
public EfRepository(AppDbContext dbContext)
{
_dbContext = dbContext;
}
public T GetById(int id)
@JonathanLoscalzo
JonathanLoscalzo / split.sql
Created June 6, 2018 13:46
how to split comma parameters in sql
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[Split]
(
@String NVARCHAR(4000),
@Delimiter NCHAR(1)
)
RETURNS TABLE
@JonathanLoscalzo
JonathanLoscalzo / correctuse-example-2.js
Created June 18, 2018 12:27 — forked from itaditya/correctuse-example-2.js
Snippet for Avoiding the async/await hell medium article
async function orderItems() {
const items = await getCartItems() // async call
const noOfItems = items.length
const promises = []
for(var i = 0; i < noOfItems; i++) {
const orderPromise = sendRequest(items[i]) // async call
promises.push(orderPromise) // sync call
}
await Promise.all(promises) // async call
}
@JonathanLoscalzo
JonathanLoscalzo / ICommandHandler
Created June 22, 2018 14:09
an approach for add aspects (AOP) to C# service
public interface ICommandHandler<TCommand>
{
void Handle(TCommand command);
}