Skip to content

Instantly share code, notes, and snippets.

View radzio's full-sized avatar
👨‍💻
Coding

Radek Piekarz radzio

👨‍💻
Coding
View GitHub Profile
@radzio
radzio / motion-activated-light-condition.yaml
Last active January 26, 2024 21:22
Motion-activated Light with condition
blueprint:
name: Motion-activated Light with condition
description: Turn on a light when motion is detected and condition met.
domain: automation
source_url: https://gist.githubusercontent.com/radzio/19992a1bd42392db265d79168e3c99d3/raw/9613351b5943f16daf0b39b881bcdf7c7463a7bb/motion-activated-light-condition.yaml
author: Home Assistant
input:
motion_entity:
name: Motion Sensor
selector:
@radzio
radzio / README.md
Created October 11, 2023 10:37 — forked from raahede/README.md
Handle multiple GitHub accounts on Mac
class LiveEvent<T> : MediatorLiveData<T>() {
private val observers = ConcurrentHashMap<LifecycleOwner, MutableSet<ObserverWrapper<T>>>()
@MainThread
override fun observe(owner: LifecycleOwner, observer: Observer<T>) {
val wrapper = ObserverWrapper(observer)
val set = observers[owner]
set?.apply {
add(wrapper)
git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done
@radzio
radzio / Instructions.md
Last active March 8, 2018 19:33
commit-msg.sh

Instructions

  • copy the file commit-msg to .git/hooks/commit-msg
  • make sure your delete the sample file .git/hooks/commit-msg.sample
  • Make commit msg executable. chmod +x .git/hooks/commit-msg
  • Edit commit-msg to better fit your development branch, commit regex and error message
  • Profit $$

Shell example

public class MainViewModelTests {
@Test
public void mainViewModel_firstName_lastName_helloButtonEnabledSetToTrue() throws Exception {
MainViewModel mainViewModel = new MainViewModel();
assertFalse(mainViewModel.helloButtonEnabled.get());
mainViewModel.firstName.set("a");
mainViewModel.lastName.set("b");
public static class MainViewModel {
public ObservableField<String> firstName = new ObservableField<>();
public ObservableField<String> lastName = new ObservableField<>();
public ObservableField<String> helloText = new ObservableField<>();
public ObservableBoolean helloButtonEnabled = new ObservableBoolean(false);
public MainViewModel() {
Observable.combineLatest(toObservable(firstName), toObservable(lastName), (firstName, lastName) -> StringUtils.isNotNullOrEmpty(firstName) && StringUtils.isNotNullOrEmpty(lastName))
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="@{viewModel.helloButtonEnabled}"
android:onClick="@{() -> viewModel.buttonClicked()}"
android:text="@string/btn_hello_rx" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="@{StringUtils.isNotNullOrEmpty(viewModel.firstName) &amp;&amp; StringUtils.isNotNullOrEmpty(viewModel.lastName)}"
android:onClick="@{() -> viewModel.buttonClicked()}"
android:text="@string/btn_hello" />
public static <T> Observable<T> toObservable(@NonNull final ObservableField<T> observableField) {
return Observable.create(new Observable.OnSubscribe<T>() {
@Override
public void call(final Subscriber<? super T> subscriber) {
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(observableField.get());
}
final OnPropertyChangedCallback callback = new OnPropertyChangedCallback() {