Skip to content

Instantly share code, notes, and snippets.

View xrubioj's full-sized avatar

Xavier Rubio Jansana xrubioj

View GitHub Profile
@markus2610
markus2610 / RealmTypeAdapter.kt
Last active March 21, 2017 10:51
Kotlin Realm Primitive Arrays Workaround for Moshi
package de.wdv.apps.yoursingapore.core.moshi
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import de.wdv.apps.yoursingapore.core.realm.RealmIntArray
import de.wdv.apps.yoursingapore.core.realm.RealmLongArray
import de.wdv.apps.yoursingapore.core.realm.RealmStringArray
import java.lang.reflect.Type
@josh-burton
josh-burton / androidmanifest.xml
Created May 3, 2017 02:07
Prevent TouchWiz from surrounding your app icon in a frame
<!-- Prevents TouchWiz from surrounding your app icon in a frame -->
<!-- Add to your manifest inside the application tag -->
<meta-data
android:name="com.samsung.android.icon_container.has_icon_container"
android:value="true"/>
@bclymer
bclymer / HttpClient.kt
Created January 21, 2016 19:00
Kotlin Realm Primitive Arrays Workaround
val realmIntArrayType = object : TypeToken<RealmIntArray>() {}.type
val realmLongArrayType = object : TypeToken<RealmLongArray>() {}.type
val realmStringArrayType = object : TypeToken<RealmStringArray>() {}.type
val gson = GsonBuilder()
.setExclusionStrategies(object : ExclusionStrategy {
override fun shouldSkipClass(clazz: Class<*>?): Boolean {
return false
}
override fun shouldSkipField(f: FieldAttributes?): Boolean {
@DarrenAtherton49
DarrenAtherton49 / GetPosts.kt
Last active July 21, 2017 15:43
Parameterised reactive use cases in Kotlin
class GetPosts @Inject constructor(
uiExecutor: UiExecutor,
@Named("ioExecutor") backgroundExecutor: BackgroundExecutor,
private val redditRepository: RedditRepository
) : ReactiveUseCase<List<RedditLink>>(uiExecutor, backgroundExecutor) {
fun execute(onNext: (List<RedditLink>) -> Unit,
onError: (Throwable) -> Unit,
onCompleted: () -> Unit) {
@android10
android10 / AndroidApplication.java
Created July 20, 2016 09:56
Android: how to know if your app is completely hidden
public class AndroidApplication extends MultiDexApplication {
public static final String TAG = AndroidApplication.class.getSimpleName();
@Override
public void onCreate() {
super.onCreate();
registerComponentCallbacks(new ComponentCallback());
}
private class ComponentCallback implements ComponentCallbacks2 {
@kabadisha
kabadisha / dedup-imovie-library
Last active November 7, 2017 06:46 — forked from bhollis/dedup-imovie-library
When you import movies into iMovie 10 libraries, the file is always copied, wasting space and hindering editability. This script replaces the copy with a hardlink, reclaiming disk space.
#!/usr/bin/env ruby
# Usage: dedup-imovie-library LIBRARY ORIGINALS
#
# Goes through an iMovie 10 library and replaces all the "Original Media" with
# symlinks to the actual original media, in order to conserve disk space. Note
# that because they're symlinks, if the path to the originals changes (e.g. you
# rename the external drive they are on) then the links will be broken.
#
# This assumes you've already imported the files into iMovie and waited for them
extension DataRequest{
/// @Returns - DataRequest
/// completionHandler handles JSON Object T
@discardableResult func responseObject<T: Decodable> (
queue: DispatchQueue? = nil ,
completionHandler: @escaping (DataResponse<T>) -> Void ) -> Self{
let responseSerializer = DataResponseSerializer<T> { request, response, data, error in
guard error == nil else {return .failure(BackendError.network(error: error!))}
@pedrovgs
pedrovgs / ScreenshotTest.kt
Last active November 22, 2019 12:50
Interface you can import from your tests to be able to use screenshot testing for Android with different resolutions easily
import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.view.View
import androidx.fragment.app.Fragment
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import com.facebook.testing.screenshot.Screenshot
import com.facebook.testing.screenshot.ViewHelpers
@gauntface
gauntface / toggle-remote-styles.js
Last active March 12, 2020 12:56
A book marklet to toggle styles.
javascript:(function(){var styles = document.querySelectorAll('link[rel=\'stylesheet\']'); for (var s = 0; s < styles.length; s++) {styles[s].mediax = styles[s].media;if (styles[s].media === 'only x') { styles[s].media = styles[s].mediax; } else if (styles[s].media !== 'print') {styles[s].media = 'only x';}}})();
@dedeexe
dedeexe / URLRequest+curlCommand.swift
Last active April 17, 2020 13:08
Convert URL Request to curl command
extension URLRequest {
public func curl(pretty:Bool = false) -> String {
var data : String = ""
let complement = pretty ? "\\\n" : ""
let method = "-X \(self.httpMethod ?? "GET") \(complement)"
let url = "\"" + self.url?.absoluteString ?? "" + "\""
var header = ""