Skip to content

Instantly share code, notes, and snippets.

View ajsaraujo's full-sized avatar
👋

Allan Juan ajsaraujo

👋
View GitHub Profile
@ajsaraujo
ajsaraujo / normalize.py
Created June 18, 2020 14:51
Script to min-max normalize a dataset in Python
import sys
def read_file(file_path):
dataset = []
with open(file_path, "r") as file:
for line in file:
str_values = line.split()
row = [ float(value) for value in str_values if value not in [" ", "\n"] ]
dataset.append(row)
@ajsaraujo
ajsaraujo / moneyMask.java
Created September 4, 2020 01:32
Máscara de Dinheiro em Java
textField.textProperty().addListener((observable, oldValue, newValue) -> {
String numbersOnly = newValue.replace(",", "");
if (numbersOnly.matches("\\d+")) {
int valueInCents = Integer.parseInt(numbersOnly);
StringBuilder builder = new StringBuilder();
if (valueInCents >= 100) {
int integerPart = valueInCents / 100;
@ajsaraujo
ajsaraujo / manha-heroku.md
Last active October 22, 2020 10:24
Manhas do Heroku

Manhas do Heroku

Esse Gist tem a intenção de servir como material para rápida consulta sobre como fazer alguma coisa no Heroku.

Pré-requisitos

  • Git
  • Conta no Heroku
  • Heroku CLI

O Heroku vai tentar identificar qual é a tecnologia que você está usando, e com isso executar as rotinas para instalar as dependências e tudo mais que for necessário quando você der push. No entanto, você ainda precisa dizer a ele como iniciar a sua aplicação. Para isso, criamos um arquivo chamado Procfile na raiz do projeto. Para iniciar uma aplicação Express, por exemplo, bastou incluir a seguinte linha no Procfile:

@ajsaraujo
ajsaraujo / profile.ps1
Last active October 24, 2022 19:13
My powershell profile
# Configuração oh-my-posh
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\1_shell.omp.json" | Invoke-Expression
$env:POSH_GIT_ENABLED = $true
# Configuração Git
Import-Module posh-git # autocomplete
function push { git push origin HEAD } # alias de push
# Alias de open
New-Alias open ii
@ajsaraujo
ajsaraujo / fix-jest-config.js
Created March 15, 2022 11:54
Fix jest config Nx v13
const path = require('path');
const fs = require('fs');
const { promisify, inspect } = require('util');
async function getAllJestConfigJsFilePaths(directory) {
const readDir = promisify(fs.readdir);
const stat = promisify(fs.stat);
const files = await readDir(directory);
@ajsaraujo
ajsaraujo / only-numbers.directive.ts
Last active June 30, 2022 12:37
"Only numbers" directive for Angular
import { Directive, ElementRef, HostListener } from '@angular/core';
@Directive({
selector: '[appOnlyNumbers]',
})
export class OnlyNumbersDirective {
constructor(private element: ElementRef) {}
/**
* Stops the user from typing non-numerical
@ajsaraujo
ajsaraujo / format-phone-number.spec.ts
Created August 26, 2022 12:30
Formatar número de telefone
import { formatPhoneNumber } from './format-phone-number';
describe('formatPhoneNumber', () => {
it('deve formatar como XXXX-XXXX se tiver 8 dígitos', () => {
expect(formatPhoneNumber('12345678')).toEqual('1234-5678');
});
it('deve formatar como X XXXX-XXXX se tiver 9 dígitos', () => {
expect(formatPhoneNumber('912345678')).toEqual('9 1234-5678');
});
@ajsaraujo
ajsaraujo / delete-git-branches.ps1
Created September 9, 2022 12:27
Deleting old git branches
# Delete old local branches
git for-each-ref --format '%(refname:short)' refs/heads | ForEach-Object {git branch $_ -d}
# Remove references to old remote branches
git remote prune origin
@ajsaraujo
ajsaraujo / sum.ts
Last active November 6, 2022 11:13
Sum an array of numbers or objects
type KeysMatchingType<T, U> = NonNullable<{
[K in keyof T]: [U] extends [T[K]] ? T[K] extends U ? K : never : never;
}[keyof T]>;
function sum(values: number[]): number;
function sum<T>(values: T[], prop: KeysMatchingType<T, number>): number;
function sum<T>(values: T[], prop?: KeysMatchingType<T, number>): number {
if (values.length === 0) {
return 0;
}
@ajsaraujo
ajsaraujo / preferences.service.ts
Created October 26, 2022 12:41
Preferences Service
import { Injectable } from '@angular/core';
import { LocalStorage } from '../storage/local.storage';
interface Preferences {
myPreference: string;
}
@Injectable({ providedIn: 'root' })
export class PreferencesService {
preferences: Preferences;