Skip to content

Instantly share code, notes, and snippets.

View sergiocasero's full-sized avatar
😄

Sergio Casero Hernández sergiocasero

😄
View GitHub Profile
@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 / 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
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 / 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();
}
@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");
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),
});