Skip to content

Instantly share code, notes, and snippets.

View eyeahs's full-sized avatar

박현우(HyunwooPark) eyeahs

  • Hyundai
  • South Korea
View GitHub Profile
@eyeahs
eyeahs / Base64.kt
Created January 2, 2019 07:07 — forked from hrules6872/Base64.kt
Base64.kt for Kotlin
fun String.encodeBase64ToString(): String = String(this.toByteArray().encodeBase64())
fun String.encodeBase64ToByteArray(): ByteArray = this.toByteArray().encodeBase64()
fun ByteArray.encodeBase64ToString(): String = String(this.encodeBase64())
fun String.decodeBase64(): String = String(this.toByteArray().decodeBase64())
fun String.decodeBase64ToByteArray(): ByteArray = this.toByteArray().decodeBase64()
fun ByteArray.decodeBase64ToString(): String = String(this.decodeBase64())
fun ByteArray.encodeBase64(): ByteArray {
val table = (CharRange('A', 'Z') + CharRange('a', 'z') + CharRange('0', '9') + '+' + '/').toCharArray()
@eyeahs
eyeahs / EventObserver.kt
Created November 1, 2018 13:51 — forked from JoseAlcerreca/EventObserver.kt
An Observer for Events, simplifying the pattern of checking if the Event's content has already been handled.
/**
* An [Observer] for [Event]s, simplifying the pattern of checking if the [Event]'s content has
* already been handled.
*
* [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled.
*/
class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> {
override fun onChanged(event: Event<T>?) {
event?.getContentIfNotHandled()?.let { value ->
onEventUnhandledContent(value)
<android.support.v7.widget.RecyclerView
android:id="@+id/results_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar_wrapper"
android:scrollbars="vertical"
app:itemView="@{listViewModel.itemView}"
app:items="@{listViewModel.films}"
app:layoutManager="@{LayoutManagers.linear()}"
app:onItemSelected="@{listViewModel.onItemSelected}"
@eyeahs
eyeahs / Generic.md
Last active September 13, 2018 01:54
Generic study

Ref : https://stackoverflow.com/questions/3546745/multiple-wildcards-on-a-generic-methods-makes-java-compiler-and-me-very-confu

As Appendix B indicates, this has nothing to do with multiple wildcards, but rather, misunderstanding what List<List<?>> really means.

Let's first remind ourselves what it means that Java generics is invariant:

An Integer is a Number A List is NOT a List A List IS a List<? extends Number> We now simply apply the same argument to our nested list situation (see appendix for more details):

@eyeahs
eyeahs / DefaultInjectingHelper.java
Last active December 29, 2016 02:00
Reflection of overloaded methods
public class DefaultInjectingHelper {
public static void main(String[] args) {
final Component component = new ComponentMockImpl();
final BaseDependecy a = new A();
injectWithReflection(component, a);
}
public void injectWithReflection(Component component, Object target) throws InterruptedException {
@eyeahs
eyeahs / MyTest.java
Created May 10, 2016 08:28 — forked from romainpiel/MyTest.java
Source for https://medium.com/p/3f6f4179652e - "RecyclerView and espresso, a complicated story"
RecyclerViewInteraction.<Item>onRecyclerView(withId(R.id.recyclerview))
.withItems(items)
.check(new ItemViewAssertion<Item>() {
@Override
public void check(Item item, View view, NoMatchingViewException e) {
matches(hasDescendant(withText(item.getDisplayName())))
.check(view, e);
}
});
public enum EnumCode {
ABC(R.string.abc),
DEF(R.string.def),
GHI(R.string.ghi);
private final int stringResourceId;
public static EnumCode fromString(String name) {
for (EnumCode code : EnumCode.values()) {
if (code.name().equalsIgnoreCase(name)) {
@eyeahs
eyeahs / manipulating List
Last active August 29, 2015 14:11
Collection Gist
// Delete items while iterate
Iterator<Long> iterator = anyArrayList.iterator();
while (iterator.hasNext()) {
long value = iterator.next();
if (/** condition **/) {
iterator.remove();
}
}
// Find duplicates
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- disabled -->
<item android:color="#ff000000" android:state_enabled="false" />
<!-- pressed -->
<item android:color="#ff000000" android:state_enabled="true" android:state_pressed="true" />
<!-- focused -->
<item android:color="#ff000000" android:state_enabled="true" android:state_focused="true" />

##Getting results from DialogFragments to another Fragment.

When setting up the DialogFragment make a call to Fragment.setTargetFragment()
Then from DialogFragment you can access the main fragment with Fragment.getTargetFragment()
Use interfaces to provide the required actions to the calling Fragment.

##Example code.

###AddFriendDialogFragment - Calls back to calling fragment.