Skip to content

Instantly share code, notes, and snippets.

View pedrovasconcellos's full-sized avatar

Pedro Vasconcellos pedrovasconcellos

View GitHub Profile
@pedrovasconcellos
pedrovasconcellos / IRR.rs
Created April 14, 2023 06:44
Internal Rate of Return
fn main() {
let initial_investment = -1000.0;
let cash_receipts = vec![250.0, 350.0, 450.0, 550.0];
let cash_flows = vec![initial_investment,
cash_receipts[0], cash_receipts[1], cash_receipts[2], cash_receipts[3]];
let rate = irr(&cash_flows);
println!("IRR: {:.2}%", rate * 100.0);
}
@pedrovasconcellos
pedrovasconcellos / connect-in-vm-linux.sh
Last active April 12, 2023 19:29
Use SSH with VM Linux Ubuntu
# Transfer folder with files to vm
scp -r -i certificate.pem home/userlocal/diretory uservm:ip_vm_host home/uservm/directory
# Connect to vm
ssh -i certificate.pem uservm:ip_vm_host
# INSTALL .NET 7
# 1) Add package
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
@pedrovasconcellos
pedrovasconcellos / get-duplicity-zipecode.py
Last active April 10, 2023 17:34
ZipeCode Scripts Python
import pymongo
print("start program --")
client = pymongo.MongoClient("mongodb://localhost/DataBaseName?ssl=true&authSource=admin&maxIdleTimeMS=120000&retrywrites=false"
, socketTimeoutMS=3600000)
db = client["DataBaseName"]
collection = db["ZipeCodeNumber"]
ceps = {}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Extensions.Logging;
namespace Vasconcellos.Log
@pedrovasconcellos
pedrovasconcellos / EnumExtension.cs
Last active April 12, 2023 19:04
EnumExtension with GetDescription
using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
public static class EnumExtension
{
public static string GetDescription<TEnum>(this TEnum value) where TEnum : Enum
{
FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
@pedrovasconcellos
pedrovasconcellos / base64.js
Created July 19, 2021 18:08
Javascript Base64 UTF8 encoding and decoding
function b64EncodeUnicode(str) {
// first we use encodeURIComponent to get percent-encoded UTF-8,
// then we convert the percent encodings into raw bytes which
// can be fed into btoa.
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
function toSolidBytes(match, p1) {
return String.fromCharCode('0x' + p1);
}));
}
private static T DeepCopy<T>(T other)
{
using (MemoryStream ms = new MemoryStream())
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Context = new StreamingContext(StreamingContextStates.Clone);
formatter.Serialize(ms, other);
ms.Position = 0;
return (T)formatter.Deserialize(ms);
@pedrovasconcellos
pedrovasconcellos / FollowInstagramUsers.js
Last active February 9, 2021 20:04
Follow Instagram Users
function timer(ms) { return new Promise(res => setTimeout(res, ms)); }
async function FollowInstagramUsers(amount) {
for (var i = 0; i <= amount; i++) {
document.getElementsByClassName("sqdOP L3NKy y3zKF ")[i].click();
console.log(i);
await timer(5000);
}
}
function wait(ms) {
@pedrovasconcellos
pedrovasconcellos / getInstagramsIFollow.js
Last active February 9, 2021 16:16
Get Instagrams I Follow
function download(content, fileName, contentType) {
var a = document.createElement("a");
var file = new Blob([content], {type: contentType});
a.href = URL.createObjectURL(file);
a.download = fileName;
a.click();
}
function getInstagramsIFollow(amount) {
let instagrams = '';
@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>