Skip to content

Instantly share code, notes, and snippets.

View luthfihariz's full-sized avatar
🏠
Working from home

Luthfi Hariz luthfihariz

🏠
Working from home
View GitHub Profile
@luthfihariz
luthfihariz / NewsActivity.java
Created December 7, 2012 15:52
Submenu with Action Bar Sherlock
//here code before...
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.article_menu, menu);
return super.onCreateOptionsMenu(menu);
}
public boolean onOptionsItemSelected(
@luthfihariz
luthfihariz / ListItem.java
Created December 30, 2012 02:59
Loading newsfeed in background
package com.ideaplay.sharee.utility;
import java.util.ArrayList;
public class ListItem {
private String contributorImageUrl;
private String itemTitle;
private String itemContent;
private String itemContributor;
private String itemPubDate;
@luthfihariz
luthfihariz / cosine_similiarity.py
Last active June 18, 2016 03:18
Using TF-IDF and Cosine Similiarity to find item to item similiarity based on its name and descriptions.
import pandas as pd
import time
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import linear_kernel
import json
start = time.time()
ds = pd.read_csv('query_result.csv')
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:padding="16dp"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/rvListOfEvent"
dependencies {
....
// viewmodel & livedata
implementation "android.arch.lifecycle:extensions:$rootProject.archLifecycleVersion"
annotationProcessor "android.arch.lifecycle:compiler:$rootProject.archLifecycleVersion"
....
}
class EventListViewModel : ViewModel(){
val eventList = arrayListOf(Event("Google IO 2018"),
Event("Droidcon London 2018"),
Event("GOTO Berlin 2018"))
}
class EventListActivity : BaseActivity(){
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_event_list)
val viewModel = ViewModelProviders.of(this).get(EventListViewModel::class.java)
rvListOfEvent.layoutManager = LinearLayoutManager(this)
val adapter = EventListAdapter()
@luthfihariz
luthfihariz / EventListActivity.kt
Created August 1, 2018 00:26
ViewModel & LiveData
class EventListViewModel : ViewModel(){
val eventList = MutableLiveData<List<Event>>()
init {
eventList.postValue(arrayListOf(Event("Google IO 2018"),
Event("Droidcon London 2018"),
Event("GOTO Berlin 2018")))
}
@luthfihariz
luthfihariz / EventListActivity.kt
Created August 1, 2018 00:30
Observing LiveData
class EventListActivity : BaseActivity(){
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_event_list)
val viewModel = ViewModelProviders.of(this).get(EventListViewModel::class.java)
// setup recyclerview
rvListOfKajian.layoutManager = LinearLayoutManager(this)
if (isIpAddressDifferentWithLastRecorded(latestIpAddress)) {
Log.d(
WorkManagerHelper.TAG,
"Different IP Address ($latestIpAddress}."
)
insertNewRecordToDb(latestIpAddress)
} else {
if (connManager.getNetworkClass() == ConnectionManager.NETWORK_WIFI) {
// check if its on wifi more than one hour