Skip to content

Instantly share code, notes, and snippets.

Avatar

Rio Swarawan Putra swarawan

View GitHub Profile
@swarawan
swarawan / DateUtils.java
Created Jun 19, 2017
Pretty date format to get duration.
View DateUtils.java
public class DateUtils {
public static String getDurationDate(Date date) {
Date today = new Date();
long diff = today.getTime() - date.getTime();
long diffSeconds = diff / 1000 % 60;
long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = diff / (60 * 60 * 1000) % 24;
long diffDays = diff / (24 * 60 * 60 * 1000) % 30;
long diffWeeks = diff / (30 * 24 * 60 * 60 * 1000) / 4;
@swarawan
swarawan / Get Duration
Created Sep 14, 2017
Get duration depend on inserted Date.
View Get Duration
public static String getDurationDate(Date date) {
Date today = new Date();
long diff = today.getTime() - date.getTime();
long diffSeconds = diff / 1000 % 60;
long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = diff / (60 * 60 * 1000) % 24;
long diffDays = diff / (24 * 60 * 60 * 1000) % 30;
long diffWeeks = diff / (30 * 24 * 60 * 60 * 1000) / 4;
long diffMonth = diff / (30 * 24 * 60 * 60 * 1000);
View gist:e2f29290f695d27d5a5b20ed849147a8
/**
* Return string formatted with dot separator and prepended with currency
* symbol (IDR). By default will return Rp 0.
*
* @param defaultOutput Default string to return (with currency prefix) when error happen.
*/
@NonNull
public static final String formatCurrency(@Nullable BigDecimal input, @NonNull String defaultOutput) {
if (input == null)
return defaultOutput;
@swarawan
swarawan / Sistem Parkir
Last active Mar 9, 2018
Belajar menggunakan kondisi (decision) dan perulangan (loop)
View Sistem Parkir
total roda <= 2 -> lahan parkir sebelah kiri
total roda > 2 <=4 -> lahan parkir sebelah kanan
total roda > 4 -> basement
check here -> https://github.com/swarawan/batch-6-java-basic.git
View Latihan Decision - Loop
Buat sistem lift
- ada 20 lantai
- posisi pemain ada di lantai `x`
- pemain ingin ke lantai `y`
Soal:
gambarkan alur lift tersebut.
Contoh:
posisi pemain = 5
View Latihan Kalkulator
Kalkulator
Nilai 1 : <inputA> // 5
Nilai 2 : <inputB> // 2
Pilih Operator:
1. Tambah
2. Kurang
3. Kali
4. Bagi
Pilihan (1..4) : <inputOperator> // 1
@swarawan
swarawan / NetworkUtils
Created Mar 13, 2018
Use this class to check connection availability
View NetworkUtils
public class NetworkUtils {
private static boolean isConnected;
public NetworkUtils(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager == null) return;
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
View publish.gradle
apply plugin: 'maven-publish'
publishing {
publications {
aar(MavenPublication) {
setGroupId 'com.swarawan'
artifactId project.getName()
version libraryVersion
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
@swarawan
swarawan / delete_git_submodule.md
Created Sep 13, 2018 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.
View delete_git_submodule.md

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
View Soal Binar: Data Class + Extension
x = 10
y = 5
10 + 5 = 15
10 - 5 = 5
10 * 5 = 50
10 / 5 = 2
syaratnya:
- gunakan data class untuk menyimpan nilai x dan y