Skip to content

Instantly share code, notes, and snippets.

package pl.brightinventions.samples;
import android.content.Context;
import android.content.SharedPreferences;
import javax.inject.Singleton;
public interface CurrentUserProvider {
boolean isLoggedIn();
CurrentUser getCurrentUser();
enum UserType {
ANONYMOUS,
REGULAR,
PREMIUM
}
class MyActivity extends Activity {
@Inject
CurrentUserProvider _userProvider;
interface UserReference {
void dispatchBehavior(@NonNull UserBehavior behavior);
}
class AnonymousUserReference implements UserReference {
@Override
public void dispatchBehavior(@NonNull UserBehavior behavior) {
behavior.onAnonymous(this);
}
}
public abstract class UserBehavior {
private boolean shouldRunDefault;
public void byDefault(UserReference reference){}
public void onAnonymous(UserReference user){
shouldRunDefault = true;
}
public void onRegular(RegularUserReference user) {
shouldRunDefault = true;
interface Action2<T,Throwable> {
void call(T t, Throwable error);
}
interface RegisterApi {
class RegistrationModel {
String firstName;
}
void register(RegistrationModel data, Action2<RegistrationModel, Throwable> result);
}
import pl.brightinventions.databinding.databinding.ActivityRegisterBinding;
public class RegisterActivity extends Activity {
RegisterApi registerApi; // inject or create remote api
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityRegisterBinding viewDataBinding = DataBindingUtil.setContentView(this, R.layout.activity_register);
@miensol
miensol / aws-elasticbeanstalk-ec2-role-trust.json
Created December 15, 2015 07:24
ElasticBeanstaclk Default IAM Policies
{
"Version": "2008-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
@miensol
miensol / MsdnExample.cs
Created December 25, 2015 10:08
SimpleConfigSections samples
public class PageAppearanceSection : ConfigurationSection<IPageAppearance>
{
}
public interface IPageAppearance
{
bool RemoteOnly { get; }
IFont Font { get; }
IColor Color { get; }
}
public class RetrofitTest {
@Test
public void configure() throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.registerModule(new JodaModule());
Retrofit retrofit = new Retrofit.Builder()
package sample.stackanswers;
import android.app.Activity
import org.junit.Assert
import org.junit.Before;
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith;
import org.mockito.*
import org.mockito.junit.MockitoJUnit