Skip to content

Instantly share code, notes, and snippets.

Avatar
😄

Sergio Casero Hernández sergiocasero

😄
View GitHub Profile
View mapCircle
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 Jan 28, 2017
Listing Ports with android things
View listingPorts.java
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");
View relays.java
// 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();
}
View switch.java
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 Feb 27, 2017
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// 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 Jun 30, 2017
Reveal animations for views (Android)
View Animations.kt
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 Dec 14, 2017
Normalize extensions function
View Extensions.kt
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 Dec 21, 2017
Simple code to get your public ip address
View Ip.kt
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 Feb 9, 2018
Kotlin Android logging extensions
View LogExtensions.kt
import android.util.Log
/**
* AndroidExtensions
*/
/**
* Any
* */
fun Any.info(text: String) {
@sergiocasero
sergiocasero / MaybeSave.kt
Last active Oct 24, 2018
Maybe extension function to save data and return the same value (wihout blocking the stream)
View MaybeSave.kt
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))
}