Skip to content

Instantly share code, notes, and snippets.

View herisulistiyanto's full-sized avatar
:octocat:
Working from home

heri sulistiyanto herisulistiyanto

:octocat:
Working from home
View GitHub Profile
@herisulistiyanto
herisulistiyanto / index.js
Created January 6, 2018 17:14
scrapping data
const cheerio = require('cheerio');
const axios = require('axios');
var qs = require('qs');
const fs = require('fs');
const dist_file_dir = 'dist/';
let provinsi = [];
let kabupaten = [];
let kecamatan = [];
fun main() {
val shotGun = ShotGun("S12K", "Brown").apply {
projectile = 3
}
val deagle = Deagle("Deagle", "Red").apply {
projectile = 3
}
val snipper = Snipper().apply {
interface MovieApiService {
@GET("/3/discover/movie")
suspend fun discoverAllMovies(): Response<MovieResponse>
@GET("/3/movie/{movieId}")
suspend fun getMovieDetail(@Path("movieId") movieId: Int): Response<MovieDetailResponse>
}
abstract class BaseDataSource {
protected suspend fun <T> getResult(call: suspend () -> Response<T>): ResponseResult<ResponseWrapper<T>> {
try {
val response = call()
if (response.isSuccessful) {
val body = response.body()
if (null != body) return ResponseResult.Success(ResponseWrapper(body, null))
}
return error("${response.code()} ${response.message()}")
class MovieRemoteDataSource(private val movieApiService: MovieApiService) : BaseDataSource() {
fun discoverAllMovies(scope: CoroutineScope): LiveData<ResponseResult<ResponseWrapper<MovieResponse>>> = resultLiveData(scope) {
getResult {
movieApiService.discoverAllMovies()
}
}
fun getMovieDetails(movieId: Int, scope: CoroutineScope): LiveData<ResponseResult<ResponseWrapper<MovieDetailResponse>>> = resultLiveData(scope) {
getResult {
class DashboardViewModel(private val movieRemoteDataSource: MovieRemoteDataSource) : ViewModel() {
private val _movieResult = MutableLiveData<ResponseResult<ResponseWrapper<MovieResponse>>>()
val movieResult: LiveData<ResponseResult<ResponseWrapper<MovieResponse>>> get() = _movieResult
fun discoverAllMovies() {
viewModelScope.launch {
val response = movieRemoteDataSource.discoverAllMovies(it)
//usually i do like this, but it will give null when we observe movieResult
class DashboardViewModel(private val movieRemoteDataSource: MovieRemoteDataSource) : ViewModel() {
fun discoverAllMovies() = movieRemoteDataSource.discoverAllMovies(viewModelScope)
}
class DashboardActivity : BaseActivity() {
private val dashboardViewModel by viewModel<DashboardViewModel>()
private val movieAdapter by lazy {
DashboardMovieAdapter {
launchActivity<MovieDetailActivity>(
MovieDetailActivity.ExtraKey.EXTRA_MOVIE_ID to it.first,
MovieDetailActivity.ExtraKey.EXTRA_MOVIE_TITLE to it.second
)
}
@herisulistiyanto
herisulistiyanto / manifest-checker.gradle
Last active September 12, 2022 08:18
manifest-checker.gradle
import org.w3c.dom.Node
/**
* This function will check child nodes from the AndroidManifest.xml file
* whether the nodes (activity, service, receiver) which contains "intent-filter" tag
* has the "android:exported" attribute or not.
* @param manifestFile
* @return List of nodes which doesn't have "android:exported" attribute
*/
@herisulistiyanto
herisulistiyanto / daemon-log-housekeeping.sh
Created September 13, 2022 10:16
Gradle Daemon Log Housekeeping
#!/bin/sh
# This script is used to clean up the log files in the Gradle Daemon directory.
# All of the *.out.log files will be removed
# Use it if you have storage space issue, caused of gradle daemon log
GRADLE_HOME=$HOME/.gradle
GRADLE_DAEMON_DIR=$GRADLE_HOME/daemon
if [ -d "$GRADLE_HOME" ]; then