Skip to content

Instantly share code, notes, and snippets.

View pedrovasconcellos's full-sized avatar

Pedro Vasconcellos pedrovasconcellos

View GitHub Profile
@pedrovasconcellos
pedrovasconcellos / ObjectExtension.cs
Created December 31, 2020 02:59
ObjectExtension with CopyObject and CopyPropertiesTo
using System.IO;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Binary;
using System.Linq;
namespace Vasconcellos.Extensions
{
public static class ObjectExtension
{
/// <summary>
@pedrovasconcellos
pedrovasconcellos / MongoDBService.cs
Last active March 28, 2023 04:22
MongoDB Service with method Insert
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Serializers;
using MongoDB.Driver;
namespace VS.Services
{
public class MongoDBService
{
@pedrovasconcellos
pedrovasconcellos / RestSharpWithPollyExample.cs
Last active May 16, 2025 12:30
Example using restsharp with polly
using Polly;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Net;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Threading.Tasks;
namespace RestSharpWithPolly
@pedrovasconcellos
pedrovasconcellos / ResponseModel.cs
Last active January 23, 2020 04:46
Response Model
using System;
using System.Collections.Generic;
using System.Linq;
/// <summary>
/// Response Model
/// </summary>
public class ResponseModel<T>
{
/// <summary>
@pedrovasconcellos
pedrovasconcellos / RecursionExamples.cs
Last active February 21, 2020 03:41
Recursion Examples
void Main()
{
var x = 19;
var y = 7;
Console.WriteLine($"Factorial of x={x}, result={Factorial(x)}.\n");
Console.WriteLine($"Multiplication of x*y={x}*{y}={Multiplication(x, y)}.\n");
Console.WriteLine($"Binary of x={x}, result={DecimalToBinary(x)}.\n");
}
public long Factorial(long x)
@pedrovasconcellos
pedrovasconcellos / http-post.js
Last active December 26, 2020 01:32
Http POST in Ajax using pure Javascript
var url = 'https://udemy.com.br/OpenClass';
var obj = { schoolID: 77 , classId: 3};
var callBackParameter = {};
var callBackFunction = function(ajax, callBackParameter) {
let objResponse = JSON.parse(ajax.responseText);
console.log('Response Object', objResponse);
};
var callBackErrorParamater = {};
@pedrovasconcellos
pedrovasconcellos / http-get.js
Last active November 1, 2019 18:02
Http GET in Ajax using pure Javascript
var schoolID = 77;
var classId = 3;
var url = 'https://udemy.com.br/Cursos?schoolID='+schoolID+'&classId='+classId;
var callBackParameter = {};
var callBackFunction = function(callBackParameter, ajax){
let objResponse = JSON.parse(ajax.responseText);
console.log('Response Object', objResponse);
};
@pedrovasconcellos
pedrovasconcellos / httpsredirect.php
Created September 25, 2019 03:49
HTTPS Redirect
<?php
if(empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off"){
$redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $redirect);
exit();
}
?>
@pedrovasconcellos
pedrovasconcellos / DropDatabaseWithCloseAllConnections.sql
Created September 4, 2019 04:15
SQL to close all connections and drop database
--SQL to close all connections and drop database
USE [master];
DECLARE @DatabaseName VARCHAR(MAX) = 'MyDatabaseName' --to change
DECLARE @kill VARCHAR(8000) = '';
SELECT @kill = @kill + 'kill ' + CONVERT(VARCHAR(5), session_id) + ';'
FROM sys.dm_exec_sessions
WHERE database_id = db_id(@DatabaseName)
EXEC(@kill);
@pedrovasconcellos
pedrovasconcellos / CarWithPaginationController.cs
Last active March 27, 2019 12:21
Example: Car Controller with pagination in C# ASP.NET Core
using AutoMapper;
using Vasconcellos.WebAPI.Entity;
using Vasconcellos.WebAPI.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;