Skip to content

Instantly share code, notes, and snippets.

View haydarai's full-sized avatar

Haydar Ali Ismail haydarai

View GitHub Profile
List<Post> posts = ...; // Fill the list with data
List<Post> filteredPost = new ArrayList<>();
// Iterate through the collection
for (Post post : posts) {
if (post.getAuthor().equals("Haydar") // The filter condition
filteredPost.add(post); // Adding the filtered item to the filtered collection
}
viewHolder.deleteButton.setOnClickListener(view -> delete(viewHolder.getAdapterPosition()));
@Override
public void onBindViewHolder(PostAdapter.ViewHolder holder,
int position) { // The `position` sometimes is not updated according to the latest update
/**
* We initialize our view for the current item here
**/
/**
* We want to set our delete button to run delete method.
List<Post> posts = ...; // Fill the list with initial data
PostAdapter adapter = new PostAdapter(this, posts); // Initialize the RecyclerView Adapter
recyclerView.setAdapter(adapter); // Set adapter to the RecyclerView
/**
* Running some operation that modify the `posts` list
**/
adapter.notifyDataSetChanged; // Notify the adapter that the `posts` list already changed,
// it can also substituted with `notifyItemInserted`,
@haydarai
haydarai / studio64.exe.vmoptions
Created February 5, 2017 09:39
My custom Android Studio VM options
# custom Android Studio VM options
#
# *DO NOT* modify this file directly. If there is a value that you would like to override,
# please add it to your user specific configuration file.
#
# See http://tools.android.com/tech-docs/configuration
#
-server
-Xms1G
@haydarai
haydarai / gradle.properties
Created February 5, 2017 09:35
Configuration to allow Gradle build faster
org.gradle.parallel=true
org.gradle.daemon=true
@haydarai
haydarai / check-accuracy-with-parameter-tuning.py
Created February 2, 2017 12:10
Check model accuracy that already given best parameter from Grid Search
cv_scores = cross_val_score(dtc, all_inputs, all_classes)
sns.distplot(cv_scores)
plt.title('Average score: {}'.format(np.mean(cv_scores)))
@haydarai
haydarai / grid-search.py
Last active February 2, 2017 12:07
Searching for best parameters
from sklearn.grid_search import GridSearchCV
dtc = DecisionTreeClassifier()
parameter_grid = {'criterion': ['gini', 'entropy'],
'splitter': ['best', 'random'],
'max_depth': [1, 2, 3, 4, 5],
'max_features': [1, 2, 3, 4]}
cross_validation = StratifiedKFold(all_classes, n_folds=10)
@haydarai
haydarai / 10-fold-cross-validation.py
Last active February 2, 2017 12:08
Perform 10-fold cross-validation to the dataset and display the accuracy
from sklearn.cross_validation import cross_val_score
dtc = DecisionTreeClassifier()
cv_scores = cross_val_score(dtc, all_inputs, all_classes, cv=10)
sns.distplot(cv_scores)
plt.title('Average score: {}'.format(np.mean(cv_scores)))
@haydarai
haydarai / checking-for-accuracies.py
Created February 2, 2017 10:12
Checking for models' accuracy and plot them
model_accuracies = []
for i in range(1000):
(training_inputs,
testing_inputs,
training_classes,
testing_classes) = train_test_split(all_inputs, all_classes, train_size=0.7)
decision_tree_classifier = DecisionTreeClassifier()
decision_tree_classifier.fit(training_inputs, training_classes)