Skip to content

Instantly share code, notes, and snippets.

Christian Vasquez chrisvasqm

Block or report user

Report or block chrisvasqm

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View MathV2.kt
class MathV2 {
companion object {
fun calculate(first: Int, second: Int, callback: (a: Int, b: Int) -> Int) =
callback(first, second)
}
}
View MathV1.kt
class MathV1 {
companion object {
fun add(first: Int, second: Int) = first + second
fun multiply(multiplicand: Int, multiplier: Int) = multiplicand * multiplier
}
@chrisvasqm
chrisvasqm / orientation_change_layout.xml
Created May 23, 2018
Sample layout to demonstrate how to preserve state after a device has been rotated.
View orientation_change_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textMessage"
@chrisvasqm
chrisvasqm / Math.java
Last active Jun 18, 2019
Reimplementation of the Math class to be used as an example for Unit Testing.
View Math.java
public final class Math {
public static int add(int first, int second) {
return firstNumber + secondNumber;
}
public static int multiply(int multiplicand, int multiplier) {
return multiplicand * multiplier;
}
@chrisvasqm
chrisvasqm / fizzbuzz.js
Last active Mar 20, 2018
Example of the classic interview exercise known as the FizzBuzz. Which consists on counting all the numbers from 1 to 100, and replace any numbers that are divisible by 3 with the word "Fizz", if it's divisible by 5 replace it with "Buzz", and if it is divisible by both 3 and 5 replace it with "FizzBuzz".
View fizzbuzz.js
for (let i = 1; i < 100; i++) {
if (isFizzBuzz(i))
console.log('FizzBuzz');
else if (isFizz(i))
console.log('Fizz');
else if (isBuzz(i))
console.log('Buzz');
else
console.log(i);
}
@chrisvasqm
chrisvasqm / functional-programming.js
Created Mar 19, 2018
This is an example of a function that takes another function and then invokes it.
View functional-programming.js
function executeTheOTherFunction(theOtherFunction) {
theOtherFunction();
}
executeTheOTherFunction(() => console.log('suh dude')); // outputs: suh dude
@chrisvasqm
chrisvasqm / NumberoALetra.java
Created Mar 11, 2018
Convierte numeros enteros y decimales a palabras y las imprime en consola.
View NumberoALetra.java
package com.example;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class NumeroALetra {
private static int flag = 0;
private static String num;
private static String num_letra;
@chrisvasqm
chrisvasqm / Main.kt
Last active Mar 20, 2018
The goal is to design and create the structure of a ReportCard Java Class which would allow a school to store a student’s grades for a particular year.
View Main.kt
fun main(args: Array<String>) {
val student = ReportCard("Chris")
student.apply {
biologyGrade = "A"
historyGrade = "B"
mathGrade = "B"
}
println(student) // ReportCard(studentName=Chris, historyGrade=B, mathGrade=B, biologyGrade=A)
}
@chrisvasqm
chrisvasqm / sum-all-argument.js
Created Jan 1, 2018
Example of how to create a function that can sum any amount of numbers you pass in by using the "arguments" object that every non-arrow function has by default in JavaScript
View sum-all-argument.js
console.log("Result: " + sum(2, 2, 2, 2, 2, 2))
function sum() {
let result = 0
const args = Array.from(arguments)
args.forEach(element => {
result += element
});
You can’t perform that action at this time.