Skip to content

Instantly share code, notes, and snippets.

Patrick Hammond patrickhammond

Block or report user

Report or block patrickhammond

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View reply.xml
Thanks! If you want me to stop reminding you, reply with STOP.
View keybase.md

Keybase proof

I hereby claim:

  • I am patrickhammond on github.
  • I am patrickhammond (https://keybase.io/patrickhammond) on keybase.
  • I have a public key whose fingerprint is 6C11 873C A480 C6FC 14C4 E534 7453 02C8 2C35 C49A

To claim this, I am signing this object:

@patrickhammond
patrickhammond / MainActivity.kt
Last active Jan 21, 2017
Motor controlled via L293D.
View MainActivity.kt
package com.madebyatomicrobot.things
import android.app.Activity
import android.os.Bundle
import android.util.Log
import com.google.android.things.pio.Gpio
import com.google.android.things.pio.PeripheralManagerService
import java.io.IOException
@patrickhammond
patrickhammond / MainActivity.kt
Created Jan 9, 2017
Raspberry Pi 3 running Android Things driving an Arduino Uno to control an RGB LED
View MainActivity.kt
package com.madebyatomicrobot.things
import android.app.Activity
import android.os.Bundle
import android.util.Log
import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import android.widget.TextView
import com.google.android.things.pio.PeripheralManagerService
import com.google.android.things.pio.UartDevice
@patrickhammond
patrickhammond / MainActivity.java
Created Jan 5, 2017
First tinkering with Android Things on a Raspberry Pi. Demo video: https://goo.gl/photos/R6oZmnqS8XBmTNx58
View MainActivity.java
package com.example.androidthings.myproject;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
@patrickhammond
patrickhammond / 0_no.java
Created Nov 9, 2016
Correctly managing realm results that also have an associated change listener.
View 0_no.java
private void setupChangeListener() {
RealmResults<Unique> results = realm.where(Something.class).findAll();
handleResults(results);
// I've tried this with the listener as an anonymous inner class and also assigning it to a
// field to ensure there isn't an issue with it being GC'd.
results.addChangeListener(new RealmChangeListener<RealmResults<Something>>() {
@Override
public void onChange(RealmResults<Something> element) {
handleResults(element);
View ParcelableHelper.java
import android.os.Parcel;
import android.os.Parcelable;
public class ParcelableHelper {
/**
* There is not always a guarantee that Parcelable values will be immediately written out and
* read back in. For data data that mutable (its own issue), this can be a problem. This is
* for the times when it would be great to have confidence that you will be working with a copy
* of that data.
View SampleJsonTest.java
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class SampleJsonTest {
private static final String SAMPLE_JSON = "{ \"first_name\": \"Atomic\", \"last_name\": \"Robot\" }";
@patrickhammond
patrickhammond / snippet.java
Created Jun 23, 2016
Tinting a map marker.
View snippet.java
Bitmap markerBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.mapmarker);
Bitmap resultBitmap = Bitmap.createBitmap(markerBitmap, 0, 0, markerBitmap.getWidth() - 1, markerBitmap.getHeight() - 1);
ColorFilter filter = new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
Paint markerPaint = new Paint();
markerPaint.setColorFilter(filter);
Canvas canvas = new Canvas(resultBitmap);
canvas.drawBitmap(resultBitmap, 0, 0, markerPaint);
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resultBitmap));
You can’t perform that action at this time.