Skip to content

Instantly share code, notes, and snippets.

mkdir alpha
cd alpha
mkdir data
printf 'a' > data/letter.txt
git init
git add data/letter.txt
printf '1234' > data/number.txt
git add data
printf '1' > data/number.txt
git add data
# Package by features
The directory structure is the very first thing encountered by a programmer when browsing source code. Everything flows from it. Everything depends on it. It is clearly one of the most important aspects of your source code.
### Gains and Benefits
* By looking at the structure you can already tell what the app is all about (figure 1);
* Higher modularity;
* Easier code navigation;
* Higher level of abstraction;
## Note :
We will use MVP as default architecture cause it's easy to implement comparing to MVVM.
Instead we will implement some features with MVVM architecture.
## Why we need an Architecture ?
1. The Android API is tightly coupled.
2. Make the app easy to test (the must important part).
3. Make the app modular.
4. Make app change/fix easy.
@selmanon
selmanon / gist:ec3f18e31618c8648077fb224416521a
Created August 30, 2017 20:15
Simplifying the startActivity function on Android using reified type parameter
inline fun<reified T:Activity>Context.startActivity() {
val intent = Intent(this, T:: class.java)
startActivity(intent)
}
startActivity<DetailActivity>()
testLoginError()
testLoginSuccess()
testLoginWithoutStudentNameAndPassword()
@Test
public void testSuccessfulLogin() {
// Aragnge
final LoginViewModel vm = new LoginViewModel(environment());
final TestSubscriber<Void> loginSuccess = new TestSubscriber<>();
vm.outputs.loginSuccess().subscribe(loginSuccess);
vm.inputs.email("hello@kickstarter.com");
vm.inputs.password("danisawesome");
Observable
.just(1, 2, 3, 4, 5)
.filter(new Func1<Integer, Boolean>() {
@Override
public Boolean call(Integer integer) {
return integer % 2 != 0;
}
}).subscribe(new Observer<Integer>() {
@Override
public void onSubscribe(Disposable d) {
Observable
.just(1, 2, 3, 4, 5)
.filter(integer -> integer % 2 != 0)
.subscribe(
integer -> Log.i(TAG, String.valueOf(integer)),
error -> Log.e(TAG, "Error"),
() -> Log.i(TAG, "No more results")
);
if (product.getType == productType.TYPE_A) {
// ...
} else if (product.getType == productType.TYPE_B) {
// ...
} else if (...) {
// ...
}
else {
// ...
}
import kotlin.math.ceil
data class Cell(val i: Int, val j: Int, val isAlive: Boolean) {
operator fun get(i: Int, j: Int): Int {
if ((i < 0 || i >= 2) || (j < 0 || j >= 2)) return 0
else
return 0
}
}