Skip to content

Instantly share code, notes, and snippets.

View sergiocasero's full-sized avatar
😄

Sergio Casero Hernández sergiocasero

😄
View GitHub Profile
createMapCircle: function(latitude, longitude){
var latitudeRadius = this.getRadiusInLatitudeDegrees(this.radius);
var longuitudeRadius = this.getRadiusInLongitudeDegrees(this.radius, latitude);
for (var i = 0; i < 360; i++) {
var angle = i * (3.141516/180);
this.push('points', {
latitude: latitude + latitudeRadius * Math.sin(angle),
longitude: longitude + longuitudeRadius * Math.cos(angle),
});
@sergiocasero
sergiocasero / listingPorts.java
Last active January 28, 2017 20:31
Listing Ports with android things
private void initializeHardware() {
// Create peripheralManagerService and get GPIO list
PeripheralManagerService peripheralManagerService = new PeripheralManagerService();
List<String> portList = peripheralManagerService.getGpioList();
if (!portList.isEmpty()) {
try {
// Initialize GPIOs
initializeGpios(peripheralManagerService, portList, portList.size() < MAX_RELAYS ? portList.size() : MAX_RELAYS);
} catch (IOException e) {
view.showError("An error has ocurred");
@sergiocasero
sergiocasero / relays.java
Last active January 28, 2017 20:45
Models
// Uploading relays
try {
for (Relay relay : relays) {
RelayDto relayDto = new RelayDto(relay.getLabel(), relay.getGpio().getValue());
relayReference.child(relay.getId()).setValue(relayDto);
}
} catch (IOException e) {
e.printStackTrace();
}
private void switchRelay(String key, Boolean value) {
try {
for (Relay relay : relays) {
if (relay.getId().equals(key)) {
relay.getGpio().setValue(value);
}
}
} catch (IOException e) {
e.printStackTrace();
}
@sergiocasero
sergiocasero / 0_reuse_code.js
Created February 27, 2017 09:19
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@sergiocasero
sergiocasero / Animations.kt
Last active June 30, 2017 10:56
Reveal animations for views (Android)
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.annotation.TargetApi
import android.os.Build
import android.view.View
import android.view.ViewAnimationUtils
/**
* Animation.
@sergiocasero
sergiocasero / Extensions.kt
Created December 14, 2017 10:49
Normalize extensions function
fun String.normalize(): String {
val map = mutableMapOf<Char, Char>()
map.put('À', 'A')
map.put('Á', 'A')
map.put('Â', 'A')
map.put('Ã', 'A')
map.put('Ä', 'A')
map.put('È', 'E')
map.put('É', 'E')
map.put('Ê', 'E')
@sergiocasero
sergiocasero / Ip.kt
Last active December 21, 2017 17:38
Simple code to get your public ip address
import IpAddress.Companion.IP_END
import IpAddress.Companion.IP_SEGMENT_SIZE
import IpAddress.Companion.IP_START
import kotlinx.coroutines.experimental.runBlocking
import java.net.URL
/**
* Ipfy
*/
data class IpAddress(private val segment1: Int,
@sergiocasero
sergiocasero / LogExtensions.kt
Created February 9, 2018 07:52
Kotlin Android logging extensions
import android.util.Log
/**
* AndroidExtensions
*/
/**
* Any
* */
fun Any.info(text: String) {
@sergiocasero
sergiocasero / MaybeSave.kt
Last active October 24, 2018 15:42
Maybe extension function to save data and return the same value (wihout blocking the stream)
fun <T> Maybe<T>.save(saveFunction: (T) -> Unit): Maybe<T> {
return MaybeSave(this, saveFunction)
}
private class MaybeSave<T>(val source: MaybeSource<T>, val saveFunction: (T) -> Unit) : Maybe<T>() {
override fun subscribeActual(observer: MaybeObserver<in T>) {
source.subscribe(MaybeSaveObserver<T>(observer, saveFunction))
}