Skip to content

Instantly share code, notes, and snippets.

@aldoKelvianto
aldoKelvianto / CoroutineCancellation.kt
Created August 7, 2019 02:37
Demonstrate cancellation in coroutine
import kotlinx.coroutines.*
import java.net.URL
fun main() {
cancelWhenFetchingDataOverNetwork()
// cancelWhenTakeANap()
// cancelWhenDoingHeavyComputation()
}
fun cancelWhenDoingHeavyComputation() = runBlocking {
@aldoKelvianto
aldoKelvianto / The Technical Interview Cheat Sheet.md
Last active February 22, 2018 10:08 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

Array

Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
// © 2013 Basil Bourque. This source code may be used freely forever by anyone taking full responsibility for doing so.
// import org.joda.time.*;
// Default time zone.
DateTime dateTimeInMyDefaultTimeZone = new DateTime( "2010-01-01T12:00:00+01:00" );
// UTC
DateTime dateTimeInUtc = new DateTime( "2010-01-01T12:00:00+01:00", DateTimeZone.UTC );
// Named time zone
@aldoKelvianto
aldoKelvianto / AutoFormatUtil.java
Created March 10, 2017 10:22
for . delimiter countries (like Indonesia, Spanish, etc.)
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.Locale;
/**
* Created by aldo on 21/08/16.
*/
public class AutoFormatUtil {
@aldoKelvianto
aldoKelvianto / AutoFormatEditText.java
Last active March 10, 2017 10:22
for . delimiter countries (like Indonesia, Spanish, etc.)
import android.content.Context;
import android.content.res.TypedArray;
import android.support.v7.widget.AppCompatEditText;
import android.text.InputFilter;
import android.text.method.DigitsKeyListener;
import android.util.AttributeSet;
import java.util.StringTokenizer;
/**
<!--
ListActivity.java
-->
@Override public void onAnimalClick(View view, Animal animal) {
ImageView ivTarget = (ImageView) view.findViewById(R.id.iv_image);
Intent intent = getBundledIntent(animal);
launchDetailActivity(ivTarget, intent);
}
<!---
list_item_animal.xml
-->
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="25dp"
android:padding="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
@aldoKelvianto
aldoKelvianto / VSCodeIntelliJKeyBindings.json
Last active December 19, 2016 15:55
Visual Studio Keybindings - IntelliJ Flavor
[
{ "key": "cmd+shift+]", "command": "workbench.action.nextEditor" },
{ "key": "cmd+shift+[", "command": "workbench.action.previousEditor" }
]
// Default setting
{
"editor.cursorStyle": "block",
"java.home": "/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home",
@aldoKelvianto
aldoKelvianto / AndroidRxRetrofitApi.md
Created December 5, 2016 19:18
How to chain two API calls (or more) in Rx?

A friend of mine basically ask me this question, "How to chain two API calls in Rx?". At first I thought it would be a quick and easy code. And I was wrong, in the end I spent more time than I should, so I hope this post would help.

Let's say we have this API and we want to get weather for every city.

public interface WeatherApi {

    @GET("cities")
    Observable<List<City>> getCities(); 
    // Query params is omitted for simplicty, usually lat and lan
@aldoKelvianto
aldoKelvianto / Various Proxy Configuration
Created April 30, 2016 07:40
Proxy Configuration for Git, Heroku, Grails, NPM
grails add-proxy client --host=proxy-server --port=4300
--username=guest --password=guest
grails set-proxy client
untuk melihat settingan proxy yang sudah ada:
git config --global --get http.proxy
git config --global --get https.proxy
untuk nge-set settingan proxy:
git config --global http.proxy http://aldo11%40mhs.is.its.ac.id:passsword@proxy.its.ac.id:8080