Skip to content

Instantly share code, notes, and snippets.

View swarawan's full-sized avatar

Rio Swarawan Putra swarawan

  • Jakarta, Indonesia
View GitHub Profile
@swarawan
swarawan / DateUtils.java
Created June 19, 2017 05:30
Pretty date format to get duration.
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 September 14, 2017 01:12
Get duration depend on inserted Date.
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);
/**
* 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 March 9, 2018 15:11
Belajar menggunakan kondisi (decision) dan perulangan (loop)
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
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
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 March 13, 2018 12:51
Use this class to check connection availability
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();
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 September 13, 2018 09:42 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.

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
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