Skip to content

Instantly share code, notes, and snippets.

🙏
:)

Prem Nirmal premnirmal

View GitHub Profile
@premnirmal
premnirmal / settings.json
Last active Apr 23, 2019
my vscode settings
View settings.json
{
"window.titleBarStyle": "custom",
"workbench.colorTheme": "Yoncé",
"workbench.editor.enablePreview": false,
"window.zoomLevel": 2,
"window.restoreWindows": "none",
"explorer.confirmDelete": false,
"editor.cursorStyle": "block"
}
View RxFragmentDelegates.kt
import com.trello.rxlifecycle2.android.FragmentEvent
import io.reactivex.subjects.BehaviorSubject
/**
* Owner of a Fragment Lifecycle. Your Fragment should implement this interface.
*/
interface FragmentLifeCycleOwner {
val lifecycle: BehaviorSubject<FragmentEvent>
}
View BrowseRecipesFragment_delegates.kt
class BrowseRecipesFragment : Fragment(), View.OnClickListener {
private val recipeClickListener: RecipeClickListener by ParentActivityDelegate(this)
...
override fun onClick(v: View) {
// Guaranteed to be not null :)
recipeClickListener.onRecipeClicked(recipe)
}
View FragmentDelegates.kt
/**
* Delegate that sets and disposes the fragment's listener by casting it to the fragment's activity.
*/
class ParentActivityDelegate<T>(fragment: Fragment) : BaseParentDelegate<T>(fragment) {
override fun extractValue(fragment: Fragment): T? = fragment.activity as? T
}
/**
* Delegate that sets and disposes the fragment's listener by casting it to the fragment's
View BrowseRecipesFragment_boilerplate.kt
class BrowseRecipesFragment : Fragment(), View.OnClickListener {
private var recipeClickListener: RecipeClickListener? = null
...
override fun onAttach(context: Context) {
super.onAttach(context)
recipeClickListener = context as RecipeClickListener
}
@premnirmal
premnirmal / NutritionalInfoNet.kt
Last active Apr 23, 2018
NutritionalInfo with correct annotations
View NutritionalInfoNet.kt
import com.squareup.moshi.Json
/**
* Class representing a recipe's nutritional information.
* The [calories_per_serving] field here includes the correct annotations for Moshi to be able to parse it.
*/
data class NutritionalInfoNet(
@JvmField
var id: String,
@JvmField
@premnirmal
premnirmal / NutritionalInfoNet.kt
Last active Apr 23, 2018
NutritionalInfo missing annotation
View NutritionalInfoNet.kt
import com.squareup.moshi.Json
/**
* Class representing a recipe's nutritional information.
* The [calories_per_serving] field does not include the correct annotation for Moshi to be able to parse it.
*/
data class NutritionalInfoNet(
@JvmField
var id: String,
@JvmField
@premnirmal
premnirmal / XORCrypt.java
Created Sep 26, 2014
Simple yet effective XOR encryption
View XORCrypt.java
import java.io.*;
import java.util.*;
/**
* @author Prem Nirmal
*/
public class XORCrypt {
static String value = "SampleStringToBeEncrypted";
static String keyval = "thisIsAKey";
@premnirmal
premnirmal / GZipRequest.java
Last active Aug 12, 2018
Parse GZip responses using volley
View GZipRequest.java
import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
import com.android.volley.Response;
import com.android.volley.toolbox.HttpHeaderParser;
import com.android.volley.toolbox.StringRequest;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
You can’t perform that action at this time.