Skip to content

Instantly share code, notes, and snippets.

View shahbazahmed1269's full-sized avatar
:octocat:

Shahbaz Ahmed shahbazahmed1269

:octocat:
View GitHub Profile
@shahbazahmed1269
shahbazahmed1269 / CPTTRN4.java
Created May 28, 2016 09:54
problem CPTTRN4, based on SPOJ submission 17005746 (JAVA)
import java.util.*;
import java.lang.*;
import java.io.*;
class CPTTRN4
{
public static void main (String[] args) throws java.lang.Exception
{
int t,l,c,h,w;
String input;
@shahbazahmed1269
shahbazahmed1269 / ApiResponse.java
Created May 29, 2017 14:42
Snippets for medium blog post "Getting started with android architecture components and MVVM"
public class ApiResponse {
private List<Issue> issues;
private Throwable error;
public ApiResponse(List<Issue> issues) {
this.issues = issues;
this.error = null;
}
public ApiResponse(Throwable error) {
public class ApiResponse {
private List<Issue> issues;
private Throwable error;
public ApiResponse(List<Issue> issues) {
this.issues = issues;
this.error = null;
}
public ApiResponse(Throwable error) {
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
public interface GithubApiService {
@GET("/repos/{owner}/{repo}/issues")
Call<List<Issue>> getIssues(@Path("owner") String owner, @Path("repo") String repo);
}
public interface IssueRepository {
LiveData<ApiResponse> getIssues(String owner, String repo);
}
public class IssueRepositoryImpl implements IssueRepository {
public static final String BASE_URL = "https://api.github.com/";
private GithubApiService mApiService;
public IssueRepositoryImpl() {
Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(BASE_URL)
.build();
public class ListIssuesViewModel extends ViewModel {
private MediatorLiveData<ApiResponse> mApiResponse;
private IssueRepository mIssueRepository;
// No argument constructor
public ListIssuesViewModel() {
mApiResponse = new MediatorLiveData<>();
mIssueRepository = new IssueRepositoryImpl();
}
@shahbazahmed1269
shahbazahmed1269 / ListIssuesViewModelnoDI.java
Created June 10, 2017 05:43
Part of my 2nd blog post on architecture components and MVVM
public class ListIssuesViewModel extends ViewModel {
private IssueRepository mIssueRepository;
// Other member declarations
public ListIssuesViewModel() {
mIssueRepository = new IssueRepositoryImpl();
// Other code
}
// Other code
@shahbazahmed1269
shahbazahmed1269 / ListIssuesViewModelWithDI.java
Created June 10, 2017 05:45
Part of my 2nd blog post on architecture components and MVVM
public class ListIssuesViewModel extends ViewModel {
private IssueRepository mIssueRepository;
// Other member declarations
public ListIssuesViewModel(IssueRepository repository) {
mIssueRepository = repository;
// Other code
}
// Other code