Skip to content

Instantly share code, notes, and snippets.

@loeschg
loeschg / gpio.ex
Created March 21, 2017 22:32
Fake gpio implementation for ElixirAle
defmodule FakeAle.Gpio do
use GenServer
@moduledoc """
This is a fake Elixir interface to ElixirALE.GPIO.
Each "GPIO" is an independent GenServer.
"""
defmodule State do
@moduledoc false
@loeschg
loeschg / DateTypeAdapter.java
Last active December 11, 2019 12:14
Custom TypeAdapter for GSON which handles both Date and DateTime formats (ISO 8601 and a simple date format)
package com.my.utility;
import com.fasterxml.jackson.databind.util.ISO8601Utils;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.text.DateFormat;
@loeschg
loeschg / android-snippets.md
Last active August 29, 2015 14:08
Android snippets

New View/Activity/Fragment animation

private void setupAnimation(View view) {
    if (view.getViewTreeObserver().isAlive()) {
        ViewTreeObserver observer = view.getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
 if (view.getViewTreeObserver().isAlive()) {
@loeschg
loeschg / build.gradle
Last active August 29, 2015 14:07
Robolectric tests are not working with double-espresso due to it not excluding espresso files. This snippet allows you to exclude Espresso resources when running Robolectric tests. More info can be found here: http://stackoverflow.com/a/24706452/413254
/** Hook into existing tasks. */
tasks.whenTaskAdded { theTask ->
excludeEspressoFilesIfNecessary(theTask)
}
/**
* This excludes Espresso tests from Robolectric. http://stackoverflow.com/a/24706452/413254
*
* This was needed when using double-espresso. I couldn't get Robolectric to exclude them
* normally unless doing this. Double-espresso is used to fix a conflicting Dagger 1.2 dependency
@loeschg
loeschg / activity_main.xml
Last active August 29, 2015 14:01
ALG - Session 1 - activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.weddingwire.android.learninggroup.session1.MainActivity">
@loeschg
loeschg / MainActivity.java
Last active August 29, 2015 14:01
ALG - Session 1 - MainActivity.java
package com.weddingwire.android.learninggroup.session1;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
/**
* Activity to increment a textfield on button press.
@loeschg
loeschg / gist:31f9ced8437331947221
Last active August 29, 2015 14:01
WeddingWire: Android Learning Group

Android Learning Group

##Table of Contents: 1 - Intro: Android Studio & Genymotion

#1 - Intro: Android Studio & Genymotion

Android Studio

[Android Studio][1] is a new Android development environment based on IntelliJ IDEA. It bundles all the essential Android SDK and Android IntelliJ plugins.

@loeschg
loeschg / gist:00df15fddefd3614c7d8
Created May 2, 2014 20:09
Multiple Fragments side by side
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2012 The Android Open Source Project
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
package some.awesome.package;
import it.sephiroth.android.library.imagezoom.ImageViewTouch;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
public class ImageViewTouchViewPager extends ViewPager {
@loeschg
loeschg / Notes:Vi_IMproved-Vim.md
Last active December 14, 2015 06:48
Some notes from the book Vi IMproved-Vim by Steve Oualline

Vi IMproved - Vim

Notes

Table Of Contents:

Undo/redo

U       - undoes all changes to the line