Skip to content

Instantly share code, notes, and snippets.

View gfreivasc's full-sized avatar

Gabriel Freitas Vasconcelos gfreivasc

View GitHub Profile
@gfreivasc
gfreivasc / rpn.clj
Last active February 27, 2020 19:37
(ns rpn
(:require [clojure.edn :as edn]))
(deftype Pair [f s])
(defn push' [top value]
(Pair. top value))
(defn empty'? [stack]
(= stack nil))
@gfreivasc
gfreivasc / rpn.c
Last active February 24, 2020 18:13
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/// --- STACK DEFINITION ---
typedef struct node_ {
int value;
struct node_* last;
} stack_node_t;
package com.gabrielfv.sandbox.rpn;
import java.util.Scanner;
import java.util.Stack;
/**
* Calculadora RPN interativa.
*
* RPN = Reverse Polish Notation, ou Notação Polonesa Inversa.
* (https://pt.wikipedia.org/wiki/Nota%C3%A7%C3%A3o_polonesa_inversa)
package com.gabrielfv.sandbox.triangle;
import java.util.Scanner;
public class Triangle {
/**
* Este programa deve "printar" na tela três tipos de triângulos
* cujo tamanho é definido pela entrada do usuário. Os tipos de
* triângulo são:
@gfreivasc
gfreivasc / DaggerInjectedMVPExample.kt
Last active October 9, 2019 15:33
This is an example of how to achieve MVP with injection through dagger (this version without dagger android)
package com.gabrielfv.sandbox6
import android.app.Activity
import android.app.Application
import android.os.Bundle
import android.view.View
import android.widget.Toast
import dagger.*
import javax.inject.Inject
class MainActivity : ComponentActivity(R.layout.activity_main) {
private lateinit var viewModel: MainViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
viewModel = provideViewModel(MainViewModel::class.java)
textView.text = "${viewModel.count}"
class MainActivity : ComponentActivity(R.layout.activity_main) {
private lateinit var viewModel: MainViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
viewModel = ViewModelProvider(viewModelStore, ViewModelProvider.NewInstanceFactory())
.get(MainViewModel::class.java)
public static ViewModelProvider of(@NonNull FragmentActivity activity,
@Nullable Factory factory) {
Application application = checkApplication(activity);
if (factory == null) {
factory = ViewModelProvider.AndroidViewModelFactory.getInstance(application);
}
return new ViewModelProvider(activity.getViewModelStore(), factory);
}
class MainActivity : ComponentActivity(R.layout.activity_main) {
private val viewModel = GenericProvider.provide { MainViewModel() }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
textView.text = "${viewModel.count}"
button.setOnClickListener {
viewModel.inc()
class MainActivity : ComponentActivity(R.layout.activity_main) {
private var count: Int = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
savedInstanceState?.let { state ->
count = state.getInt("COUNT", 0)
}