Skip to content

Instantly share code, notes, and snippets.

View blundell's full-sized avatar
😶‍🌫️

Paul Blundell blundell

😶‍🌫️
View GitHub Profile
@blundell
blundell / clear-android-things-apps.sh
Last active April 22, 2022 17:23
Uninstall all apps on an Android Device that have the intent-filter category IOT_LAUNCHER
#!/bin/bash
sp="/-\|"
sc=0
spin() {
printf "\b${sp:sc++:1}"
((sc==${#sp})) && sc=0
}
endspin() {
printf "\r"
}
@blundell
blundell / interleave Java 8.java
Created November 14, 2018 20:12
Interleave two streams of the same type in Java 8
Stream<String> a = Stream.of("one", "three", "five");
Stream<String> b = Stream.of("two", "four", "six");
Stream<String> out = interleave(a, b);
/**
* https://stackoverflow.com/questions/53307682/how-to-interleave-merge-two-java-8-streams
**/
public static <T> Stream<T> interleave(Stream<T> streamA, Stream<T> streamB) {
return zip(streamA, streamB, (o1, o2) -> Stream.of(o1, o2)).flatMap(s -> s);
class HellowWorldRepository {
interface Listener {
void onSomethingDone(String result);
}
public void doSomething(Listener listener) {
new Thread(new Runnable(){ // this is the worst way to do threading, google "android threading"
@Override
public void run() {
// do some stuff
@blundell
blundell / VideoView Buffering Spinner
Created January 21, 2014 12:29
Adding a progress spinner to a video view for before it starts or whilst it is buffering.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="@+id/my_video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />
@blundell
blundell / mailchimp.iframe
Last active February 9, 2019 20:48
Clean Mailchimp sign up form
<!-- Begin Mailchimp Signup Form -->
<style type="text/css">
#mc_embed_signup { border: none; text-align: center; width: 100%; } /* Signup form container */
.mc-field-group { display: inline-block; } /* positions input field horizontally */
#mce-EMAIL { font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 1em; ; border:none; border-bottom: 2px solid #000; color: #343434; background-color: transparent; padding: .7em 30em .7em 1em; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; display: inline-block; margin: 0; } /* Input Styles */
.clear { display: inline-block; } /* positions button horizontally in line with input */
@blundell
blundell / ForegroundImageView.java
Created January 4, 2015 13:00
An ImageView which supports a centered foreground drawable. - Based on Jake Wharton's ForegroundImageView
/**
* https://gist.github.com/JakeWharton/0a251d67649305d84e8a
* <p/>
* Then modified to :
* not scale the foreground to the ImageView size
* draw the foreground centered
*/
public class ForegroundImageView extends ImageView {
private Drawable foreground;
@blundell
blundell / anti-hungarian-checkstyle
Created January 25, 2014 15:12
Anti-Hungarian CheckStyle check
import com.puppycrawl.tools.checkstyle.api.*;
public class AntiHungarianCheck extends Check {
private static final String CATCH_MSG = "Hungarian notation belongs in the 90's. " +
"Don't prefix member variables with 'm'. " +
"Use your IDE's shiny colors. Culprit was: ";
private final HungarianNotationMemberDetector detector = new HungarianNotationMemberDetector();
@blundell
blundell / 1_use.java
Created April 17, 2017 09:46
An AndroidThings button you can use to run something in a 1 liner call
Runnable somethingIWannaDo = new Runnable() {
@Override
public void run() {
Log.d("EZ", "I got ran");
}
};
// In Android Activity onCreate:
RunnableButton.create("BCM21", somethingIWannaDo).onCreateInjectInto(this);
@blundell
blundell / Gradle handle repos
Created January 20, 2014 19:48
Handle the declaration of all source code repositories in your base build file, and you don't have to worry about declaring them in any child modules. The code below would go at the top of your build.gradle, in your 'base' or 'top' build.gradle file. You don't have to add anything to child modules. You will get full repository source retrieval.
subprojects {
buildscript {
repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
maven {
url "https://github.com/novoda/public-mvn-repo/raw/master/releases"
}
@blundell
blundell / Crazy Array Init
Last active December 31, 2015 18:22
1 line annon inner class array initialisation because I want to be able to add & remove but I'm too lazy to extend BaseAdapter.
public class NavDrawerArrayAdapter extends ArrayAdapter<String> {
public NavDrawerArrayAdapter(final Context context) {
super(context, android.R.layout.simple_list_item_activated_1, android.R.id.text1,
new ArrayList<String>() {{
add(context.getString(R.string.nav_drawer_section_explore));
add(context.getString(R.string.nav_drawer_section_rewards));
add(context.getString(R.string.nav_drawer_section_offers));
add(context.getString(R.string.nav_drawer_section_events));
}});
refresh();