Skip to content

Instantly share code, notes, and snippets.

View aldajo92's full-sized avatar

Alejandro Gómez aldajo92

View GitHub Profile
package com.example.aldajo92.androidthingsnearby
import android.app.Activity
import android.os.Bundle
import android.util.Log
import com.example.aldajo92.androidthingsnearby.BuildConfig.NEARBY_SERVICE_ID
import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.api.GoogleApiClient
import com.google.android.gms.nearby.Nearby
import com.google.android.gms.nearby.connection.*
.retryWhen(this@CheckoutViewModel::processRetry)
private fun processRetry(error: Observable<Throwable>): Observable<Observable<Long>>? {
return error.filter { isServerTimeOut(it) }
.zipWith(Observable.range(1, 2), BiFunction<Throwable, Int, Observable<Long>> { _, _ ->
hasRetried = true
Observable.timer(2, TimeUnit.SECONDS)
})
}
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
// https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define ESCMIN 150
#define ESCMAX 600
#define SERVOMIN 250
@aldajo92
aldajo92 / my_solution.py
Last active April 23, 2019 20:46
Udacity - Data Structures and Algorithms: Find the smallest positive number in a list.
def smallest_positive(in_list):
# TODO: Define a control structure that finds the smallest positive
# number in in_list and returns the correct smallest number.
smallest = None
missing_positive = True
for val in in_list:
if val > 0 and smallest is not None:
if val < smallest:
@aldajo92
aldajo92 / my_solution.py
Created April 23, 2019 20:45
Udacity - Data Structures and Algorithms: You will need to complete the function when_offered(courses, course). This function accepts a "courses" data structure and a "course" string. The function should return a list of strings representing the semesters when the input course is offered. See the two test cases below for examples of correct resu…
# This exercise uses a data structure that stores Udacity course information.
# The data structure format is:
# { <semester>: { <class>: { <property>: <value>, ... },
# ... },
# ... }
courses = {
'spring2020': { 'cs101': {'name': 'Building a Search Engine',
@aldajo92
aldajo92 / my_solution.py
Created May 17, 2019 04:35
Udacity - Data Structures and Algorithms: Creating a linked list using iteration.
def create_linked_list(input_list):
"""
Function to create a linked list
@param input_list: a list of integers
@return: head node of the linked list
"""
head = None
current_node = None
head_created = False
for value in input_list:
@aldajo92
aldajo92 / main.c
Last active September 23, 2019 14:47
getCharValue in C
#include <stdio.h>
char getCharValue(unsigned char byte) {
char result = 0;
if (byte >= 0 && byte < 10) {
result = 48 + byte;
} else if (byte >= 10 && byte <= 15) {
result = 65 + (byte - 10);
}
return result;
@aldajo92
aldajo92 / ImageViewExtensions.kt
Last active October 7, 2019 05:28
Loads an Image from Url into ImageView, using a extension function in kotlin.
import android.widget.ImageView
import com.squareup.picasso.Picasso
// add dependency
// implementation 'com.squareup.picasso:picasso:2.5.0'
fun ImageView.setImageFromUrl(url: String) {
Picasso.with(this.context).load(url).into(this)
}
@aldajo92
aldajo92 / main.c
Created December 1, 2019 05:50
Array comparison with time complexity O(n)
int main()
{
}
@aldajo92
aldajo92 / main.c
Last active January 30, 2020 20:31
Solución alternativa Parcial I Procesadores Unal Med 2019-02, Facultad de Minas
/******************************************************************************
Referencias:
- Conversor para floats a binarios: https://www.h-schmidt.net/FloatConverter/IEEE754.html
- Conversor de enteros a binarios: http://www.binaryconvert.com/
Escriba una función en Lenguaje C que reciba un vector con 32 números enteros (representando los 32 bits del
formato float) y devuelva un valor entero cuyo significado es el siguiente:
- retornar 1 si es cero
- retornar 2 si es positivo y menor que 1 en magnitud
- retornar 3 si es negativo y menor que 1 en magnitud