Skip to content

Instantly share code, notes, and snippets.

View ryanamaral's full-sized avatar

Ryan Amaral ryanamaral

View GitHub Profile
@ryanamaral
ryanamaral / Arduino 230v Light bulb dimming
Last active November 23, 2020 18:46
Arduino 230v Light Bulb Dimming (Portugal 220V 50 Hz)
//source: http://electronics.stackexchange.com/q/59615
int AC_LOAD = 3; // Output to Opto Triac pin
int dimming = 128; // Dimming level (0-128) 0 = ON, 128 = OFF
void setup()
{
pinMode(AC_LOAD, OUTPUT); // Set the AC Load as output
attachInterrupt(0, zero_crosss_int, RISING); // Choose the zero cross interrupt # from the table above
}
@ryanamaral
ryanamaral / LedsOnOff.ino
Last active August 29, 2015 14:18
[Arduino] Control LEDs with IR Remote
//Control LEDs ON/OFF with IR Remote and Arduino
//source: http://www.electroschematics.com/9522/arduino-control-leds-ir-remote/
/*
source: www.electroschematics.com
You'll need to change the led pins and the codes
accordingly to your configuration and IR remote
*/
#include <IRremote.h>
import android.support.v7.widget.RecyclerView;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* Created by pascalwelsch on 04.07.14.
*/
public abstract class ArrayAdapter<T, VH extends RecyclerView.ViewHolder>

You can use this class to realize a simple sectioned grid RecyclerView.Adapter without changing your code.

Screen

The RecyclerView has to use a GridLayoutManager.

This is a porting of the class SimpleSectionedListAdapter provided by Google

If you are looking for a sectioned list RecyclerView.Adapter you can take a look here

@ryanamaral
ryanamaral / PaddingItemDecoration.java
Created May 25, 2015 15:18
RecyclerView.ItemDecoration implementation for equal padding between the list items except first and last items.
/**
* ItemDecoration implementation for equal padding between the list items except first and last items.
* @author Ryan Amaral
* @version 1.0
*/
public class PaddingItemDecoration extends RecyclerView.ItemDecoration {
private int mPaddingPx;
private int mPaddingEdgesPx;
/*
* Author: Felipe Herranz (felhr85@gmail.com)
* Contributors:Francesco Verheye (verheye.francesco@gmail.com)
* Israel Dominguez (dominguez.israel@gmail.com)
*/
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import android.os.Handler;
@ryanamaral
ryanamaral / MyApp.java
Last active December 3, 2015 08:05 — forked from UweTrottmann/MyApp.java
Set up a dummy account for your Android SyncAdapter. Run this on app startup, e.g. in your Application classes onCreate().
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
// set up a dummy account for syncing
AccountManager manager = AccountManager.get(this);
final Account account = new Account(MyAccountAuthenticator.ACCOUNT_NAME, getPackageName());
if (manager.addAccountExplicitly(account, null, null)) {
// Only change sync settings if it did not exist, yet
@ryanamaral
ryanamaral / BarListParcelConverter.java
Last active September 2, 2015 09:12 — forked from cmelchior/BarListParcelConverter.java
Using Parceler 1.0.3 with Realm
// Specific class for a RealmList<Bar> field
public class BarListParcelConverter extends RealmListParcelConverter<Bar> {
@Override
public void itemToParcel(Bar input, Parcel parcel) {
parcel.writeParcelable(Parcels.wrap(input), 0);
}
@Override
public Bar itemFromParcel(Parcel parcel) {
/*
* Copyright 2013 Chris Banes
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ryanamaral
ryanamaral / LeakSlackUploadService.java
Last active September 13, 2015 13:49 — forked from pyricau/LeakSlackUploadService.java
Sending Leak Traces to a Slack Channel (and HipChat, see the comments)
import android.util.Log;
import com.squareup.leakcanary.AnalysisResult;
import com.squareup.leakcanary.DisplayLeakService;
import com.squareup.leakcanary.HeapDump;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.http.Multipart;
import retrofit.http.POST;
import retrofit.http.Part;
import retrofit.mime.TypedFile;