Skip to content

Instantly share code, notes, and snippets.

View Tarek-Bohdima's full-sized avatar

Tarek Bohdima Tarek-Bohdima

View GitHub Profile
/* Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
public class LiveDataTestUtil {
public static <T> T getOrAwaitValue(final LiveData<T> liveData) throws InterruptedException {
final Object[] data = new Object[1];
final CountDownLatch latch = new CountDownLatch(1);
Observer<T> observer = new Observer<T>() {
@Override
public void onChanged(@Nullable T o) {
data[0] = o;
@DucNgn
DucNgn / PowerlineForTerminal.md
Last active March 29, 2024 03:28
Powerline style for terminal OSX

Installing and configuring Powerline-style command line tools for developers (OSX)

Intro:

For every developer, terminal is their weapon, so why don't you customize it to become a powerful, and a beautiful weapon?

Powerline style refers to a terminal style that helps developer to keep track of their workflow easily, allows them to have perfect visual on current directories and new changes. It is also git recognizable, and failure detector that will help your development process becomes more interact and much faster.

In this guideline, I will introduce you with 2 smart shells: Zsh and Fishshell. Both are perfect for the development jobs due to its rich of resources, and user-friendly.

Note:

@objcode
objcode / ConcurrencyHelpers.kt
Last active January 5, 2025 08:26
Helpers to control concurrency for one shot requests using Kotlin coroutines.
/* Copyright 2019 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
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@MuhsinFatih
MuhsinFatih / fix-macos-python.md
Last active March 6, 2025 07:13
How to recover from messed up python installation on mac, and never have to mess with apple's shitty python confusion factory

I am assuming you are here because like me, you installed a bazillion different python interpreters on mac and the whole thing is a spagetti. Today, I finally fixed my python installation. Whatever I install for python2 or python3 using pip JUST.WORKS.. My god! finally.

What the hell?

Here is what I had messed up, which you also probably did:

  • I had too many different python interpreters
  • Too many different symlinks which I lost track of
  • almost no package I installed with pip worked without a headache
  • any attempt to fix using online resources made it worse.
@worric
worric / learning_dagger2.md
Last active September 24, 2018 20:08
Learning how to use Dagger2

Learning how to use Dagger2

When learning to use Dagger, I think a large part of the difficulty arises from the fact that there are A LOT of articles out there explaining how Dagger works, which can be confusing in itself when trying to synthesize all the knowledge. One issue is that the example projects are wildly different in terms of organization and practices used. Another issue is the variance in Android version used, and so some resources may use outdated libraries and practices.

Adding to the confusion, somewhat recently a few Android-specific Dagger packages were introduced, which added some improvements to how it's used on Android. This means that there are articles dealing with the OLD method of using Dagger as well as articles dealing with the NEW way. This confused the hell out of me when I was trying to learn it.

Having come out on the other side of the confusion, the following are the resources I would recommend to anyone trying to learn Dagger from scratch.

Resources

@florina-muntenescu
florina-muntenescu / pre-commit
Created June 24, 2018 22:26
Pre-commit hooks
#!/bin/sh
#
# Add hook scripts to be run before every commit.
# This is called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook save this file in your repo .git/hooks folder
# clean and run tests
@JoseAlcerreca
JoseAlcerreca / Event.kt
Created April 26, 2018 10:25
An event wrapper for data that is exposed via a LiveData that represents an event.
/**
* Used as a wrapper for data that is exposed via a LiveData that represents an event.
*/
open class Event<out T>(private val content: T) {
var hasBeenHandled = false
private set // Allow external read but not write
/**
* Returns the content and prevents its use again.
public class MainActivity extends AppCompatActivity {
//Declaring global variables
private int score;
private EditText nameField;
private CheckBox india;
private CheckBox unitedStates;
private CheckBox china;
private CheckBox unitedKingdom;
private RadioGroup answers1;
@florina-muntenescu
florina-muntenescu / BaseDao.kt
Last active January 1, 2025 06:52
Use Dao inheritance to reduce the amount of boilerplate code - https://medium.com/google-developers/7-pro-tips-for-room-fbadea4bfbd1
/*
* Copyright (C) 2017 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
*
* Unless required by applicable law or agreed to in writing, software
@florina-muntenescu
florina-muntenescu / Data.kt
Last active February 19, 2025 14:28
Using RoomDatabase#Callback to pre-populate the database - https://medium.com/google-developers/7-pro-tips-for-room-fbadea4bfbd1
/*
* Copyright (C) 2017 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
*
* Unless required by applicable law or agreed to in writing, software