Skip to content

Instantly share code, notes, and snippets.

View gabrielbmoro's full-sized avatar
👋
Hii

Gabriel Bronzatti Moro gabrielbmoro

👋
Hii
View GitHub Profile
@gabrielbmoro
gabrielbmoro / CreateNewHistoricEntryController.ts
Created September 6, 2022 21:01
An API Project - Gists Part 5
import { Request, Response } from "express";
import { container } from "tsyringe";
import { CreateNewHistoricEntryUseCase } from "../domain/useCases/CreateNewHistoricEntryUseCase";
class CreateNewHistoricEntryController {
async handle(request: Request, response: Response): Promise<Response> {
const { beds, activity, crop, variety, resultIndicator, input } = request.body;
const useCase = container.resolve(CreateNewHistoricEntryUseCase);
const result = await useCase.execute({
@gabrielbmoro
gabrielbmoro / CreateNewHistoricEntryUseCase.ts
Created September 6, 2022 21:00
An API Project - Gists Part 4
@injectable()
class CreateNewHistoricEntryUseCase {
constructor(
@inject("ISisOrgRepository")
private sisOrgRepository: ISisOrgRepository
) {
}
async execute(request: IRequest): Promise<IHistoricEntry[]> {
const historicEntries: IHistoricEntry[] = [];
@gabrielbmoro
gabrielbmoro / server.ts
Created September 6, 2022 20:59
An API Project - Gists Part 3
import { container } from "tsyringe";
...
function setup() {
container.registerSingleton<ISisOrgRepository>(
"ISisOrgRepository",
FirestoreDataSource
);
}
...
app.listen(port, () => {
@gabrielbmoro
gabrielbmoro / historic.routes.ts
Created September 6, 2022 20:53
An API Project - Gists Part 2
import { Router } from "express";
import { CreateNewHistoricEntryController } from "../../controllers/CreateNewHistoricEntryController";
const historyRoutes = Router();
const createNewHistoricEntryController = new CreateNewHistoricEntryController();
historyRoutes.post("/historic", createNewHistoricEntryController.handle);
export { historyRoutes };
@gabrielbmoro
gabrielbmoro / app.ts
Created September 6, 2022 20:51
An API Project - Gists Part 1
import express, { Request, Response, NextFunction } from "express";
require('express-async-errors');
import { historyRoutes } from "./routes/history.routes";
const app = express();
app.use(express.json());
app.use("/history", historyRoutes);
@gabrielbmoro
gabrielbmoro / Composable.kt
Created July 12, 2022 22:13
Typing a Text
ComposableFunction() {
DisposableEffect(Unit) {
typingTimer = TypingTimer().apply {
setup(
baseMessage = welcomingMessage,
finishCallback = { showFooter = true },
currentMessageUpdateCallback = {
// here if you are using viewbinding it could be textView.text = currentMessage
currentMessage = it
}
@gabrielbmoro
gabrielbmoro / build.gradle
Created May 29, 2022 20:27
Exposing Gradle properties
android {
compileSdk 31
defaultConfig {
applicationId "com.matematicasimples"
minSdk 23
targetSdk 30
versionCode getVersionCode()
versionName getVersionName()
@gabrielbmoro
gabrielbmoro / build.gradle
Created May 29, 2022 20:25
Get Keystore properties from local environment or Bitrise
private static Properties loadProperties(Project rootProject) {
def keystoreProperties = new Properties()
// load your keystore.properties file into e keystoreProperties object.
try {
def keystorePropertiesFile = rootProject.file("keystore.properties")
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
} catch(FileNotFoundException exception){
println(exception.message)
println("-------")
@gabrielbmoro
gabrielbmoro / build.gradle
Last active May 29, 2022 20:01
Getting version name, and version code from env variables
private static String getVersionName() {
String versionName = "$System.env.ANDROID_VERSION_NAME"
if (versionName == null || versionName.isEmpty()) {
int versionCode = getVersionCode()
return "1.0.$versionCode"
} else {
return versionName
}
}
@gabrielbmoro
gabrielbmoro / MainNavGraph.kt
Created January 21, 2022 14:03
Navigation graph - Navigation Compose
composable(
"${ScreenRoutes.QUIZ_ROUTE}/{${ScreenRoutes.QUIZ_ARGUMENT_KEY}}",
arguments = listOf(
navArgument(ScreenRoutes.QUIZ_ARGUMENT_KEY) {
type = NavQuizType()
}
)
) {
val quiz = it.arguments?.getParcelable<Quiz>(ScreenRoutes.QUIZ_ARGUMENT_KEY)
?: throw IllegalStateException("It is not possible access the quiz object")