Skip to content

Instantly share code, notes, and snippets.

View pferreirafabricio's full-sized avatar
🔥

Fabrício Pinto Ferreira pferreirafabricio

🔥
View GitHub Profile
@pferreirafabricio
pferreirafabricio / GetStringBetweenByIndex.ps1
Last active November 3, 2022 14:55
Basic script to get a string between two indexes with PowerShell
$originalString = "Hello world"
$firstIndex = $originalString.IndexOf('H')
$lastIndex = $originalString.IndexOf('o')
$startIndex = $firstIndex + 1
$length = ($lastIndex - $firstIndex) - 1;
$finalString = $originalString.Substring($startIndex, $length)
@pferreirafabricio
pferreirafabricio / ConvertGitLogToJson.ps1
Created October 26, 2022 20:33
Powershell script to convert git logs in JSON
# Credits: https://stackoverflow.com/a/49515414/12542704
$header = @("commit", "tree", "parent", "refs", "subject", "body", "author", "commiter")
[string] $gitLogs = (git --no-pager log -n 10 --no-merges --pretty=format:'%H|%T|%P|%D|%s|%b|%an|%cn;')
$replacedArray = $gitLogs.Replace("; ", ';') -split ";", 0, "multiline";
$handledLogs = foreach ($commit in $replacedArray) {
$prop = $commit -split "\|"
$hash = [ordered]@{}
@pferreirafabricio
pferreirafabricio / canvasUtilities.js
Last active July 8, 2022 13:33
Class with some utilities to work on a canvas context
/**
* Class with some utilities to work on a canvas context
* @author Fabrício Pinto Ferreira
*/
export class CanvasUtility {
/**
* @param {CanvasRenderingContext2D} newContext
*/
constructor(newCanvasContext) {
/** @type {CanvasRenderingContext2D} */
@pferreirafabricio
pferreirafabricio / global.json
Created June 22, 2022 13:58
Example of global.json file for configuring a dotnet core application to use the the latest dotnet core SDK version 3.1
{
"sdk": {
"version": "3.1.0",
"rollForward": "latestFeature"
}
}
@pferreirafabricio
pferreirafabricio / .gitattributes
Last active June 4, 2022 20:30
Example o a .gitattributes file for correct identification of languages on GitHub
# Auto detect text files and perform LF normalization
* text=auto
*.cs linguist-language=csharp
*.csproj linguist-language=csharp
*.sln linguist-language=csharp
*.md linguist-detectable=true
*.md linguist-documentation=false
# And ignore those repositories considering them as documentation
@pferreirafabricio
pferreirafabricio / Speak-Powershell.ps1
Last active June 30, 2021 20:23
Making PowerShell talk
<#
Usage example:
./Speak-Powershell.ps1 "Hy PowerShell"
#>
Add-Type -AssemblyName System.speech
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
$textToSpeak = switch ( [String]::IsNullOrEmpty($args[0]) ) {
$true { "Hello World" }
$false { $args[0] }
@pferreirafabricio
pferreirafabricio / Request.cs
Last active March 18, 2024 08:46
A simple C# script for making HTTP Request on Unity
using System;
using System.Collections;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
namespace Project.Base
{
public static class Request
@pferreirafabricio
pferreirafabricio / convertImagesToBase64.ps1
Last active March 30, 2024 16:03
Script to loop through a folder with images and convert all of them to a Base64 string
<#
Usage on Linux:
pwsh ./convertImagesToBase64.ps1 /home/user/folder/images
Usage on Windows:
./convertImagesToBase64.ps1 C:/Path/To/Imagens
#>
$folderPath = $args[0]
@pferreirafabricio
pferreirafabricio / png-to-base64.ps1
Last active March 30, 2024 15:44
🖼 Convert an image to a Base64 string with PowerShell
<#
OBS:
The AsByteStream parameter was introduced in Windows PowerShell 6.0
If your PowerShell version (run `(Get-Host).Version` to find out) is lower than 6 then use the version for Powershell 5.1:
#>
$pathToImage = "/home/user/development/image.png"
# For Powershell 5.1
[String]$base64 = [convert]::ToBase64String((Get-Content $pathToImage -Raw -Encoding Byte))
@pferreirafabricio
pferreirafabricio / logger.js
Last active June 22, 2021 18:23
A simple logger script made with Winston package for NodeJS
const { createLogger, format, transports } = require('winston');
const { combine, timestamp, label, printf } = format;
const config = require('./config');
const isLogsEnabled = config.enableLogs;
/**
* Class to log in text files
*/
class Logger {